geerlingguy.ecr_container_build

Ansible Role: ECR Container Build

CI

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 format namespace/project).

  • ecr_image_buildargs: {}
    Parameters to send to the docker_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 to true if your Dockerfile uses an image from ECR (e.g., FROM in your Dockerfile).

  • ecr_push: true
    Set to true to push the image to ECR after building, or false if you are only testing the build.

  • ecr_region: us-east-1

  • ecr_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.

Informazioni sul progetto

ECR docker image build and push management role.

Installa
ansible-galaxy install geerlingguy.ecr_container_build
Licenza
mit
Download
24.2k
Proprietario
Father, author, developer, maker. Sometimes called "an inflammatory enigma". #stl #drupal #ansible #k8s #raspberrypi #crohns