https://github.com/sc5/serverless-deployment-ansible-lite
Simple build and deploy example for deploying Serverless service with Ansible.
https://github.com/sc5/serverless-deployment-ansible-lite
ansible ansible-playbook jenkins orchestration serverless
Last synced: about 1 year ago
JSON representation
Simple build and deploy example for deploying Serverless service with Ansible.
- Host: GitHub
- URL: https://github.com/sc5/serverless-deployment-ansible-lite
- Owner: SC5
- Created: 2017-02-03T12:31:47.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-10T12:36:19.000Z (over 9 years ago)
- Last Synced: 2025-04-19T19:05:03.032Z (about 1 year ago)
- Topics: ansible, ansible-playbook, jenkins, orchestration, serverless
- Language: Shell
- Homepage:
- Size: 67.4 KB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Ansible Playbook for Serverless Framework
A simple build and deploy example for deploying [Serverless](https://github.com/serverless/serverless) service with [Ansible](https://github.com/ansible/ansible).
Docker is required for deploying the playbook or alternatively Ansible and all the dependencies defined in Dockerfile installed in you environment.
For bigger scale Serverless projects there is also a more advanced version [serverless-deployment-ansible](https://github.com/SC5/serverless-deployment-ansible) that deploys Serverless service from built artifacts.
## Project Structure
* `group_vars` default variables
* `inventories` inventory files and variables for environments (development, production, etc.)
* `roles`
* `infra` role for infrastructure, vpc, database etc.
* `service` role for Serverless service
* `scripts` scripts that helps deployment
## Setup Jenkins
When using jenkins for deployment, easiest way is to setup Jenkins into EC2 instance running in your AWS account. Here is quick and dirty instructions how to do that [Jenkins setup instructions](https://github.com/laardee/jenkins-installation)
In addition to suggested plugins, install following plugins also:
* Pipeline: AWS Steps
* Version Number Plug-In
## Deployment
### Deployment flow

1. Get services from git, S3 bucket or other places with Ansible
2. Deploy Serverless service with Ansible Serverless module
3. Deploy other services, e.g. copy frontend files to buckets, deploy CloudFormation stacks
### Local environment
When deploying from local environment AWS secrets needs to be passed to deployment container, for that e.g. `.deploy.sh` script in the project root with contents of
```Bash
#!/usr/bin/env bash
export AWS_ACCESS_KEY=my-access-key
export AWS_SECRET_KEY=my-secret-key
export SECRET=example-lambda-env-variable
./scripts/deploy-local.sh
```
might ease up the deployment flow.
1. Build Dockerfile with `./scripts/build-docker.sh`
2. Run `./.deploy.sh`
### Jenkins
When using Jenkins on AWS EC2, the role of the instance needs to have permissions to deploy CloudFormation stacks, create S3 buckets, IAM Roles, Lambda and other services that are used in Serverless service.
```Groovy
node {
stage('Checkout repository') {
git 'https://github.com/SC5/serverless-deployment-ansible-lite.git'
}
stage('Build Docker image') {
sh "./scripts/build-docker.sh"
}
stage('Deploy') {
withEnv(['SECRET=my-example-secret']) {
sh './scripts/deploy-development.sh'
}
}
}
```