Skip to content

Commit f81f85f

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

File tree

9 files changed

+119
-6
lines changed

9 files changed

+119
-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: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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+
# Variable for gup-docker-deploy?
17+
- name: Ensure remote working directory exists
18+
file:
19+
path: /opt/gup-docker-deploy
20+
state: directory
21+
22+
- name: Copy compose files to server
23+
copy:
24+
src: "{{ playbook_dir }}/../docker/{{ item }}"
25+
dest: "/opt/gup-docker-deploy/{{ item }}"
26+
loop:
27+
- docker-compose.yml
28+
- docker-compose.deploy.yml
29+
30+
- name: Ensure database initialization directory exists
31+
file:
32+
path: /opt/gup-docker-deploy/postgres-initdb.d
33+
state: directory
34+
35+
- name: Copy database dump if exists
36+
copy: src="{{ item }}" dest=/opt/gup-docker-deploy/postgres-initdb.d
37+
with_fileglob: postgres-initdb.d/*.gz
38+
39+
# Revisions log instead
40+
- name: Get local username from whoami
41+
become: false
42+
local_action: command whoami
43+
register: local_username_result
44+
45+
- name: Set local username fact
46+
set_fact:
47+
deploy_local_username: "{{ local_username_result.stdout }}"
48+
49+
- name: Copy deploy .env file to server
50+
template:
51+
src: deploy_env.j2
52+
dest: "/opt/gup-docker-deploy/.env"
53+
54+
- name: Deploy container stack from compose file
55+
environment:
56+
GIT_REVISION: "{{ deploy_git_revision }}"
57+
docker_stack:
58+
state: present
59+
with_registry_auth: yes
60+
name: gup
61+
compose:
62+
- /opt/gup-docker-deploy/docker-compose.yml
63+
- /opt/gup-docker-deploy/docker-compose.deploy.yml
64+
- version: '3.7'
65+
services:
66+
frontend:
67+
environment:
68+
- "EMBER_ENVIRONMENT={{ gup_environment }}"
69+
- "GUP_SERVICE_PORT={{ gup_frontend_port }}"
70+
ports:
71+
- "{{ gup_frontend_port }}:8080"
72+
backend:
73+
environment:
74+
- "GUP_ENVIRONMENT={{ gup_environment }}"
75+
- "GUP_DB={{ gup_db }}"
76+
- "GUP_DB_USER={{ gup_db_user }}"
77+
- "GUP_DB_PASSWORD={{ gup_db_password }}"
78+
- "GUP_SCOPUS_API_KEY={{ gup_scopus_api_key }}"
79+
- "GUP_MQ_API_KEY={{ gup_mq_api_key }}"
80+
- "GUP_SECRET_KEY_BASE={{ gup_secret_key_base }}"
81+
ports:
82+
- "{{ gup_backend_port }}:3000"
83+
solr:
84+
ports:
85+
- "{{ gup_solr_port }}:8983"

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: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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>
18+
gup_secret_key_base: 29f01727314845cd7351aace2c4453e28cb95089dadafb49e299e5750e382c303d483d25c2854832fe274d6d27e09442fce906c2621e311ff650fd79644c8ea8
19+

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)