diff --git a/docs/roles/deploy_container.md b/docs/roles/deploy_container.md index 46285580..e34d028c 100644 --- a/docs/roles/deploy_container.md +++ b/docs/roles/deploy_container.md @@ -1,5 +1,14 @@ # Deploy container -Step that deploys the codebase in a Docker container image. +Step that deploys the codebase in a Docker container image. Requires Docker and the `community.docker` collection for Ansible to be installed on your deploy server. You will also need to add a `docker` group and make sure your local deploy user is in that group, for example: + +``` +sudo groupadd docker +sudo usermod -aG docker deploy +``` + +This can be handled automatically by [`ce-provision`](https://github.com/codeenigma/ce-provision) using the `ce_deploy` and `docker_ce` roles. + +AWS ECR registries require the AWS CLI user provided for `ce-deploy` to have the managed AWS `EC2InstanceProfileForImageBuilderECRContainerBuilds` policy attached via IAM to allow access to fetch credentials and push containers. @@ -16,6 +25,7 @@ deploy_container: docker_registry_pass: asdf1234 docker_base_command: "docker image build" docker_build_dir: "{{ _ce_deploy_build_dir }}" + dockerfile_template: example.j2 # provide a templates directory next to your playbook and change this to match your Dockerfile template name environment_vars: {} # dictionary you can populate for use in a custom Dockerfile template # Requires the deploy IAM user to have the managed EC2InstanceProfileForImageBuilderECRContainerBuilds policy attached aws_ecr: diff --git a/roles/deploy_container/README.md b/roles/deploy_container/README.md index 0647af50..e34d028c 100644 --- a/roles/deploy_container/README.md +++ b/roles/deploy_container/README.md @@ -1,5 +1,12 @@ # Deploy container -Step that deploys the codebase in a Docker container image. Requires Docker and the `community.docker` collection for Ansible to be installed on your deploy server. This can be handled by [`ce-provision`](https://github.com/codeenigma/ce-provision) using the `ce_deploy` and `docker_ce` roles. +Step that deploys the codebase in a Docker container image. Requires Docker and the `community.docker` collection for Ansible to be installed on your deploy server. You will also need to add a `docker` group and make sure your local deploy user is in that group, for example: + +``` +sudo groupadd docker +sudo usermod -aG docker deploy +``` + +This can be handled automatically by [`ce-provision`](https://github.com/codeenigma/ce-provision) using the `ce_deploy` and `docker_ce` roles. AWS ECR registries require the AWS CLI user provided for `ce-deploy` to have the managed AWS `EC2InstanceProfileForImageBuilderECRContainerBuilds` policy attached via IAM to allow access to fetch credentials and push containers. @@ -18,6 +25,7 @@ deploy_container: docker_registry_pass: asdf1234 docker_base_command: "docker image build" docker_build_dir: "{{ _ce_deploy_build_dir }}" + dockerfile_template: example.j2 # provide a templates directory next to your playbook and change this to match your Dockerfile template name environment_vars: {} # dictionary you can populate for use in a custom Dockerfile template # Requires the deploy IAM user to have the managed EC2InstanceProfileForImageBuilderECRContainerBuilds policy attached aws_ecr: diff --git a/roles/deploy_container/defaults/main.yml b/roles/deploy_container/defaults/main.yml index 4e4d30c3..8b1e8e69 100644 --- a/roles/deploy_container/defaults/main.yml +++ b/roles/deploy_container/defaults/main.yml @@ -7,6 +7,7 @@ deploy_container: docker_registry_pass: asdf1234 docker_base_command: "docker image build" docker_build_dir: "{{ _ce_deploy_build_dir }}" + dockerfile_template: example.j2 # provide a templates directory next to your playbook and change this to match your Dockerfile template name environment_vars: {} # dictionary you can populate for use in a custom Dockerfile template # Requires the deploy IAM user to have the managed EC2InstanceProfileForImageBuilderECRContainerBuilds policy attached aws_ecr: diff --git a/roles/deploy_container/tasks/main.yml b/roles/deploy_container/tasks/main.yml index 37013df2..2b037a40 100644 --- a/roles/deploy_container/tasks/main.yml +++ b/roles/deploy_container/tasks/main.yml @@ -3,7 +3,7 @@ - name: Create Dockerfile from template. local_action: module: ansible.builtin.template - src: Dockerfile.j2 + src: "{{ deploy_container.dockerfile_template }}" dest: "{{ deploy_container.docker_build_dir }}/Dockerfile" - name: Set Docker registry username and password. diff --git a/roles/deploy_container/templates/Dockerfile.j2 b/roles/deploy_container/templates/example.j2 similarity index 80% rename from roles/deploy_container/templates/Dockerfile.j2 rename to roles/deploy_container/templates/example.j2 index d0f5e81c..5a155197 100644 --- a/roles/deploy_container/templates/Dockerfile.j2 +++ b/roles/deploy_container/templates/example.j2 @@ -3,5 +3,5 @@ FROM debian:bullseye-slim MAINTAINER sysadm@codeenigma.com RUN apt-get update -RUN apt-get install –y nginx +RUN apt-get install -y nginx CMD ["echo","Image created"] \ No newline at end of file