Skip to content

Commit f9d553d

Browse files
committed
Define task to load docker containers from archive
1 parent 0db6509 commit f9d553d

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

provision-contest/ansible/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ There are a few places where additional files should/can be added:
4444
* Machine/group specific local packages under `roles/base_packages/files/install-*/`.
4545
* Judgehost chroot local packages under `roles/judgedaemon/files/install-chroot/`.
4646
* The vendor dependencies under `roles/domjudge_checkout/files/vendor.tgz`.
47+
* Machine/group specific docker containers under `roles/docker/files/containers-*/`.
4748

4849
## TODO
4950

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Loading containers from archives
2+
Any container `.tar` files placed in a `containers-<host_type>` directory will be loaded as a container for the said host type.
3+
The container will be tagged with the relative path starting from `containers-<host_type>`, without the `.tar` file extension.
4+
For example, the file `containers-glitchtip/glitchtip/glitchtip:v4.1.3.tar` will be loaded as a container tagged `glitchtip/glitchtip:v4.1.3` for the `glitchtip` host type.
5+
Note that a nested directory structure is needed to tag containers which have both an organization and a container name.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
---
2+
- name: Load the container from archive if needed
3+
block:
4+
- name: Check for existing container
5+
community.docker.docker_image_info:
6+
name: "{{ img_name }}"
7+
register: result
8+
9+
- name: Transfer and load the container
10+
block:
11+
- name: Create temp container directory
12+
file:
13+
path: /tmp/dj_ansible
14+
state: directory
15+
owner: root
16+
group: root
17+
mode: 0700
18+
19+
- name: Transfer container archive
20+
copy:
21+
src: "{{ item.src }}"
22+
dest: "{{ img_path }}"
23+
owner: root
24+
group: root
25+
mode: 0700
26+
27+
- name: Import container from archive
28+
community.docker.docker_image:
29+
name: "{{ img_name }}"
30+
load_path: "{{ img_path }}"
31+
source: load
32+
when: not result.images
33+
vars:
34+
img_name: "{{ item.path | splitext | first }}"
35+
img_path: "/tmp/dj_ansible/{{ item.path | basename }}"

provision-contest/ansible/roles/docker/tasks/main.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,9 @@
2222
- docker-compose-plugin
2323
- python3-pip
2424
- python3-docker
25+
26+
- name: Load container archives
27+
include_tasks: load-container.yml
28+
with_filetree:
29+
- files/containers-{{ host_type }}/
30+
when: item.state == 'file' and (item.path | splitext | last) == ".tar"

0 commit comments

Comments
 (0)