Skip to content

Commit 544d0b5

Browse files
committed
Add ansible playbook for deploy
1 parent e21df8c commit 544d0b5

File tree

9 files changed

+113
-6
lines changed

9 files changed

+113
-6
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,6 @@ Sessionx.vim
7070
tags
7171
# Persistent undo
7272
[._]*.un~
73+
74+
# Remove this later and replace with ansible vault variables instead
75+
ansible/vars/docker_credentials.yml

ansible/deploy.yml

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
---
2+
- hosts: gup_deploy_swarm_managers
3+
become: true
4+
vars_files:
5+
- vars/docker_credentials.yml # Replace with vault variables
6+
tasks:
7+
- name: Log into Docker
8+
docker_login:
9+
registry: docker.ub.gu.se
10+
username: "{{ ub__docker_username }}"
11+
password: "{{ ub__docker_password }}"
12+
state: present
13+
reauthorize: yes
14+
debug: yes
15+
16+
- name: Ensure remote working directory exists
17+
file:
18+
path: /opt/gup-docker-deploy
19+
state: directory
20+
- name: Copy compose files to server
21+
copy:
22+
src: "{{ playbook_dir }}/../docker/{{ item }}"
23+
dest: "/opt/gup-docker-deploy/{{ item }}"
24+
loop:
25+
- docker-compose.yml
26+
- docker-compose.deploy.yml
27+
28+
- name: Get local username
29+
become: false
30+
local_action: command whoami
31+
register: deploy_local_username
32+
33+
- name: Copy deploy .env file to server
34+
template:
35+
src: deploy_env.j2
36+
dest: "/opt/gup-docker-deploy/.env"
37+
38+
- name: Deploy container stack from compose file
39+
docker_stack:
40+
state: present
41+
name: gup
42+
compose:
43+
- /opt/gup-docker-deploy/docker-compose.yml
44+
- /opt/gup-docker-deploy/docker-compose.deploy.yml
45+
- version: '3.7'
46+
services:
47+
frontend:
48+
environment:
49+
- "EMBER_ENVIRONMENT={{ gup_environment}}"
50+
- "GUP_SERVICE_PORT={{ gup_frontend_port }}"
51+
ports:
52+
- "{{ gup_frontend_port }}:8080"
53+
backend:
54+
environment:
55+
- "GUP_ENVIRONMENT={{ gup_environment }}}"
56+
- "GUP_DB={{ gup_db }}"
57+
- "GUP_DB_USER={{ gup_db_user }}"
58+
- "GUP_DB_PASSWORD={{ gup_db_password }}"
59+
- "GUP_SCOPUS_API_KEY={{ gup_scopus_api_key }}"
60+
- "GUP_MQ_API_KEY={{ gup_mq_api_key }}"
61+
ports:
62+
- "{{ gup_frontend_port }}:3000"
63+
solr:
64+
ports:
65+
- "{{ gup_solr_port }}:8983"
66+
67+
- name: Run job (get request against web container) within swarm netork
68+
docker_container:
69+
name: docker_ansible_demo_curl
70+
image: byrnedo/alpine-curl
71+
command: "-s http://docker_ansible_demo_web"
72+
state: started
73+
auto_remove: no
74+
detach: no
75+
cleanup: yes
76+
networks:
77+
- name: docker_ansible_demo_webnet
78+
register: job_container_result
79+
80+
- debug:
81+
var: job_container_result.ansible_facts.docker_container.Output

ansible/inventory/group_vars/all

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
gup_solr_port: 8989
3+
gup_frontend_port: 8181
4+
gup_backend_port: 3111

ansible/inventory/lab.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
all:
2+
hosts:
3+
utv02:
4+
ansible_host: 130.241.35.164
5+
ansible_user: dockeruser
6+
children:
7+
gup_deploy_swarm_managers:
8+
hosts:
9+
utv02:
10+
vars:
11+
deploy_git_revision: docker-friendly-config
12+
gup_environment: lab
13+
gup_db: gup_db
14+
gup_db_user: gup_user
15+
gup_db_password: gup_pass
16+
gup_scopus_api_key: <scopus_key>
17+
gup_mq_api_key: <mq_key>

ansible/templates/deploy_env.j2

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
GIT_REVISION={{ deploy_git_revision }}
2+
DEPLOYED_BY={{ deploy_local_username }}

ansible/vars/.gitkeep

Whitespace-only changes.

docker/.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
GIT_REVISION=docker-friendly-config
22
GUP_SOLR_PORT=8989
33
GUP_FRONTEND_PORT=8181
4-
GUP_SERVICE_PORT=3111
4+
GUP_BACKEND_PORT=3111
55
GUP_ENVIRONMENT=development
66
GUP_TEST_USER_API_KEY=an-api-key
77
GUP_SCOPUS_API_KEY=

docker/docker-compose.override.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ services:
2626
networks:
2727
- backend
2828
ports:
29-
- ${GUP_SERVICE_PORT}:3000
29+
- ${GUP_FRONTEND_PORT}:3000
3030
volumes:
3131
- ../:/usr/src/app
3232
command: ["sh", "-c", "bundle install && rails server -b 0.0.0.0 -e $GUP_ENVIRONMENT"]

docker/docker-compose.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ services:
44
image: docker.ub.gu.se/gup-frontend:${GIT_REVISION}
55
environment:
66
- EMBER_ENVIRONMENT=${GUP_ENVIRONMENT}
7-
- GUP_SERVICE_PORT=${GUP_SERVICE_PORT}
7+
- GUP_SERVICE_PORT=${GUP_FRONTEND_PORT}
88
backend:
99
image: docker.ub.gu.se/gup-backend:${GIT_REVISION}
1010
depends_on:
@@ -19,17 +19,17 @@ services:
1919
- GUP_MAIL_SMTP_HOST=${GUP_MAIL_SMTP_HOST}
2020
- GUP_MAIL_FROM=${GUP_MAIL_FROM}
2121
- GUP_MAIL_TO=${GUP_MAIL_TO}
22-
- GUP_PUBLIC_BASE_URL=http://localhost:${GUP_SERVICE_PORT}
22+
- GUP_PUBLIC_BASE_URL=http://localhost:${GUP_FRONTEND_PORT}
2323
- GUP_REPOSITORY_NAME=${GUP_REPOSITORY_NAME}
2424
- GUP_OAI_REPOSITORY_NAME=${GUP_OAI_REPOSITORY_NAME}
25-
- GUP_OAI_REPOSITORY_URL=http://localhost:${GUP_SERVICE_PORT}/oai
25+
- GUP_OAI_REPOSITORY_URL=http://localhost:${GUP_FRONTEND_PORT}/oai
2626
- GUP_OAI_RECORD_PREFIX=${GUP_OAI_RECORD_PREFIX}
2727
- GUP_MQ_BASE_URL=${GUP_MQ_BASE_URL}
2828
- GUP_MQ_API_KEY=${GUP_MQ_API_KEY}
2929
networks:
3030
- backend
3131
ports:
32-
- ${GUP_SERVICE_PORT}:3000
32+
- ${GUP_FRONTEND_PORT}:3000
3333
db:
3434
image: docker.ub.gu.se/gup-postgres:${GIT_REVISION}
3535
restart: always

0 commit comments

Comments
 (0)