diff --git a/playbooks/heyer.systems/docker1.yml b/playbooks/heyer.systems/docker1.yml index 98ab198..f88570b 100644 --- a/playbooks/heyer.systems/docker1.yml +++ b/playbooks/heyer.systems/docker1.yml @@ -45,4 +45,9 @@ - role: deploy_container_lldap tags: - lldap - - docker-container \ No newline at end of file + - docker-container + + - role: deploy_container_booklore + tags: + - booklore + - docker-container diff --git a/roles/deploy_container_booklore/defaults/main.yml b/roles/deploy_container_booklore/defaults/main.yml new file mode 100644 index 0000000..7fa2ebe --- /dev/null +++ b/roles/deploy_container_booklore/defaults/main.yml @@ -0,0 +1,6 @@ +container_booklore_version: latest +container_booklore_domain: booklore.example.com +container_booklore_directory: /opt/docker/booklore +container_booklore_db_root_password: super_duper_secret_root_password +container_booklore_db_user: db_user +container_booklore_db_password: super_secret_password \ No newline at end of file diff --git a/roles/deploy_container_booklore/handlers/main.yml b/roles/deploy_container_booklore/handlers/main.yml new file mode 100644 index 0000000..e69de29 diff --git a/roles/deploy_container_booklore/meta/main.yml b/roles/deploy_container_booklore/meta/main.yml new file mode 100644 index 0000000..e69de29 diff --git a/roles/deploy_container_booklore/tasks/main.yml b/roles/deploy_container_booklore/tasks/main.yml new file mode 100644 index 0000000..d013145 --- /dev/null +++ b/roles/deploy_container_booklore/tasks/main.yml @@ -0,0 +1,28 @@ +--- +- name: Ensure data directories exist + ansible.builtin.file: + path: "{{ container_booklore_directory }}/data/{{ item }}" + state: directory + mode: '0755' + loop: + - "app" + - "books" + - "db" + become: false + +- name: Deploy Docker Compose and .env files + ansible.builtin.template: + src: "{{ item.src }}" + dest: "{{ container_booklore_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_booklore_directory }}" + pull: always + docker_host: "unix:///run/user/1000/docker.sock" + become: false diff --git a/roles/deploy_container_booklore/templates/.env.j2 b/roles/deploy_container_booklore/templates/.env.j2 new file mode 100644 index 0000000..45333ad --- /dev/null +++ b/roles/deploy_container_booklore/templates/.env.j2 @@ -0,0 +1,10 @@ +# Booklore Version (Standard: latest) # Excalidraw Version (Standard: latest) +BOOKLORE_VERSION={{ container_booklore_version }} + +# Booklore Domain +BOOKLORE_DOMAIN={{ container_booklore_domain }} + +# Booklore DB +BOOKLORE_DB_ROOT_PASSWORD={{ container_booklore_db_root_password }} +BOOKLORE_DB_USER={{ container_booklore_db_user }} +BOOKLORE_DB_PASSWORD={{ container_booklore_db_password }} \ No newline at end of file diff --git a/roles/deploy_container_booklore/templates/docker-compose.yml.j2 b/roles/deploy_container_booklore/templates/docker-compose.yml.j2 new file mode 100644 index 0000000..3a0c66d --- /dev/null +++ b/roles/deploy_container_booklore/templates/docker-compose.yml.j2 @@ -0,0 +1,63 @@ +--- +services: + booklore: + image: ghcr.io/adityachandelgit/booklore-app:${BOOKLORE_VERSION:-latest} + container_name: booklore + restart: unless-stopped + depends_on: + mariadb: + condition: service_healthy + networks: + - traefik + - booklore + volumes: + - ./data/app:/app/data + - ./data/books:/books + environment: + - PUID=1000 + - PGID=1000 + - TZ=Europe/Berlin + - DATABASE_URL=jdbc:mariadb://mariadb:3306/booklore + - DATABASE_USERNAME=${BOOKLORE_DB_USER:-booklore} + - DATABASE_PASSWORD=${BOOKLORE_DB_PASSWORD} + - SWAGGER_ENABLED=false + labels: + - "traefik.enable=true" + - "traefik.docker.network=traefik" + - "traefik.http.routers.booklore.entrypoints=http" + - "traefik.http.routers.booklore.rule=Host(`${BOOKLORE_DOMAIN:?error}`)" + - "traefik.http.middlewares.booklore-https-redirect.redirectscheme.scheme=https" + - "traefik.http.routers.booklore.middlewares=booklore-https-redirect" + - "traefik.http.routers.booklore-secure.entrypoints=https" + - "traefik.http.routers.booklore-secure.rule=Host(`${BOOKLORE_DOMAIN:?error}`)" + - "traefik.http.routers.booklore-secure.tls=true" + - "traefik.http.routers.booklore-secure.service=booklore" + - "traefik.http.services.booklore.loadbalancer.server.port=6060" + + mariadb: + image: lscr.io/linuxserver/mariadb:11.4.5 + container_name: mariadb + networks: + - booklore + environment: + - PUID=1000 + - PGID=1000 + - TZ=Etc/UTC + - MYSQL_ROOT_PASSWORD=${BOOKLORE_DB_ROOT_PASSWORD} + - MYSQL_DATABASE=booklore + - MYSQL_USER=${BOOKLORE_DB_USER:-booklore} + - MYSQL_PASSWORD=${BOOKLORE_DB_PASSWORD} + volumes: + - ./data/db:/config + restart: unless-stopped + healthcheck: + test: ["CMD", "mariadb-admin", "ping", "-h", "localhost"] + interval: 5s + timeout: 5s + retries: 10 + +networks: + traefik: + external: true + booklore: + driver: bridge \ No newline at end of file diff --git a/roles/deploy_container_booklore/vars/main.yml b/roles/deploy_container_booklore/vars/main.yml new file mode 100644 index 0000000..e69de29