Akron | e53ef3a | 2024-03-19 11:27:11 +0100 | [diff] [blame] | 1 | - name: Deploy Kalamar-Plugin-ExternalResources |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 2 | hosts: |
Akron | 6c26c6a | 2024-03-19 14:19:53 +0100 | [diff] [blame] | 3 | - test |
| 4 | - main |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 5 | serial: 1 |
Akron | 6c26c6a | 2024-03-19 14:19:53 +0100 | [diff] [blame] | 6 | run_once: true |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 7 | tasks: |
| 8 | - name: Save docker image |
Akron | 700679f | 2024-03-19 16:41:36 +0100 | [diff] [blame] | 9 | local_action: ansible.builtin.command docker save {{ external_image }} -o ./kalamar-plugin-externalresources-latest.tar |
Akron | e53ef3a | 2024-03-19 11:27:11 +0100 | [diff] [blame] | 10 | |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 11 | - name: Copy docker image to hosts |
| 12 | ansible.builtin.copy: |
| 13 | src: ./kalamar-plugin-externalresources-latest.tar |
Akron | 6c26c6a | 2024-03-19 14:19:53 +0100 | [diff] [blame] | 14 | dest: "{{ external_path }}/kalamar-plugin-externalresources-latest.tar" |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 15 | mode: '0644' |
Akron | e53ef3a | 2024-03-19 11:27:11 +0100 | [diff] [blame] | 16 | |
| 17 | - name: Delete docker image tar |
| 18 | local_action: |
| 19 | module: ansible.builtin.file |
| 20 | path: ./kalamar-plugin-externalresources-latest.tar |
| 21 | state: absent |
| 22 | |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 23 | - name: Load docker image on host |
Akron | 6c26c6a | 2024-03-19 14:19:53 +0100 | [diff] [blame] | 24 | ansible.builtin.command: "docker load -i {{ external_path }}/kalamar-plugin-externalresources-latest.tar" |
Akron | e53ef3a | 2024-03-19 11:27:11 +0100 | [diff] [blame] | 25 | |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 26 | - name: Get UID for KorAP user |
| 27 | getent: |
| 28 | database: passwd |
| 29 | key: korap |
Akron | e53ef3a | 2024-03-19 11:27:11 +0100 | [diff] [blame] | 30 | |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 31 | - name: Gracefully stop and remove old docker container, if existing |
| 32 | community.docker.docker_container: |
Akron | 700679f | 2024-03-19 16:41:36 +0100 | [diff] [blame] | 33 | image: "{{ external_image }}" |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 34 | state: "absent" |
Akron | 6c26c6a | 2024-03-19 14:19:53 +0100 | [diff] [blame] | 35 | name: "{{ external_container_name }}" |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 36 | recreate: true |
| 37 | keep_volumes: true |
| 38 | comparisons: |
| 39 | image: ignore # do not restart containers with older versions of the image |
Akron | e53ef3a | 2024-03-19 11:27:11 +0100 | [diff] [blame] | 40 | |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 41 | - name: Restart docker container |
| 42 | community.docker.docker_container: |
Akron | 700679f | 2024-03-19 16:41:36 +0100 | [diff] [blame] | 43 | image: "{{ external_image }}" |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 44 | restart_policy: "unless-stopped" |
| 45 | pull: false |
Akron | 6c26c6a | 2024-03-19 14:19:53 +0100 | [diff] [blame] | 46 | name: "{{ external_container_name }}" |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 47 | user: "{{ ansible_facts.getent_passwd[\"korap\"].1 }}" |
| 48 | init: true |
| 49 | detach: true |
| 50 | mounts: |
| 51 | - type: bind |
Akron | 6c26c6a | 2024-03-19 14:19:53 +0100 | [diff] [blame] | 52 | source: "{{ external_path }}/db" |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 53 | target: "/db" |
| 54 | - type: bind |
Akron | 6c26c6a | 2024-03-19 14:19:53 +0100 | [diff] [blame] | 55 | source: "{{ external_path }}/.env" |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 56 | target: "/.env" |
| 57 | ports: |
Akron | 700679f | 2024-03-19 16:41:36 +0100 | [diff] [blame] | 58 | - "{{ external_port }}" |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 59 | comparisons: |
| 60 | image: ignore # do not restart containers with older versions of the image |