Browse Source

[26]-Add support to download docker images instead of git repository

tags/v1.0.0^2
drymer 1 year ago
parent
commit
4f3cc6c27a
Signed by: drymer <drymer@autistici.org> GPG Key ID: A307D64D5DDFDAAD
2 changed files with 53 additions and 7 deletions
  1. 3
    2
      README.md
  2. 50
    5
      tasks/main.yml

+ 3
- 2
README.md View File

@@ -1,7 +1,7 @@
1 1
 Deploy docker as a service
2 2
 ==========================
3 3
 
4
-Download a git repository which has a Dockerfile, build it locally, push it to a registry and create a systemd service to manage it.
4
+Download a git repository which has a Dockerfile, build it locally, push it to a registry or just download a Docker image and push it to a registry. Also create a systemd service to manage it.
5 5
 
6 6
 Requirements
7 7
 ------------
@@ -19,7 +19,8 @@ Role Variables
19 19
 * `docker_registry_read`: Domain of the registry with read access.
20 20
 * `registry_user`: User used to authenticate with the registry.
21 21
 * `registry_password`: Password used to authenticate with the registry.
22
-* `docker_tag`: Docker tag.
22
+* `docker_image`: If you want to download a docker image and not a git repository
23
+* `docker_image_tag`: Docker tag.
23 24
 * `docker_command`: Docker command used to launch the container.
24 25
 
25 26
 Dependencies

+ 50
- 5
tasks/main.yml View File

@@ -1,17 +1,36 @@
1 1
 ---
2
+- name: Log locally into private registry
3
+  local_action:
4
+    module: docker_login
5
+    registry: "{{ docker_registry }}"
6
+    username: "{{ registry_user }}"
7
+    password: "{{ registry_password }}"
8
+
2 9
 - name: Clone git repository
3 10
   local_action:
4 11
     module: git
5 12
     repo: "{{ git_repository }}"
6 13
     dest: "{{ git_repository_destination }}"
7 14
     version: "{{ git_repository_tag }}"
15
+  when: docker_image is not defined
8 16
 
9
-- name: Log locally into private registry
17
+- name: Build docker image locally and push it to a registry with tag latest
10 18
   local_action:
11
-    module: docker_login
12
-    registry: "{{ docker_registry }}"
13
-    username: "{{ registry_user }}"
14
-    password: "{{ registry_password }}"
19
+    module: docker_image
20
+    path: "{{ git_repository_destination }}/{{ git_repository_extra_path }}"
21
+    name: "{{ docker_registry }}/{{ service_name }}"
22
+    tag: latest
23
+    push: yes
24
+  when: docker_image is not defined
25
+
26
+- name: Build docker image locally and push it to a registry with real tag
27
+  local_action:
28
+    module: docker_image
29
+    path: "{{ git_repository_destination }}/{{ git_repository_extra_path }}"
30
+    name: "{{ docker_registry }}/{{ service_name }}"
31
+    tag: "{{ docker_image_tag }}"
32
+    push: yes
33
+  when: docker_image is not defined
15 34
 
16 35
 - name: Build docker image locally and push it to a registry
17 36
   local_action:
@@ -19,6 +38,32 @@
19 38
     path: "{{ git_repository_destination }}/{{ git_repository_extra_path }}"
20 39
     name: "{{ docker_registry }}/{{ service_name }}"
21 40
     push: yes
41
+  when: docker_image is not defined
42
+
43
+- name: Download image from public registry
44
+  local_action:
45
+    module: docker_image
46
+    name: "{{ docker_image }}"
47
+    tag: "{{ docker_image_tag }}"
48
+  when: docker_image is defined
49
+
50
+- name: Push image to own registry with tag latest
51
+  local_action:
52
+    module: docker_image
53
+    name: "{{ docker_image }}"
54
+    repository: "{{ docker_registry }}/{{ service_name }}"
55
+    tag: latest
56
+    push: yes
57
+  when: docker_image is defined
58
+
59
+- name: Push image to own registry with real tag
60
+  local_action:
61
+    module: docker_image
62
+    name: "{{ docker_image }}"
63
+    repository: "{{ docker_registry }}/{{ service_name }}"
64
+    tag: "{{ docker_image_tag }}"
65
+    push: yes
66
+  when: docker_image is defined
22 67
 
23 68
 - name: Create systemd service
24 69
   become: yes

Loading…
Cancel
Save