Skip to content

Commit 677748f

Browse files
committed
Add wait_for_container_exit role for FE
1 parent 135fe5d commit 677748f

5 files changed

Lines changed: 68 additions & 2 deletions

File tree

ansible/enterprise-sign-in.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@
77
roles:
88
- { role: builder, tags: "build" }
99
- { role: container_start }
10+
- { role: wait_for_container_exit }

ansible/group_vars/alpha-web.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ container_envs: >
1212
-e API_URL=https://{{ api_hostname }}
1313
-e MIXPANEL_PROXY_URL={{ mixpanel_proxy_url }}
1414
-e AWS_ACCESS_KEY={{ aws_access_key }}
15-
-e AWS_BUCKET app.{{ domain }}
15+
-e AWS_BUCKET=app.{{ domain }}
1616
-e AWS_REGION={{ web_aws_bucket_region | default('us-east-1') }}
1717
-e AWS_SECRET_KEY={{ aws_secret_key }}
1818
-e INTERCOM_APP_ID={{ web_intercom_id }}
1919
-e MARKETING_URL={{ marketing_url }}
20-
-e NODE_ENV production
20+
-e NODE_ENV=production
2121
-e SIFT_API_KEY={{ web_sift_public_key }}
2222
-e STRIPE_TOKEN={{ cream_stripe_publishable_key }}
2323
-e USER_CONTENT_DOMAIN={{ user_content_domain }}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/usr/bin/env bash
2+
3+
IMAGE_NAME="$1"
4+
CONTAINERS=`docker ps | grep -v '^CONTAINER' | awk '{print $1}'`
5+
6+
if [ "" = "${CONTAINERS}" ] ; then
7+
exit 0
8+
else
9+
for container in ${CONTAINERS} ; do
10+
docker inspect "${container}" | grep -q '"Image": "'"${IMAGE_NAME}":
11+
if [ ${?} -eq 0 ] ; then
12+
if [ -z "${RUNNING_CONTAINERS}" ] ; then
13+
RUNNING_CONTAINERS="${container}"
14+
else
15+
RUNNING_CONTAINERS="${RUNNING_CONTAINERS} ${container}"
16+
fi
17+
fi
18+
done
19+
fi
20+
21+
if [ ! -z "${RUNNING_CONTAINERS}" ] ; then
22+
echo "${RUNNING_CONTAINERS}"
23+
fi
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
---
2+
- name: get containers
3+
tags: deploy
4+
become: yes
5+
script: findTagRunning.sh {{ container_image }}
6+
register: container_ids
7+
8+
- name: wait for container to stop
9+
become: yes
10+
script: findTagRunning.sh {{ container_image }}
11+
register: result
12+
tags: deploy
13+
until: result.stdout_lines|length == 0
14+
retries: 100
15+
delay: 1
16+
17+
- name: get container exit code
18+
tags: deploy
19+
become: true
20+
command: docker inspect -f {% raw %}{{.State.ExitCode}}{% endraw %} {{ container_ids.stdout_lines[0] }}
21+
register: container_exit_code
22+
23+
- name: get logs
24+
tags: deploy
25+
shell: source /home/ubuntu/.bash_aliases && loglast {{ name }} "n 200"
26+
args:
27+
executable: /bin/bash
28+
when: container_exit_code.stdout != "0"
29+
register: last_200_lines_of_logs
30+
31+
- name: display logs for debugging purposes
32+
tags: deploy
33+
when: container_exit_code.stdout != "0"
34+
debug:
35+
var: last_200_lines_of_logs
36+
37+
- name: assert container exited with no errors
38+
tags: deploy
39+
when: container_exit_code.stdout != "0"
40+
fail:
41+
msg: "Container did not exit with code 0 (Code: {{ container_exit_code.stdout }})"

ansible/web.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@
1010
tags: [ notify ]
1111
- { role: builder, tags: "build" }
1212
- { role: container_start }
13+
- { role: wait_for_container_exit }

0 commit comments

Comments
 (0)