-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(feat) add watchtower for cheap container updates
- Loading branch information
1 parent
f06eb6a
commit a3b1aae
Showing
7 changed files
with
90 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
- name: Setup Watchtower | ||
hosts: all | ||
pre_tasks: | ||
- name: Include Variables | ||
ansible.builtin.include_vars: config.yml | ||
|
||
roles: | ||
- watchtower |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
# Specifies the watchtower docker image to be used. | ||
watchtower_docker_image: "containrrr/watchtower:latest" | ||
|
||
# Specifies the watchtower path, owner and group. | ||
watchtower_docker_path: /opt/watchtower | ||
watchtower_docker_owner: root | ||
watchtower_docker_group: root | ||
|
||
# Specifies the watchtower command | ||
watchtower_docker_command: "--debug" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
- name: Restart watchtower container | ||
ansible.builtin.command: >- | ||
docker compose --ansi never --progress plain restart | ||
args: | ||
chdir: "{{ watchtower_docker_path }}" | ||
changed_when: true | ||
listen: restart watchtower |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
- name: Create watchtower directory | ||
ansible.builtin.file: | ||
path: "{{ watchtower_docker_path }}" | ||
owner: "{{ watchtower_docker_owner }}" | ||
group: "{{ watchtower_docker_group }}" | ||
state: directory | ||
mode: 0755 | ||
|
||
- name: Create watchtower docker compose deployment | ||
ansible.builtin.template: | ||
src: docker-compose.yml.j2 | ||
dest: "{{ watchtower_docker_path }}/docker-compose.yml" | ||
owner: "{{ watchtower_docker_owner }}" | ||
group: "{{ watchtower_docker_group }}" | ||
trim_blocks: false | ||
mode: 0644 | ||
notify: restart watchtower | ||
|
||
- name: Validate watchtower docker compose deployment | ||
ansible.builtin.command: docker compose config --quiet | ||
args: | ||
chdir: "{{ watchtower_docker_path }}" | ||
changed_when: false | ||
|
||
- name: Startup watchtower docker compose deployment | ||
ansible.builtin.command: >- | ||
docker compose --ansi never --progress plain up --detach | ||
args: | ||
chdir: "{{ watchtower_docker_path }}" | ||
register: watchtower_container_startup | ||
changed_when: "'Started' in watchtower_container_startup.stdout" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{{ ansible_managed | comment }} | ||
--- | ||
services: | ||
watchtower: | ||
image: "{{ watchtower_docker_image }}" | ||
container_name: watchtower | ||
restart: unless-stopped | ||
logging: | ||
driver: json-file | ||
options: | ||
max-size: "100m" | ||
max-file: "10" | ||
command: "{{ watchtower_docker_command }}" | ||
volumes: | ||
- "/etc/localtime:/etc/localtime:ro" | ||
- "/var/run/docker.sock:/var/run/docker.sock:ro" |