From dd2e11392bce2edff0dd4f067491a629be0c81ee Mon Sep 17 00:00:00 2001 From: Michael Weimann Date: Thu, 26 Aug 2021 19:49:06 +0200 Subject: [PATCH] switch to docker-compose :ugly: --- Pipfile | 11 ++++++ tasks/main.yml | 70 +++++---------------------------- templates/config.js.j2 | 7 ++++ templates/docker-compose.yml.j2 | 48 ++++++++++++++++++++++ 4 files changed, 76 insertions(+), 60 deletions(-) create mode 100644 Pipfile create mode 100644 templates/config.js.j2 create mode 100644 templates/docker-compose.yml.j2 diff --git a/Pipfile b/Pipfile new file mode 100644 index 0000000..22d660a --- /dev/null +++ b/Pipfile @@ -0,0 +1,11 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] + +[dev-packages] + +[requires] +python_version = "3.8" diff --git a/tasks/main.yml b/tasks/main.yml index 327dbef..2198627 100644 --- a/tasks/main.yml +++ b/tasks/main.yml @@ -3,77 +3,27 @@ # SPDX-License-Identifier: AGPL-3.0-or-later --- -- name: be sure the ki network exists - community.general.docker_network: - name: ki - -- name: "be sure the {{ item }} volume exists" - docker_volume: - name: "{{ item }}" - with_items: - - ki_data - - ki_db - - name: be sure the ki config directory exists become: true file: - path: /etc/ki + path: /var/docker/ki state: directory owner: root group: root mode: "0755" -- name: be sure the ki-frontend config file is in place +- name: be sure the ki files are in place become: true template: - src: frontend.js - dest: /etc/ki/frontend.js + src: "{{ item }}.j2" + dest: "/var/docker/ki/{{ item }}" owner: root group: root mode: "0655" + with_items: + - config.js + - docker-compose.yml -- name: be sure the ki_database container is running - community.general.docker_container: - name: ki_db - image: "{{ ki_db_image }}" - pull: no - restart_policy: unless-stopped - env: - MYSQL_ROOT_PASSWORD: "{{ ki_db_root_password }}" - MYSQL_DATABASE: ki - MYSQL_USER: ki - MYSQL_PASSWORD: "{{ ki_db_password }}" - volumes: - - ki_db:/var/lib/mysql/ - networks: - - name: ki - -- name: be sure the ki_backend container is running - community.general.docker_container: - name: ki_backend - image: "{{ ki_backend_image }}" - pull: yes - restart_policy: unless-stopped - env: - SQLALCHEMY_DATABASE_URI: "mariadb+pymysql://ki:{{ ki_db_password }}@ki_db:3306/ki" - FLASK_ENV: "development" - KI_LOGLEVEL: "10" - KI_AUTH: "file" - CORS_ORIGINS: "{{ ki_frontend_uri }}" - ports: - - "{{ ki_backend_port }}:5000" - volumes: - - ki_data:/app/data/ - networks: - - name: ki - -- name: be sure the ki_frontend container is running - community.general.docker_container: - name: ki_frontend - image: "{{ ki_frontend_image }}" - pull: yes - restart_policy: unless-stopped - ports: - - "{{ ki_frontend_port }}:80" - volumes: - - /etc/ki/frontend.js:/usr/share/nginx/html/config.js +- name: be sure the ki services are running + community.docker.docker_compose: + project_src: /var/docker/ki diff --git a/templates/config.js.j2 b/templates/config.js.j2 new file mode 100644 index 0000000..44a9133 --- /dev/null +++ b/templates/config.js.j2 @@ -0,0 +1,7 @@ +// SPDX-FileCopyrightText: 2021 WTF Kooperative eG +// +// SPDX-License-Identifier: AGPL-3.0-or-later + +window.ki = { + apiUrl: '{{ ki_backend_uri }}' +} diff --git a/templates/docker-compose.yml.j2 b/templates/docker-compose.yml.j2 new file mode 100644 index 0000000..811e014 --- /dev/null +++ b/templates/docker-compose.yml.j2 @@ -0,0 +1,48 @@ +version: "3" + +networks: + ki: + +volumes: + ki_data: + ki_db: + +services: + backend: + image: "{{ ki_backend_image }}" + restart: unless-stopped + depends_on: + - db + networks: + - ki + environment: + SQLALCHEMY_DATABASE_URI: "mariadb+pymysql://ki:{{ ki_db_password }}@ki_db:3306/ki" + FLASK_ENV: "development" + KI_LOGLEVEL: "10" + KI_AUTH: "file" + CORS_ORIGINS: "{{ ki_frontend_uri }}" + volumes: + - ki_data:/app/data/ + ports: + - "{{ ki_backend_port }}:5000" + frontend: + image: "{{ ki_frontend_image }}" + restart: unless-stopped + depends_on: + - backend + volumes: + - ./config.js:/usr/share/nginx/html/config.js + ports: + - "{{ ki_frontend_port }}:80" + db: + image: "{{ ki_db_image }}" + restart: unless-stopped + networks: + - ki + environment: + MYSQL_ROOT_PASSWORD: "{{ ki_db_root_password }}" + MYSQL_DATABASE: ki + MYSQL_USER: ki + MYSQL_PASSWORD: "{{ ki_db_password }}" + volumes: + - ki_db:/var/lib/mysql/