(Alpine + AWS CLI + Ansible) @ Docker
I’m using Bitbucket Pipelines widely for CI/CD at my current position. It sucks a little if compare it with GitLab CI/CD, but I don’t complain.
One common restriction in both: you cannot use different images in a single step (job).
It sounds legit: steps (jobs) are atomic execution units.
However, in GitLab you could group jobs in stages, while in Bitbucket there seems to be no grouping at all.
So, if your deployment logically consists of multiple different actions, like deploying Lambdas with AWS CLI and running Ansible plays for EC2 instances, you’re out of luck in Bitbucket: you need two steps — one with AWS CLI and another with Ansible.
Sucking deeper: if you want to use deployments feature (you, generally, want) you cannot have multiple steps with the same deployment
key.
Usually, enterprises tend to build “The Image” that holds everything they need to build the project and use it across all steps, so all the tools are available at every single step. We did that as well. The image was like 2 gigs and it just suck.
I believe in DOTADIW / Unix way and I think we should reuse community images where possible. For example, there are awesome OpenJDK builds available for free @ Docker Hub, why not use them for Java build steps?
That way, we thrown away our “The Image” and seen a great improvement in build times due to better image caching and container startup times. The problem is that we cannot deploy anything due to the problem I’ve stated above. I’ve googled for AWS CLI + Ansible images on the Net, but they all were either abandoned, or used Ubuntu.
I believe I can do better with awesome Alpine Linux, so I’ve created this image.
It’s only 63MiB and it contains only the tools we need — AWS CLI + Ansible. Though the Ansible version is not the latest 2.5, it fits us well. It’s fully open sourced (BTW, I’m moving to GitLab completely, with automatic repo mirroring to GitHub).
Finally, my friends told me, that the name is cool.
Feel free to use it if you need. Oh, and here is the example for BitBucket:
step:
name: Deploy to UAT
image:
name: madhead/awesible:latest
trigger: manual
deployment: staging
script:
- aws lambda update-function-code --region us-west-1 --function-name uat-lambda --s3-bucket us-west-1-artifacts --publish --s3-key ${BITBUCKET_REPO_SLUG}/${BITBUCKET_BUILD_NUMBER}/uat-lambda.jar
- ansible-playbook uat.yml -i ec2.py