geerlingguy.ecr_container_build
Ansible Role: ECR Container Build
This Ansible Role helps you create Docker container images and can send them to AWS ECR (Elastic Container Registry) if you want.
Requirements
- Docker must be installed.
- You need Pip packages:
boto3
,docker
.
Role Variables
Here are the variables you can use, along with their default settings (see defaults/main.yml
):
ecr_image_src_dir
: ../my-project
The folder where your Dockerfile and other resources are located, and the name for your Docker image (usually in formatnamespace/project
).ecr_image_buildargs
: {}
Parameters to send to thedocker_image
module when building the Docker image. Provide as an object with key-value pairs, for example,{ name: value, name2: value2 }
.ecr_image_tags
: ['latest']
Tags that will be added to the image once it is pushed to ECR.ecr_login_required
: false
Set totrue
if your Dockerfile uses an image from ECR (e.g.,FROM
in your Dockerfile).ecr_push
: true
Set totrue
to push the image to ECR after building, orfalse
if you are only testing the build.ecr_region
: us-east-1ecr_account_id
: '123456789012'ecr_url
: "{{ ecr_account_id }}.dkr.ecr.{{ ecr_region }}.amazonaws.com"
These are your AWS details for accessing ECR.
Dependencies
There are no dependencies.
Example Playbook
Building Locally
Assuming you have Docker and the docker
pip package set up:
---
- hosts: localhost
connection: local
gather_facts: false
vars:
ecr_image_src_dir: ../my-project
ecr_image_name: namespace/my-project
ecr_image_tags: ['latest','1.2.3']
ecr_account_id: '123456789012'
pip_install_packages: ['docker']
roles:
- role: geerlingguy.ecr_container_build
Building on a Remote Server
---
- hosts: localhost
connection: local
gather_facts: false
vars:
ecr_image_src_dir: ../my-project
ecr_image_name: namespace/my-project
ecr_image_tags: ['latest','1.2.3']
ecr_account_id: '123456789012'
pip_install_packages: ['docker']
roles:
- role: geerlingguy.docker
- role: geerlingguy.pip
- role: geerlingguy.ecr_container_build
License
MIT / BSD
Author Information
This role was created in 2018 by Jeff Geerling, the author of Ansible for DevOps.
ECR docker image build and push management role.
ansible-galaxy install geerlingguy.ecr_container_build