Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ _host-preseed platform:

# compose

# Deploy/remove stacks
# Up/down Docker stacks
[group('System setup')]
[arg("stack", long, short="s")]
compose action hostname='' stack='all': _check-password
Expand All @@ -60,7 +60,7 @@ compose action hostname='' stack='all': _check-password
if [ "{{action}}" = "up" ]; then
skip_tags="down"
elif [ "{{action}}" = "down" ]; then
skip_tags="deploy,up"
skip_tags="up"
else
echo "action must be 'up' or 'down'" >&2; exit 1;
fi
Expand Down
2 changes: 2 additions & 0 deletions roles/karo-compose/defaults/main/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,5 @@ karo_compose_oidc_certificate_url: "{{ karo_compose_oidc_url }}{{ karo_compose_o
# internal

karo_compose_justfile_stack: all

karo_compose_secrets_path: ""
25 changes: 0 additions & 25 deletions roles/karo-compose/tasks/deploy.yml

This file was deleted.

27 changes: 6 additions & 21 deletions roles/karo-compose/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,25 +86,7 @@
- stack.enabled
- karo_compose_justfile_stack in [stack.name, 'all']

- name: Deploy stacks
become: true
become_user: dockeruser
tags: deploy
block:
- name: Deploy docker compose stacks
ansible.builtin.include_tasks: deploy.yml
loop: "{{ karo_compose_expanded_stacks }}"
loop_control:
loop_var: stack
label: "{{ stack.name }}"
vars:
stack_vars: "{{ lookup('vars', stack.namespace ~ '_stack') }}"
stack_defaults: "{{ lookup('vars', stack.namespace ~ '_stack_defaults') }}"
when:
- stack.enabled
- karo_compose_justfile_stack in [stack.name, 'all']

- name: Create stacks
- name: Up stacks
become: true
become_user: dockeruser
tags: up
Expand All @@ -116,15 +98,18 @@
loop_var: stack
label: "{{ stack.name }}"
vars:
stack_secrets: "{{ lookup('vars', stack.namespace ~ '_secrets', default={}) | dict2items }}"
stack_vars: "{{ lookup('vars', stack.namespace ~ '_stack') }}"
stack_defaults: "{{ lookup('vars', stack.namespace ~ '_stack_defaults') }}"
stack_secrets: "{{ query('filetree', '../templates/' ~ stack.path ~ '/secrets') }}"
karo_compose_secrets_path: "/run/user/1001/karo-compose/{{ stack.path }}"
when:
- stack.enabled
- karo_compose_justfile_stack in [stack.name, 'all']

always:
- name: Discard tmpfs secrets directory
ansible.builtin.file:
path: "/run/user/1001/karo/compose"
path: "/run/user/1001/karo-compose"
state: absent
when: secrets_dir | default(false)
changed_when: false
54 changes: 40 additions & 14 deletions roles/karo-compose/tasks/up.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,58 @@

---

# deploy templates

- name: "Create compose stack directory for {{ stack.name }}"
ansible.builtin.file:
path: "/srv/docker/{{ stack.path }}"
mode: "0774"
state: directory

- name: "Merge compose variables for {{ stack.name }}"
ansible.builtin.set_fact:
compose: "{{ stack_defaults | combine(stack_vars, recursive=true) }}"

- name: "Deploy compose templates for {{ stack.name }}"
ansible.builtin.template:
src: "{{ template.src }}"
dest: "/srv/docker/{{ stack.path }}/{{ template.path | splitext | first }}"
mode: "0644"
loop: "{{ query('filetree', '../templates/' ~ stack.path, exclude='^secrets$') }}"
loop_control:
loop_var: template
label: "{{ template.path }}"

# handle secrets

- name: Prepare secrets
when:
- stack_secrets | length > 0
- secrets_dir is undefined
when: stack_secrets | length > 0
block:
- name: Create tmpfs secrets directory
ansible.builtin.file:
path: /run/user/1001/karo/compose
path: "{{ karo_compose_secrets_path }}"
state: directory
mode: "0700"
changed_when: false

- name: Mark secrets directory as created
ansible.builtin.set_fact:
secrets_dir: true
when: secrets_dir is undefined

- name: Create secrets for {{ stack.name }}
ansible.builtin.copy:
dest: "/run/user/1001/karo/compose/{{ secret.key }}"
content: "{{ secret.value }}"
mode: "0644"
loop: "{{ stack_secrets }}"
loop_control:
loop_var: secret
label: "{{ secret.key }}"
changed_when: false
- name: Create secrets for {{ stack.name }}
ansible.builtin.copy:
# secrets template, removing end of file newline
content: "{{ lookup('template', secret.src) | regex_replace('(\r?\n)$', '') }}"
dest: "{{ karo_compose_secrets_path }}/{{ secret.path | splitext | first }}"
mode: "0644"
loop: "{{ stack_secrets }}"
loop_control:
loop_var: secret
label: "{{ secret.path | splitext | first }}"
changed_when: false

# start services

- name: Up compose stack {{ stack.name }}
community.docker.docker_compose_v2:
Expand Down