From d1b2d8e6537f5b4beeefe3a9381a6795554e8a79 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Sun, 24 Dec 2023 18:48:38 +0100 Subject: [PATCH] Implemented docker-compose.yml file https://chat.openai.com/share/981ecca4-9df7-4086-b99e-1b60f2632bf6 --- roles/docker-openproject/tasks/main.yml | 43 +++++-- .../templates/docker-compose.yml.j2 | 117 ++++++++++++++++++ roles/docker-openproject/templates/env.j2 | 4 +- roles/docker-openproject/vars/main.yml | 2 + 4 files changed, 155 insertions(+), 11 deletions(-) create mode 100644 roles/docker-openproject/templates/docker-compose.yml.j2 diff --git a/roles/docker-openproject/tasks/main.yml b/roles/docker-openproject/tasks/main.yml index 66654184..e3b8ff88 100644 --- a/roles/docker-openproject/tasks/main.yml +++ b/roles/docker-openproject/tasks/main.yml @@ -2,21 +2,40 @@ - name: "include tasks nginx-docker-proxy-domain.yml" include_tasks: nginx-docker-proxy-domain.yml -- name: "create {{ repository_directory }}" - file: - path: "{{ repository_directory }}" - state: directory - mode: 0755 +- name: register repository_directory_register + stat: + path: "{{repository_directory}}" + register: repository_directory_register + +- name: checkout repository + ansible.builtin.shell: git checkout . + become: true + args: + chdir: "{{repository_directory}}" + when: repository_directory_register.stat.exists + +- name: "backup docker-compose.yml if it exists" + command: > + mv "{{ docker_compose_file_path }}" "{{ docker_compose_backup_path }}" + args: + removes: "{{ docker_compose_file_path }}" + become: true - name: pull docker repository git: repo: "https://github.com/opf/openproject-deploy" - dest: "{{repository_directory}}" + dest: "{{ repository_directory }}" update: yes notify: recreate openproject become: true register: git_result - ignore_errors: true + +- name: "restore docker-compose.yml from backup" + command: > + mv "{{ docker_compose_backup_path }}" "{{ docker_compose_file_path }}" + args: + removes: "{{ docker_compose_backup_path }}" + become: true - name: Warn if repo is not reachable debug: @@ -26,5 +45,11 @@ - name: "copy .env" template: src: env.j2 - dest: "{{docker_compose_instance_directory}}.env" - notify: recreate openproject \ No newline at end of file + dest: "{{ docker_compose_instance_directory }}.env" + notify: recreate openproject + +- name: "copy docker-compose.yml" + template: + src: docker-compose.yml.j2 + dest: "{{ docker_compose_file_path }}" + notify: recreate openproject diff --git a/roles/docker-openproject/templates/docker-compose.yml.j2 b/roles/docker-openproject/templates/docker-compose.yml.j2 new file mode 100644 index 00000000..ebc2193d --- /dev/null +++ b/roles/docker-openproject/templates/docker-compose.yml.j2 @@ -0,0 +1,117 @@ +version: "3.7" + +networks: + frontend: + backend: + +volumes: + pgdata: + opdata: + +x-op-restart-policy: &restart_policy + restart: unless-stopped +x-op-image: &image + image: openproject/community:${TAG:-13} +x-op-app: &app + <<: [*image, *restart_policy] + environment: + OPENPROJECT_HTTPS: "${OPENPROJECT_HTTPS:-true}" + OPENPROJECT_HOST__NAME: "${OPENPROJECT_HOST__NAME:-localhost:8080}" + OPENPROJECT_HSTS: "${OPENPROJECT_HSTS:-true}" + RAILS_CACHE_STORE: "memcache" + OPENPROJECT_CACHE__MEMCACHE__SERVER: "cache:11211" + OPENPROJECT_RAILS__RELATIVE__URL__ROOT: "${OPENPROJECT_RAILS__RELATIVE__URL__ROOT:-}" + DATABASE_URL: "${DATABASE_URL:-postgres://postgres:p4ssw0rd@db/openproject?pool=20&encoding=unicode&reconnect=true}" + RAILS_MIN_THREADS: ${RAILS_MIN_THREADS:-4} + RAILS_MAX_THREADS: ${RAILS_MAX_THREADS:-16} + # set to true to enable the email receiving feature. See ./docker/cron for more options + IMAP_ENABLED: "${IMAP_ENABLED:-false}" + volumes: + - "${OPDATA:-opdata}:/var/openproject/assets" + +services: + db: + image: postgres:13 + <<: *restart_policy + stop_grace_period: "3s" + volumes: + - "${PGDATA:-pgdata}:/var/lib/postgresql/data" + environment: + POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-p4ssw0rd} + POSTGRES_DB: openproject + networks: + - backend + + cache: + image: memcached + <<: *restart_policy + networks: + - backend + + proxy: + <<: [*image, *restart_policy] + command: "./docker/prod/proxy" + ports: + - "${PORT:-8080}:80" + environment: + APP_HOST: web + OPENPROJECT_RAILS__RELATIVE__URL__ROOT: "${OPENPROJECT_RAILS__RELATIVE__URL__ROOT:-}" + depends_on: + - web + networks: + - frontend + + web: + <<: *app + command: "./docker/prod/web" + networks: + - frontend + - backend + depends_on: + - db + - cache + - seeder + labels: + - autoheal=true + healthcheck: + test: ["CMD", "curl", "-f", "http://localhost:8080${OPENPROJECT_RAILS__RELATIVE__URL__ROOT:-}/health_checks/default"] + interval: 10s + timeout: 3s + retries: 3 + start_period: 30s + + autoheal: + image: willfarrell/autoheal:1.2.0 + volumes: + - "/var/run/docker.sock:/var/run/docker.sock" + environment: + AUTOHEAL_CONTAINER_LABEL: autoheal + AUTOHEAL_START_PERIOD: 600 + AUTOHEAL_INTERVAL: 30 + + worker: + <<: *app + command: "./docker/prod/worker" + networks: + - backend + depends_on: + - db + - cache + - seeder + + cron: + <<: *app + command: "./docker/prod/cron" + networks: + - backend + depends_on: + - db + - cache + - seeder + + seeder: + <<: *app + command: "./docker/prod/seeder" + restart: on-failure + networks: + - backend \ No newline at end of file diff --git a/roles/docker-openproject/templates/env.j2 b/roles/docker-openproject/templates/env.j2 index 699330f2..7c4e79b5 100644 --- a/roles/docker-openproject/templates/env.j2 +++ b/roles/docker-openproject/templates/env.j2 @@ -18,5 +18,5 @@ RAILS_MIN_THREADS=4 RAILS_MAX_THREADS=16 # The following volumes are default -# PGDATA="pgdata" -# OPDATA="opdata" \ No newline at end of file +PGDATA="pgdata" +OPDATA="opdata" \ No newline at end of file diff --git a/roles/docker-openproject/vars/main.yml b/roles/docker-openproject/vars/main.yml index 982d3bea..fff8f0bd 100644 --- a/roles/docker-openproject/vars/main.yml +++ b/roles/docker-openproject/vars/main.yml @@ -1,2 +1,4 @@ repository_directory: "{{ path_docker_compose_instances }}openproject/" docker_compose_instance_directory: "{{repository_directory}}compose/" +docker_compose_file_path: "{{docker_compose_instance_directory}}docker-compose.yml" +docker_compose_backup_path: "/tmp/openproject-docker-compose-backup.yml" \ No newline at end of file