Skip to content

Commit

Permalink
SBS docker deploy is dempotent
Browse files Browse the repository at this point in the history
  • Loading branch information
baszoetekouw committed Apr 9, 2024
1 parent 32e38cf commit 7800fc0
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 15 deletions.
30 changes: 22 additions & 8 deletions roles/docker_sbs/handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
---
- name: "systemd daemon-reload"
systemd:
daemon_reload: true
# - name: "systemd daemon-reload"
# systemd:
# daemon_reload: true

- name: "restart sbs"
systemd:
name: "sram-sbs.service"
state: "restarted"
enabled: true
# - name: "restart sbs"
# systemd:
# name: "sram-sbs.service"
# state: "restarted"
# enabled: true

- name: Restart sbs containers
docker_container:
name: "{{ item }}"
state: started
restart: true
loop:
- "{{ containers.sbs }}"
- "{{ containers.sbs_server}}"

- name: Restart redis container
docker_container:
name: "{{ containers.redis }}"
state: started
restart: true
49 changes: 42 additions & 7 deletions roles/docker_sbs/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@
owner: "root"
group: "root"
mode: 0644
notify: "Restart sbs containers"

- name: Copy https cert
copy:
Expand All @@ -149,11 +150,13 @@
owner: "root"
group: "root"
mode: 0644
notify: "Restart sbs containers"

- name: "Create redis config"
template:
src: "redis.conf.j2"
dest: "{{ redis_conf_dir }}/redis.conf"
notify: "Restart redis container"

- name: "Create SBS config files"
template:
Expand All @@ -168,6 +171,7 @@
- { name: "disclaimer.css", mode: "0644" }
# notify: "restart sbs"
no_log: "{{sram_ansible_nolog}}"
notify: "Restart sbs containers"

# - name: "Remove obsolete JWT keys"
# file:
Expand All @@ -189,6 +193,7 @@
- { name: "advanced_settings.json", mode: "0644" }
# notify: "restart sbs"
no_log: "{{ sram_ansible_nolog }}"
notify: "Restart sbs containers"

# - name: "Create links to config files"
# file:
Expand Down Expand Up @@ -236,6 +241,7 @@
template:
src: "sbs-apache.j2"
dest: "{{ sbs_apache_conf }}"
notify: "Restart sbs containers"

# - name: "install nginx config"
# template:
Expand Down Expand Up @@ -272,6 +278,35 @@
networks:
- name: "{{internal_network}}"


- name: Pull sbs container image and create container
docker_container:
name: "{{ containers.sbs }}"
image: "{{ images.sbs }}"
restart_policy: "always"
state: present
pull: "always"
comparisons:
image: "strict"
env:
REQUESTS_CA_BUNDLE: /etc/ssl/certs/ca-certificates.crt
volumes:
- "{{ sbs_conf_dir }}:/opt/sbs/config"
- "{{ sbs_cert_dir }}:/opt/sbs/cert"
- "{{ sbs_log_dir }}:/opt/sbs/log"
- "sbs_static:/opt/sbs/client/build"
networks:
- name: "{{internal_network}}"
etc_hosts:
oidc-op.scz-vm.net: "172.20.1.24"
register: sbs_container

- name: Start sbs container
docker_container:
name: "{{ containers.sbs }}"
state: started
when: "sbs_container is changed"

# We need to remove sram-static so it gets repopulated
# with new SBS image static content
- name: Stop and remove sbs and sbs-server containers
Expand All @@ -281,20 +316,20 @@
with_items:
- "{{ containers.sbs }}"
- "{{ containers.sbs_server }}"
when: "sbs_container is changed"

- name: Remove sbs_static volume
community.docker.docker_volume:
name: sbs_static
state: absent
when: "sbs_container is changed"

- name: Create sbs container
- name: Recreate sbs container
docker_container:
name: "{{ containers.sbs }}"
image: "{{ images.sbs }}"
restart_policy: "always"
restart: true
state: started
pull: true
state: "started"
env:
REQUESTS_CA_BUNDLE: /etc/ssl/certs/ca-certificates.crt
volumes:
Expand All @@ -305,16 +340,16 @@
networks:
- name: "{{internal_network}}"
etc_hosts:
oidc-op.scz-vm.net: 172.20.1.24
oidc-op.scz-vm.net: "172.20.1.24"
when: "sbs_container is changed"

- name: Create apache container
docker_container:
name: "{{ containers.sbs_server }}"
image: "{{ images.sbs_server }}"
restart_policy: "always"
restart: true
state: started
# pull: true
pull: "always"
volumes:
- "{{ sbs_apache_conf }}:/etc/apache2/sites-enabled/sbs.conf:ro"
- "sbs_static:/var/www/html"
Expand Down

0 comments on commit 7800fc0

Please sign in to comment.