Changed docker to use a hosts file with various var files and to use roles.
This commit is contained in:
parent
16f29c4139
commit
26310dfc42
@ -32,6 +32,4 @@ else
|
|||||||
fi
|
fi
|
||||||
cd "$parent_path/docker" || exit
|
cd "$parent_path/docker" || exit
|
||||||
docker save barker:latest | bzip2 | pv | ssh tanshu@beacon.tanshu.com 'bunzip2 | sudo docker load'
|
docker save barker:latest | bzip2 | pv | ssh tanshu@beacon.tanshu.com 'bunzip2 | sudo docker load'
|
||||||
ansible-playbook --limit=beacon playbook-mhl.yml
|
ansible-playbook --inventory hosts playbook.yml
|
||||||
ansible-playbook --limit=beacon playbook-chd.yml
|
|
||||||
ansible-playbook --limit=beacon playbook-pkl.yml
|
|
||||||
|
14
docker/hosts
Normal file
14
docker/hosts
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
# - Comments begin with the '#' character
|
||||||
|
# - Blank lines are ignored
|
||||||
|
# - Groups of hosts are delimited by [header] elements
|
||||||
|
# - You can enter hostnames or ip addresses
|
||||||
|
# - A hostname/ip can be a member of multiple groups
|
||||||
|
|
||||||
|
[barker]
|
||||||
|
pkl ansible_host=beacon var_file=vars/pkl.yml
|
||||||
|
chd ansible_host=beacon var_file=vars/chd.yml
|
||||||
|
mhl ansible_host=beacon var_file=vars/mhl.yml
|
||||||
|
# hin ansible_host=beacon var_file=vars/hin.yml
|
||||||
|
|
||||||
|
[all:vars]
|
||||||
|
ansible_python_interpreter=/usr/bin/python3
|
@ -1,69 +0,0 @@
|
|||||||
#################################################
|
|
||||||
# DO Community Playbooks: Docker
|
|
||||||
#################################################
|
|
||||||
---
|
|
||||||
- hosts: all
|
|
||||||
become: true
|
|
||||||
vars_files:
|
|
||||||
- vars/chd.yml
|
|
||||||
|
|
||||||
tasks:
|
|
||||||
- name: Copy dockerfile
|
|
||||||
synchronize: src=app dest=/tmp
|
|
||||||
|
|
||||||
- name: Build barker image
|
|
||||||
docker_image:
|
|
||||||
name: barker:latest
|
|
||||||
build:
|
|
||||||
path: /tmp/app/
|
|
||||||
dockerfile: /tmp/app/Dockerfile
|
|
||||||
pull: yes
|
|
||||||
state: present
|
|
||||||
source: build
|
|
||||||
|
|
||||||
- name: Upload the .env file
|
|
||||||
template:
|
|
||||||
src: "files/chd.env"
|
|
||||||
dest: "/var/lib/{{ host_directory }}/.env"
|
|
||||||
|
|
||||||
- name: Create barker container
|
|
||||||
docker_container:
|
|
||||||
name: "{{ host_directory }}"
|
|
||||||
image: barker:latest
|
|
||||||
state: started
|
|
||||||
restart_policy: "unless-stopped"
|
|
||||||
env_file: "/var/lib/{{ host_directory }}/.env"
|
|
||||||
links:
|
|
||||||
- "postgres:db"
|
|
||||||
- "redis:redis"
|
|
||||||
published_ports:
|
|
||||||
- "127.0.0.1:{{ host_port }}:80"
|
|
||||||
volumes:
|
|
||||||
- "/var/lib/{{ host_directory }}/frontend:/frontend"
|
|
||||||
|
|
||||||
- name: Check if Nginx conf file exists
|
|
||||||
stat: path="/etc/nginx/sites-available/{{ http_conf }}"
|
|
||||||
register: status
|
|
||||||
|
|
||||||
- name: No need to reload Nginx
|
|
||||||
debug: msg= {{ "No need to reload Nginx as sites-available entries have already been created" }}
|
|
||||||
|
|
||||||
- name: Set Nginx conf file
|
|
||||||
when: status.stat.exists == false
|
|
||||||
template:
|
|
||||||
src: "files/nginx.conf.j2"
|
|
||||||
dest: "/etc/nginx/sites-available/{{ http_conf }}"
|
|
||||||
|
|
||||||
- name: Enable new site
|
|
||||||
when: status.stat.exists == false
|
|
||||||
file:
|
|
||||||
src: "/etc/nginx/sites-available/{{ http_conf }}"
|
|
||||||
dest: "/etc/nginx/sites-enabled/{{ http_conf }}"
|
|
||||||
state: link
|
|
||||||
notify: Reload Nginx
|
|
||||||
|
|
||||||
handlers:
|
|
||||||
- name: Reload Nginx
|
|
||||||
service:
|
|
||||||
name: nginx
|
|
||||||
state: reloaded
|
|
@ -1,69 +0,0 @@
|
|||||||
#################################################
|
|
||||||
# DO Community Playbooks: Docker
|
|
||||||
#################################################
|
|
||||||
---
|
|
||||||
- hosts: all
|
|
||||||
become: true
|
|
||||||
vars_files:
|
|
||||||
- vars/mhl.yml
|
|
||||||
|
|
||||||
tasks:
|
|
||||||
- name: Copy dockerfile
|
|
||||||
synchronize: src=app dest=/tmp
|
|
||||||
|
|
||||||
- name: Build barker image
|
|
||||||
docker_image:
|
|
||||||
name: barker:latest
|
|
||||||
build:
|
|
||||||
path: /tmp/app/
|
|
||||||
dockerfile: /tmp/app/Dockerfile
|
|
||||||
pull: yes
|
|
||||||
state: present
|
|
||||||
source: build
|
|
||||||
|
|
||||||
- name: Upload the .env file
|
|
||||||
template:
|
|
||||||
src: "files/mhl.env"
|
|
||||||
dest: "/var/lib/{{ host_directory }}/.env"
|
|
||||||
|
|
||||||
- name: Create barker container
|
|
||||||
docker_container:
|
|
||||||
name: "{{ host_directory }}"
|
|
||||||
image: barker:latest
|
|
||||||
state: started
|
|
||||||
restart_policy: "unless-stopped"
|
|
||||||
env_file: "/var/lib/{{ host_directory }}/.env"
|
|
||||||
links:
|
|
||||||
- "postgres:db"
|
|
||||||
- "redis:redis"
|
|
||||||
published_ports:
|
|
||||||
- "127.0.0.1:{{ host_port }}:80"
|
|
||||||
volumes:
|
|
||||||
- "/var/lib/{{ host_directory }}/frontend:/frontend"
|
|
||||||
|
|
||||||
- name: Check if Nginx conf file exists
|
|
||||||
stat: path="/etc/nginx/sites-available/{{ http_conf }}"
|
|
||||||
register: status
|
|
||||||
|
|
||||||
- name: No need to reload Nginx
|
|
||||||
debug: msg= {{ "No need to reload Nginx as sites-available entries have already been created" }}
|
|
||||||
|
|
||||||
- name: Set Nginx conf file
|
|
||||||
when: status.stat.exists == false
|
|
||||||
template:
|
|
||||||
src: "files/nginx.conf.j2"
|
|
||||||
dest: "/etc/nginx/sites-available/{{ http_conf }}"
|
|
||||||
|
|
||||||
- name: Enable new site
|
|
||||||
when: status.stat.exists == false
|
|
||||||
file:
|
|
||||||
src: "/etc/nginx/sites-available/{{ http_conf }}"
|
|
||||||
dest: "/etc/nginx/sites-enabled/{{ http_conf }}"
|
|
||||||
state: link
|
|
||||||
notify: Reload Nginx
|
|
||||||
|
|
||||||
handlers:
|
|
||||||
- name: Reload Nginx
|
|
||||||
service:
|
|
||||||
name: nginx
|
|
||||||
state: reloaded
|
|
@ -1,69 +0,0 @@
|
|||||||
#################################################
|
|
||||||
# DO Community Playbooks: Docker
|
|
||||||
#################################################
|
|
||||||
---
|
|
||||||
- hosts: all
|
|
||||||
become: true
|
|
||||||
vars_files:
|
|
||||||
- vars/pkl.yml
|
|
||||||
|
|
||||||
tasks:
|
|
||||||
- name: Copy dockerfile
|
|
||||||
synchronize: src=app dest=/tmp
|
|
||||||
|
|
||||||
- name: Build barker image
|
|
||||||
docker_image:
|
|
||||||
name: barker:latest
|
|
||||||
build:
|
|
||||||
path: /tmp/app/
|
|
||||||
dockerfile: /tmp/app/Dockerfile
|
|
||||||
pull: yes
|
|
||||||
state: present
|
|
||||||
source: build
|
|
||||||
|
|
||||||
- name: Upload the .env file
|
|
||||||
template:
|
|
||||||
src: "files/pkl.env"
|
|
||||||
dest: "/var/lib/{{ host_directory }}/.env"
|
|
||||||
|
|
||||||
- name: Create barker container
|
|
||||||
docker_container:
|
|
||||||
name: "{{ host_directory }}"
|
|
||||||
image: barker:latest
|
|
||||||
state: started
|
|
||||||
restart_policy: "unless-stopped"
|
|
||||||
env_file: "/var/lib/{{ host_directory }}/.env"
|
|
||||||
links:
|
|
||||||
- "postgres:db"
|
|
||||||
- "redis:redis"
|
|
||||||
published_ports:
|
|
||||||
- "127.0.0.1:{{ host_port }}:80"
|
|
||||||
volumes:
|
|
||||||
- "/var/lib/{{ host_directory }}/frontend:/frontend"
|
|
||||||
|
|
||||||
- name: Check if Nginx conf file exists
|
|
||||||
stat: path="/etc/nginx/sites-available/{{ http_conf }}"
|
|
||||||
register: status
|
|
||||||
|
|
||||||
- name: No need to reload Nginx
|
|
||||||
debug: msg= {{ "No need to reload Nginx as sites-available entries have already been created" }}
|
|
||||||
|
|
||||||
- name: Set Nginx conf file
|
|
||||||
when: status.stat.exists == false
|
|
||||||
template:
|
|
||||||
src: "files/nginx.conf.j2"
|
|
||||||
dest: "/etc/nginx/sites-available/{{ http_conf }}"
|
|
||||||
|
|
||||||
- name: Enable new site
|
|
||||||
when: status.stat.exists == false
|
|
||||||
file:
|
|
||||||
src: "/etc/nginx/sites-available/{{ http_conf }}"
|
|
||||||
dest: "/etc/nginx/sites-enabled/{{ http_conf }}"
|
|
||||||
state: link
|
|
||||||
notify: Reload Nginx
|
|
||||||
|
|
||||||
handlers:
|
|
||||||
- name: Reload Nginx
|
|
||||||
service:
|
|
||||||
name: nginx
|
|
||||||
state: reloaded
|
|
@ -2,94 +2,12 @@
|
|||||||
# DO Community Playbooks: Docker
|
# DO Community Playbooks: Docker
|
||||||
#################################################
|
#################################################
|
||||||
---
|
---
|
||||||
- hosts: all
|
- hosts: barker
|
||||||
become: true
|
become: true
|
||||||
vars_files:
|
vars_files:
|
||||||
- vars/default.yml
|
- "{{ var_file }}"
|
||||||
|
|
||||||
tasks:
|
roles:
|
||||||
- name: Copy dockerfile
|
- upload
|
||||||
synchronize: src=app dest=/tmp
|
- docker
|
||||||
|
- nginx
|
||||||
- name: Build barker image
|
|
||||||
docker_image:
|
|
||||||
name: barker:latest
|
|
||||||
build:
|
|
||||||
path: /tmp/app/
|
|
||||||
dockerfile: /tmp/app/Dockerfile
|
|
||||||
pull: yes
|
|
||||||
state: present
|
|
||||||
source: build
|
|
||||||
|
|
||||||
- name: Build barker worker image
|
|
||||||
docker_image:
|
|
||||||
name: barker-worker:latest
|
|
||||||
build:
|
|
||||||
path: /tmp/app/
|
|
||||||
dockerfile: /tmp/app/worker.Dockerfile
|
|
||||||
pull: yes
|
|
||||||
state: present
|
|
||||||
source: build
|
|
||||||
|
|
||||||
- name: Upload the .env file
|
|
||||||
template:
|
|
||||||
src: "files/.env"
|
|
||||||
dest: "/var/lib/{{ host_directory }}/.env"
|
|
||||||
|
|
||||||
- name: Upload the worker .env file
|
|
||||||
template:
|
|
||||||
src: "files/worker.env"
|
|
||||||
dest: "/var/lib/{{ host_directory }}/worker.env"
|
|
||||||
|
|
||||||
- name: Create barker container
|
|
||||||
docker_container:
|
|
||||||
name: "{{ host_directory }}"
|
|
||||||
image: barker:latest
|
|
||||||
state: started
|
|
||||||
restart_policy: "unless-stopped"
|
|
||||||
env_file: "/var/lib/{{ host_directory }}/.env"
|
|
||||||
links:
|
|
||||||
- "postgres:db"
|
|
||||||
- "redis:redis"
|
|
||||||
published_ports:
|
|
||||||
- "127.0.0.1:{{ host_port }}:80"
|
|
||||||
volumes:
|
|
||||||
- "/var/lib/{{ host_directory }}/frontend:/frontend"
|
|
||||||
|
|
||||||
- name: Create barker worker container
|
|
||||||
docker_container:
|
|
||||||
name: "{{ host_directory }}-worker"
|
|
||||||
image: barker-worker:latest
|
|
||||||
state: started
|
|
||||||
restart_policy: "unless-stopped"
|
|
||||||
env_file: "/var/lib/{{ host_directory }}/worker.env"
|
|
||||||
links:
|
|
||||||
- "redis:redis"
|
|
||||||
|
|
||||||
|
|
||||||
- name: Check if Nginx conf file exists
|
|
||||||
stat: path="/etc/nginx/sites-available/{{ http_conf }}"
|
|
||||||
register: status
|
|
||||||
|
|
||||||
- name: No need to reload Nginx
|
|
||||||
debug: msg= {{ "No need to reload Nginx as sites-available entries have already been created" }}
|
|
||||||
|
|
||||||
- name: Set Nginx conf file
|
|
||||||
when: status.stat.exists == false
|
|
||||||
template:
|
|
||||||
src: "files/nginx.conf.j2"
|
|
||||||
dest: "/etc/nginx/sites-available/{{ http_conf }}"
|
|
||||||
|
|
||||||
- name: Enable new site
|
|
||||||
when: status.stat.exists == false
|
|
||||||
file:
|
|
||||||
src: "/etc/nginx/sites-available/{{ http_conf }}"
|
|
||||||
dest: "/etc/nginx/sites-enabled/{{ http_conf }}"
|
|
||||||
state: link
|
|
||||||
notify: Reload Nginx
|
|
||||||
|
|
||||||
handlers:
|
|
||||||
- name: Reload Nginx
|
|
||||||
service:
|
|
||||||
name: nginx
|
|
||||||
state: reloaded
|
|
||||||
|
26
docker/roles/docker/tasks/main.yaml
Normal file
26
docker/roles/docker/tasks/main.yaml
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
---
|
||||||
|
# Tasks for docker role
|
||||||
|
- name: Build barker image
|
||||||
|
docker_image:
|
||||||
|
name: barker:latest
|
||||||
|
build:
|
||||||
|
path: "/tmp/{{ host_directory }}/"
|
||||||
|
dockerfile: "/tmp/{{ host_directory }}/Dockerfile"
|
||||||
|
pull: yes
|
||||||
|
state: present
|
||||||
|
source: build
|
||||||
|
|
||||||
|
- name: Create barker container
|
||||||
|
docker_container:
|
||||||
|
name: "{{ host_directory }}"
|
||||||
|
image: barker:latest
|
||||||
|
state: started
|
||||||
|
restart_policy: "unless-stopped"
|
||||||
|
env_file: "/var/lib/{{ host_directory }}/.env"
|
||||||
|
links:
|
||||||
|
- "postgres:db"
|
||||||
|
- "redis:redis"
|
||||||
|
published_ports:
|
||||||
|
- "127.0.0.1:{{ host_port }}:80"
|
||||||
|
volumes:
|
||||||
|
- "/var/lib/{{ host_directory }}/frontend:/frontend"
|
2
docker/roles/nginx/defaults/main.yaml
Normal file
2
docker/roles/nginx/defaults/main.yaml
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
---
|
||||||
|
# Default variables for Nginx role
|
6
docker/roles/nginx/handlers/main.yaml
Normal file
6
docker/roles/nginx/handlers/main.yaml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
# Handlers for Nginx role
|
||||||
|
- name: Reload Nginx
|
||||||
|
service:
|
||||||
|
name: nginx
|
||||||
|
state: reloaded
|
24
docker/roles/nginx/tasks/main.yaml
Normal file
24
docker/roles/nginx/tasks/main.yaml
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
---
|
||||||
|
# Tasks for Nginx role
|
||||||
|
- name: Check if Nginx conf file exists
|
||||||
|
stat:
|
||||||
|
path: "/etc/nginx/sites-available/{{ http_conf }}"
|
||||||
|
register: status
|
||||||
|
|
||||||
|
- name: No need to reload Nginx
|
||||||
|
debug:
|
||||||
|
msg: "No need to reload Nginx as sites-available entries have already been created"
|
||||||
|
|
||||||
|
- name: Set Nginx conf file
|
||||||
|
when: status.stat.exists == false
|
||||||
|
template:
|
||||||
|
src: "files/nginx.conf.j2"
|
||||||
|
dest: "/etc/nginx/sites-available/{{ http_conf }}"
|
||||||
|
|
||||||
|
- name: Enable new site
|
||||||
|
when: status.stat.exists == false
|
||||||
|
file:
|
||||||
|
src: "/etc/nginx/sites-available/{{ http_conf }}"
|
||||||
|
dest: "/etc/nginx/sites-enabled/{{ http_conf }}"
|
||||||
|
state: link
|
||||||
|
notify: Reload Nginx
|
21
docker/roles/upload/tasks/main.yaml
Normal file
21
docker/roles/upload/tasks/main.yaml
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
---
|
||||||
|
# Tasks for upload role
|
||||||
|
- name: Ensure Temporary Directory exists
|
||||||
|
file:
|
||||||
|
path: "/tmp/{{ host_directory }}"
|
||||||
|
state: directory
|
||||||
|
|
||||||
|
- name: Copy dockerfile
|
||||||
|
synchronize:
|
||||||
|
src: app
|
||||||
|
dest: "/tmp/{{ host_directory }}"
|
||||||
|
|
||||||
|
- name: Ensure Host Directory exists
|
||||||
|
file:
|
||||||
|
path: "/var/lib/{{ host_directory }}"
|
||||||
|
state: directory
|
||||||
|
|
||||||
|
- name: Upload the .env file
|
||||||
|
template:
|
||||||
|
src: "{{ env_file }}"
|
||||||
|
dest: "/var/lib/{{ host_directory }}/.env"
|
@ -3,3 +3,4 @@ http_host: "knox.greatbear.in"
|
|||||||
http_conf: "knox.greatbear.in.conf"
|
http_conf: "knox.greatbear.in.conf"
|
||||||
host_port: "8337"
|
host_port: "8337"
|
||||||
host_directory: "barker-chd"
|
host_directory: "barker-chd"
|
||||||
|
env_file: "files/.env-chd"
|
||||||
|
@ -3,3 +3,4 @@ http_host: "knox.hngmohali.com"
|
|||||||
http_conf: "knox.hngmohali.com.conf"
|
http_conf: "knox.hngmohali.com.conf"
|
||||||
host_port: "8336"
|
host_port: "8336"
|
||||||
host_directory: "barker-mhl"
|
host_directory: "barker-mhl"
|
||||||
|
env_file: "files/.env-mhl"
|
||||||
|
@ -3,3 +3,4 @@ http_host: "knox.hopsngrains.com"
|
|||||||
http_conf: "knox.hopsngrains.com.conf"
|
http_conf: "knox.hopsngrains.com.conf"
|
||||||
host_port: "8338"
|
host_port: "8338"
|
||||||
host_directory: "barker-pkl"
|
host_directory: "barker-pkl"
|
||||||
|
env_file: "files/.env-pkl"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user