# vim: ft=yaml.ansible
---
- name: Create rallly volume folders
  file:
    name: "{{ services.rallly.volume_folder }}/postgres"
    state: directory

- name: Copy Rallly environment file
  template:
    src: files/configs/rallly/env_file.j2
    dest: "{{ services.rallly.volume_folder }}/env_file"

- name: Set up Rallly
  docker_compose:
    project_name: "rallly"
    pull: "yes"
    definition:
      version: "3.8"
      services:
        rallly_db:
          image: "postgres:{{ services.rallly.postgres_version }}"
          restart: "always"
          shm_size: "256mb"
          networks:
            rallly_internal:
          volumes:
            - "{{ services.rallly.volume_folder }}/postgres:/var/lib/postgresql/data"
          environment:
            POSTGRES_PASSWORD: "{{ postgres_passwords.rallly }}"
            POSTGRES_DB: "rallly_db"
          healthcheck:
            test: ["CMD-SHELL", "pg_isready -U postgres"]
            interval: 5s
            timeout: 5s
            retries: 5
          labels:
            com.centurylinklabs.watchtower.enable: "true"

        rallly:
          image: "lukevella/rallly:{{ services.rallly.version }}"
          restart: "always"
          networks:
            rallly_internal:
            external_services:
            postfix:
          depends_on:
            rallly_db:
              condition: "service_healthy"
          env_file:
            - "{{ services.rallly.volume_folder }}/env_file"
          environment:
            VIRTUAL_HOST: "{{ services.rallly.domain }}"
            VIRTUAL_PORT: "3000"
            LETSENCRYPT_HOST: "{{ services.rallly.domain }}"
            LETSENCRYPT_EMAIL: "{{ letsencrypt_email }}"
          labels:
            com.centurylinklabs.watchtower.enable: "true"

      networks:
        rallly_internal:
          internal: true
        external_services:
          external: true
        postfix:
          external: true