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 |
| 9 | local_action: ansible.builtin.command docker save korap/kalamar-plugin-externalresources:latest -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: |
| 33 | state: "absent" |
Akron | 6c26c6a | 2024-03-19 14:19:53 +0100 | [diff] [blame^] | 34 | name: "{{ external_container_name }}" |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 35 | recreate: true |
| 36 | keep_volumes: true |
| 37 | comparisons: |
| 38 | image: ignore # do not restart containers with older versions of the image |
Akron | e53ef3a | 2024-03-19 11:27:11 +0100 | [diff] [blame] | 39 | |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 40 | - name: Restart docker container |
| 41 | community.docker.docker_container: |
| 42 | image: korap/kalamar-plugin-externalresources:latest |
| 43 | restart_policy: "unless-stopped" |
| 44 | pull: false |
Akron | 6c26c6a | 2024-03-19 14:19:53 +0100 | [diff] [blame^] | 45 | name: "{{ external_container_name }}" |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 46 | user: "{{ ansible_facts.getent_passwd[\"korap\"].1 }}" |
| 47 | init: true |
| 48 | detach: true |
| 49 | mounts: |
| 50 | - type: bind |
Akron | 6c26c6a | 2024-03-19 14:19:53 +0100 | [diff] [blame^] | 51 | source: "{{ external_path }}/db" |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 52 | target: "/db" |
| 53 | - type: bind |
Akron | 6c26c6a | 2024-03-19 14:19:53 +0100 | [diff] [blame^] | 54 | source: "{{ external_path }}/.env" |
Akron | a79b6ff | 2024-03-15 12:32:44 +0100 | [diff] [blame] | 55 | target: "/.env" |
| 56 | ports: |
| 57 | - "5722:5722" |
| 58 | comparisons: |
| 59 | image: ignore # do not restart containers with older versions of the image |