Skip to content

Commit 8d5f750

Browse files
authored
Docker fixes (#139)
* Fixing docker-ansible playbooks and timeout * Bumping README version * debugging inventory.yaml * adding check * Removing inventory debug
1 parent ffe7614 commit 8d5f750

File tree

9 files changed

+69
-28
lines changed

9 files changed

+69
-28
lines changed

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
runs-on: ubuntu-latest
7070
steps:
7171
- id: deploy
72-
uses: bitovi/[email protected].0
72+
uses: bitovi/[email protected].8
7373
with:
7474
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
7575
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
@@ -97,7 +97,7 @@ jobs:
9797
steps:
9898
- id: deploy
9999
name: Deploy
100-
uses: bitovi/[email protected].0
100+
uses: bitovi/[email protected].8
101101
with:
102102
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
103103
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
@@ -124,7 +124,7 @@ jobs:
124124
1. [Certificates](#certificate-inputs)
125125
1. [Load Balancer](#load-balancer-inputs)
126126
1. [Application](#application-inputs)
127-
1. [Terraform](#terraform-inputs)
127+
1. [Deployment](#deployment-inputs)
128128

129129
The following inputs can be used as `step.with` keys
130130
<br/>
@@ -230,12 +230,13 @@ The following inputs can be used as `step.with` keys
230230
<hr/>
231231
<br/>
232232

233-
#### **Terraform Inputs**
233+
#### **Deployment Inputs**
234234
| Name | Type | Description |
235235
|------------------|---------|------------------------------------|
236236
| `tf_state_bucket` | String | AWS S3 bucket name to use for Terraform state. See [note](#s3-buckets-naming) |
237237
| `tf_state_bucket_destroy` | Boolean | Force purge and deletion of S3 bucket defined. Any file contained there will be destroyed. `stack_destroy` must also be `true`. Default is `false`. |
238238
| `additional_tags` | JSON | Add additional tags to the terraform [default tags](https://www.hashicorp.com/blog/default-tags-in-the-terraform-aws-provider), any tags put here will be added to all provisioned resources.|
239+
| `ansible_start_docker_timeout` | String | Ammount of time in seconds it takes Ansible to mark as failed the startup of docker. Defaults to `300`.|
239240
<hr/>
240241
<br/>
241242
<br/>

action.yaml

+4-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ inputs:
8686
required: false
8787
default: "8"
8888

89-
9089
# EFS
9190
aws_create_efs:
9291
description: "Toggle to indicate whether to create and EFS and mount it to the ec2 as a part of the provisioning. Note: The EFS will be managed by the stack and will be destroyed along with the stack"
@@ -110,6 +109,9 @@ inputs:
110109
# Stack management
111110
stack_destroy:
112111
description: 'Set to "true" to Destroy the stack. Will delete the elb_logs bucket after the destroy action runs.'
112+
ansible_start_docker_timeout:
113+
description: 'Ammount of time in seconds it takes Ansible to mark as failed the startup of docker. Defaults to `300`'
114+
required: false
113115

114116
# Domains
115117
domain_name:
@@ -225,6 +227,7 @@ runs:
225227
EC2_INSTANCE_TYPE: ${{ inputs.ec2_instance_type }}
226228
EC2_VOLUME_SIZE: ${{ inputs.ec2_volume_size }}
227229
STACK_DESTROY: ${{ inputs.stack_destroy }}
230+
ANSIBLE_START_DOCKER_TIMEOUT: ${{ inputs.ansible_start_docker_timeout }}
228231
AWS_RESOURCE_IDENTIFIER: ${{ inputs.aws_resource_identifier }}
229232
DOMAIN_NAME: ${{ inputs.domain_name }}
230233
SUB_DOMAIN: ${{ inputs.sub_domain }}

operations/_scripts/generate/generate_tf_vars.sh

+2
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ efs_mount_target=$(generate_var efs_mount_target $EFS_MOUNT_TARGET)
159159
data_mount_target=$(generate_var data_mount_target $DATA_MOUNT_TARGET)
160160
ec2_volume_size=$(generate_var ec2_volume_size $EC2_VOLUME_SIZE)
161161
docker_remove_orphans=$(generate_var docker_remove_orphans $DOCKER_REMOVE_ORPHANS)
162+
ansible_start_docker_timeout=$(generate_var ansible_start_docker_timeout $ANSIBLE_START_DOCKER_TIMEOUT)
162163

163164

164165
# -------------------------------------------------- #
@@ -234,6 +235,7 @@ $create_keypair_sm_entry
234235
$additional_tags
235236
236237
##-- ANSIBLE --##
238+
$ansible_start_docker_timeout
237239
$application_mount_target
238240
$efs_mount_target
239241
$data_mount_target

operations/deployment/ansible/tasks/install.yml

+25-9
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,36 @@
1010
- 'virtualenv'
1111
- 'python3-setuptools'
1212

13+
- name: Create the keyrings folder
14+
file:
15+
path: /etc/apt/keyrings
16+
state: directory
17+
mode: '0755'
18+
1319
- name: Add Docker GPG apt Key
14-
apt_key:
20+
get_url:
1521
url: https://download.docker.com/linux/ubuntu/gpg
16-
state: present
22+
dest: /etc/apt/keyrings/docker.asc
23+
24+
- name: Fix Docker key permissions
25+
file:
26+
path: /etc/apt/keyrings/docker.asc
27+
mode: '0666'
28+
29+
- name: Get APT package architecture
30+
command: dpkg --print-architecture
31+
register: dpkg_arch
1732

18-
- name: Add Docker Repository
33+
- name: Add Docker repo
1934
apt_repository:
20-
repo: deb https://download.docker.com/linux/ubuntu jammy stable
35+
repo: "deb [arch={{ dpkg_arch.stdout }} signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu {{ ansible_distribution_release }} stable"
2136
state: present
2237

23-
- name: Update apt and install docker-ce
24-
apt: update_cache=yes name=docker-ce state=latest
38+
- name: Update apt repositories
39+
apt:
40+
update_cache: yes
2541

26-
- name: Install Docker Module for Python
27-
pip:
42+
- name: Install Docker and Docker Compose
43+
apt:
2844
name:
29-
- docker
45+
- docker-ce

operations/deployment/ansible/tasks/mount.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
dest: /home/ubuntu/efs-utils
2323
update: false
2424
become: yes
25+
when: not check_efs_utils.stat.exists
2526

2627
- name: Build amazon-efs-utils
2728
ansible.builtin.shell:
@@ -60,4 +61,4 @@
6061
opts: "nfsvers=4.1,rsize=1048576,wsize=1048576,hard,timeo=612,retrans=2,noresvport"
6162
fstype: nfs4
6263
state: mounted
63-
boot: false
64+
boot: false
+12-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
1-
- name: Start docker-compose
2-
ansible.builtin.command: "docker compose --project-directory {{ app_install_root }}/{{ app_repo_name }} up --detach --build --force-recreate --remove-orphans={{ docker_remove_orphans }}"
1+
- name: Start docker-compose with remove orphans
2+
ansible.builtin.command: "docker compose --project-directory {{ app_install_root }}/{{ app_repo_name }} up --detach --build --force-recreate --remove-orphans"
33
register: output
4+
async: "{{ ansible_start_docker_timeout }}"
5+
poll: 5
6+
when: docker_remove_orphans | bool
7+
8+
- name: Start docker-compose without remove orphans
9+
ansible.builtin.command: "docker compose --project-directory {{ app_install_root }}/{{ app_repo_name }} up --detach --build --force-recreate"
10+
register: output
11+
async: "{{ ansible_start_docker_timeout }}"
12+
poll: 5
13+
when: not ( docker_remove_orphans | bool )
414

515
- ansible.builtin.debug:
616
var: output

operations/deployment/terraform/inventory.tf

+12-11
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,18 @@ resource "local_sensitive_file" "private_key" {
66

77
resource "local_file" "ansible_inventory" {
88
content = templatefile("inventory.tmpl", {
9-
ip = aws_instance.server.public_ip,
10-
ssh_keyfile = local_sensitive_file.private_key.filename
11-
app_repo_name = var.app_repo_name
12-
app_install_root = var.app_install_root
13-
mount_efs = local.mount_efs
14-
efs_url = local.efs_url
15-
resource_identifier = var.aws_resource_identifier
16-
application_mount_target = var.application_mount_target
17-
efs_mount_target = var.efs_mount_target != null ? var.efs_mount_target : ""
18-
data_mount_target = var.data_mount_target
19-
docker_remove_orphans = var.docker_remove_orphans
9+
ip = aws_instance.server.public_ip,
10+
ssh_keyfile = local_sensitive_file.private_key.filename
11+
ansible_start_docker_timeout = var.ansible_start_docker_timeout
12+
app_repo_name = var.app_repo_name
13+
app_install_root = var.app_install_root
14+
mount_efs = local.mount_efs
15+
efs_url = local.efs_url
16+
resource_identifier = var.aws_resource_identifier
17+
application_mount_target = var.application_mount_target
18+
efs_mount_target = var.efs_mount_target != null ? var.efs_mount_target : ""
19+
data_mount_target = var.data_mount_target
20+
docker_remove_orphans = var.docker_remove_orphans
2021
})
2122
filename = format("%s/%s", abspath(path.root), "inventory.yaml")
2223
}

operations/deployment/terraform/inventory.tmpl

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ bitops_servers:
44
vars:
55
ansible_ssh_user: ubuntu
66
ansible_ssh_private_key_file: ${ssh_keyfile}
7+
ansible_start_docker_timeout: ${ansible_start_docker_timeout}
78
app_repo_name: ${app_repo_name}
89
app_install_root: ${app_install_root}
910
mount_efs: ${mount_efs}

operations/deployment/terraform/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,12 @@ variable "docker_remove_orphans" {
262262
default = false
263263
}
264264

265+
variable "ansible_start_docker_timeout" {
266+
type = string
267+
description = "Ammount of time in seconds it takes Ansible to mark as failed the startup of docker."
268+
default = "300"
269+
}
270+
265271
## -- --- -- ##
266272
variable "availability_zone" {
267273
type = string

0 commit comments

Comments
 (0)