From dd0de3139e8fc2f6dd036c6b08d7d4d4fff041f7 Mon Sep 17 00:00:00 2001 From: dogeystamp Date: Sun, 27 Aug 2023 20:33:18 -0400 Subject: [PATCH] roles/containers: got gitea container up --- roles/containers/defaults/main.yml | 2 +- roles/containers/tasks/main.yml | 15 ++++++++++++++- .../templates/docker-compose.service.j2 | 2 ++ roles/containers/templates/docker-compose.yml.j2 | 2 +- 4 files changed, 18 insertions(+), 3 deletions(-) diff --git a/roles/containers/defaults/main.yml b/roles/containers/defaults/main.yml index b3ace9d..d37b62e 100644 --- a/roles/containers/defaults/main.yml +++ b/roles/containers/defaults/main.yml @@ -3,4 +3,4 @@ # these are defaults # change these in group/host vars -docker_compose_dir: "/opts/services" +docker_compose_dir: "/opt/services" diff --git a/roles/containers/tasks/main.yml b/roles/containers/tasks/main.yml index 92ae258..c4e620a 100644 --- a/roles/containers/tasks/main.yml +++ b/roles/containers/tasks/main.yml @@ -6,6 +6,11 @@ - docker - docker-compose +- name: Create docker user + user: + name: docker + group: docker + - name: Create docker-compose directory ansible.builtin.file: path: "{{ docker_compose_dir }}" @@ -17,6 +22,7 @@ template: src: "docker-compose.yml.j2" dest: "{{ docker_compose_dir }}/docker-compose.yml" + register: docker-comp - name: Create systemd unit file template: @@ -26,5 +32,12 @@ - name: Compose up systemd: name: docker-compose - state: started + state: "{{ 'restarted' if docker-comp.changed else 'started' }}" enabled: true + +# for some reason port mappings don't work without this? +- name: Restart docker for good measure + systemd: + name: docker + state: restarted + when: docker-comp.changed diff --git a/roles/containers/templates/docker-compose.service.j2 b/roles/containers/templates/docker-compose.service.j2 index 659edfb..3396604 100644 --- a/roles/containers/templates/docker-compose.service.j2 +++ b/roles/containers/templates/docker-compose.service.j2 @@ -4,6 +4,8 @@ Requires=docker.service After=docker.service [Service] +User=docker +Group=docker WorkingDirectory={{ docker_compose_dir }} ExecStartPre=-/usr/bin/docker compose pull ExecStart=/usr/bin/docker compose up --remove-orphans diff --git a/roles/containers/templates/docker-compose.yml.j2 b/roles/containers/templates/docker-compose.yml.j2 index 126ab8a..bccc685 100644 --- a/roles/containers/templates/docker-compose.yml.j2 +++ b/roles/containers/templates/docker-compose.yml.j2 @@ -23,6 +23,6 @@ services: - /etc/localtime:/etc/localtime:ro ports: - "3000:3000" - - "222:22" + - "2499:22" {% endif %}