diff --git a/roles/deploy_container_koito/defaults/main.yml b/roles/deploy_container_koito/defaults/main.yml new file mode 100644 index 0000000..18796d0 --- /dev/null +++ b/roles/deploy_container_koito/defaults/main.yml @@ -0,0 +1,4 @@ +container_koito_version: latest +container_koito_domain: music.heyer.systems +container_koito_directory: /opt/docker/koito +container_koito_db_password: "super_secret_db_password" diff --git a/roles/deploy_container_koito/handlers/main.yml b/roles/deploy_container_koito/handlers/main.yml new file mode 100644 index 0000000..e69de29 diff --git a/roles/deploy_container_koito/meta/main.yml b/roles/deploy_container_koito/meta/main.yml new file mode 100644 index 0000000..e69de29 diff --git a/roles/deploy_container_koito/tasks/main.yml b/roles/deploy_container_koito/tasks/main.yml new file mode 100644 index 0000000..3e2c4aa --- /dev/null +++ b/roles/deploy_container_koito/tasks/main.yml @@ -0,0 +1,27 @@ +--- +- name: Ensure data directories exist + ansible.builtin.file: + path: "{{ container_koito_directory }}/data/{{ item }}" + state: directory + mode: '0755' + loop: + - "db" + - "koito" + become: false + +- name: Deploy Docker Compose and .env files + ansible.builtin.template: + src: "{{ item.src }}" + dest: "{{ container_koito_directory }}/{{ item.dest }}" + mode: '0644' + loop: + - { src: 'docker-compose.yml.j2', dest: 'docker-compose.yml' } + - { src: '.env.j2', dest: '.env' } + become: false + +- name: Start Container + community.docker.docker_compose_v2: + project_src: "{{ container_koito_directory }}" + pull: always + docker_host: "unix:///run/user/1000/docker.sock" + become: false diff --git a/roles/deploy_container_koito/templates/.env.j2 b/roles/deploy_container_koito/templates/.env.j2 new file mode 100644 index 0000000..406abf4 --- /dev/null +++ b/roles/deploy_container_koito/templates/.env.j2 @@ -0,0 +1,3 @@ +KOITO_VERSION={{ container_koito_version }} +KOITO_DOMAIN={{ container_koito_domain }} +KOITO_DB_PASSWORD={{ container_koito_db_password}} \ No newline at end of file diff --git a/roles/deploy_container_koito/templates/docker-compose.yml.j2 b/roles/deploy_container_koito/templates/docker-compose.yml.j2 new file mode 100644 index 0000000..081e8c3 --- /dev/null +++ b/roles/deploy_container_koito/templates/docker-compose.yml.j2 @@ -0,0 +1,47 @@ +--- +services: + koito: + image: gabehf/koito:${KOITO_VERSION} + container_name: koito + depends_on: + - db + networks: + - traefik + - koito + environment: + - KOITO_DATABASE_URL=postgres://postgres:${KOITO_DB_PASSWORD}@db:5432/koitodb?sslmode=disable + - KOITO_ALLOWED_HOSTS=${KOITO_DOMAIN} + volumes: + - ./data/koito:/etc/koito + labels: + - "traefik.enable=true" + - "traefik.docker.network=traefik" + - "traefik.http.routers.koito.entrypoints=http" + - "traefik.http.routers.koito.rule=Host(`${KOITO_DOMAIN}`)" + - "traefik.http.middlewares.koito-https-redirect.redirectscheme.scheme=https" + - "traefik.http.routers.koito.middlewares=koito-https-redirect" + - "traefik.http.routers.koito-secure.entrypoints=https" + - "traefik.http.routers.koito-secure.rule=Host(`${KOITO_DOMAIN}`)" + - "traefik.http.routers.koito-secure.tls=true" + - "traefik.http.routers.koito-secure.service=koito" + - "traefik.http.services.koito.loadbalancer.server.port=4110" + restart: unless-stopped + + db: + image: postgres:16 + container_name: koito-db + restart: unless-stopped + networks: + - koito + environment: + POSTGRES_DB: koitodb + POSTGRES_USER: postgres + POSTGRES_PASSWORD: ${KOITO_DB_PASSWORD} + volumes: + - ./data/db:/var/lib/postgresql/data + +networks: + traefik: + external: true + koito: + driver: bridge \ No newline at end of file diff --git a/roles/deploy_container_koito/vars/main.yml b/roles/deploy_container_koito/vars/main.yml new file mode 100644 index 0000000..e69de29