Преглед на файлове

[26] - First iteration

* Systemd template
* Clone git, build docker, push to registry, pull in remote server and
  deploy systemd service
tags/v1.0.0^2
drymer преди 1 година
родител
ревизия
126bd67a69
променени са 5 файла, в които са добавени 126 реда и са изтрити 2 реда
  1. 63
    2
      README.md
  2. 1
    0
      TODO
  3. 15
    0
      files/systemd-service.template
  4. 10
    0
      meta/main.yml
  5. 37
    0
      tasks/main.yml

+ 63
- 2
README.md Целия файл

@@ -1,3 +1,64 @@
1
-# deploy-docker
1
+Deploy docker as a service
2
+==========================
2 3
 
3
-Build a docker image and push it to a registry.
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.
5
+
6
+Requirements
7
+------------
8
+
9
+None.
10
+
11
+Role Variables
12
+--------------
13
+
14
+* `git_repository`: The repository in which the dockerfile is located.
15
+* `git_repository_destination`: Local path in which to clone the git repository.
16
+* `git_repository_tag`: Version to use of the git repository.
17
+* `service_name`: Name of the systemd service.
18
+* `docker_registry`: Domain of the registry with write access.
19
+* `docker_registry_read`: Domain of the registry with read access.
20
+* `registry_user`: User used to authenticate with the registry.
21
+* `registry_password`: Password used to authenticate with the registry.
22
+* `docker_tag`: Docker tag.
23
+* `docker_command`: Docker command used to launch the container.
24
+
25
+Dependencies
26
+------------
27
+
28
+None.
29
+
30
+Example Playbook
31
+----------------
32
+
33
+```yaml
34
+- hosts: servers
35
+  vars:
36
+    git_repository: https://git.digitales.cslabrecha.org/La_Brecha_Digital/prosody-docker
37
+    git_repository_destination: /home/drymer/Proyectos/LaBrechaDigital/prosody-docker
38
+    git_repository_tag: v0.1.1
39
+    service_name: prosody
40
+    docker_registry: r.daemons.it
41
+    docker_registry_read: registry.daemons.it
42
+    registry_user: drymer
43
+    registry_password: whatever
44
+    docker_tag: "{{ git_repository_tag }}"
45
+    docker_command: /usr/bin/docker run --rm -i -v /root/docker/prosody/conf:/etc/prosody/ -v /root/docker/prosody/ssl:/etc/prosody/certs/ -v /root/docker/prosody/modules:/usr/lib/prosody/modules/extra:ro -v /root/docker/prosody/logs:/var/log/prosody/ -v /root/docker/prosody/images/:/var/lib/prosody/ -e LOCAL=admin -e DOMAIN=daemons.it -e PASSWORD=qv9NEdTBYxBv78rIfNOBVZIeICuRc -p 5222:5222 -p 5269:5269 -p 5280:5280 -p 5281:5281 --name "{{ service_name }}" "{{ docker_registry_read }}/{{ service_name }}"
46
+  roles:
47
+    - { role: deploy-docker}
48
+```
49
+
50
+Compatible
51
+----------
52
+
53
+With:
54
+  - Debian 9
55
+
56
+License
57
+-------
58
+
59
+GPL3
60
+
61
+Author Information
62
+------------------
63
+
64
+drymer [ EN ] autistici.org

+ 1
- 0
TODO Целия файл

@@ -0,0 +1 @@
1
+Molecule tests

+ 15
- 0
files/systemd-service.template Целия файл

@@ -0,0 +1,15 @@
1
+[Unit]
2
+Description={{ service_name }}
3
+Requires=docker.service
4
+Wants=docker.service
5
+
6
+[Service]
7
+TimeoutStartSec=100
8
+Restart=always
9
+RestartSec=2s
10
+
11
+ExecStop=/usr/bin/docker stop {{ service_name }}
12
+ExecStart={{ docker_command }}
13
+
14
+[Install]
15
+WantedBy=multi-user.target

+ 10
- 0
meta/main.yml Целия файл

@@ -0,0 +1,10 @@
1
+galaxy_info:
2
+  author: drymer ( drymer [ EN ] autistici.org )
3
+  description: Deploy docker services.
4
+  min_ansible_version: 2.3
5
+  license: GPLv3
6
+
7
+  platforms:
8
+  - name: Debian
9
+    versions:
10
+    - stretch

+ 37
- 0
tasks/main.yml Целия файл

@@ -0,0 +1,37 @@
1
+---
2
+- name: Clone git repository
3
+  local_action:
4
+    module: git
5
+    repo: "{{ git_repository }}"
6
+    dest: "{{ git_repository_destination }}"
7
+    version: "{{ git_repository_tag }}"
8
+
9
+- name: Log locally into private registry
10
+  local_action:
11
+    module: docker_login
12
+    registry: "{{ docker_registry }}"
13
+    username: "{{ registry_user }}"
14
+    password: "{{ registry_password }}"
15
+
16
+- name: Build docker image locally and push it to a registry
17
+  local_action:
18
+    module: docker_image
19
+    path: "{{ git_repository_destination }}/{{ git_repository_extra_path }}"
20
+    name: "{{ docker_registry }}/{{ service_name }}"
21
+    push: yes
22
+
23
+- name: Create systemd service
24
+  become: yes
25
+  template:
26
+    src: "{{ role_path }}/files/systemd-service.template"
27
+    dest: "/etc/systemd/system/{{ service_name }}.service"
28
+    owner: root
29
+    group: root
30
+
31
+- name: Enable systemd service and start it
32
+  become: yes
33
+  systemd:
34
+    name: "{{ service_name }}"
35
+    enabled: yes
36
+    daemon_reload: yes
37
+    state: started

Loading…
Отказ
Запис