From 6aef4d222c9442b5b4819561d1102c04311f5096 Mon Sep 17 00:00:00 2001 From: Bryan Joshua Pedini Date: Thu, 27 Oct 2022 08:41:50 +0200 Subject: [PATCH] turned base into guacamole deployment --- docker-compose.yml | 55 +++++++++++++++++++++++++++++++++++++++++----- env.example | 36 +++++++++++++++++++++++++----- init.sh | 37 +++++++++++++++++++++++++++++++ start.sh | 16 ++++++++++++++ 4 files changed, 132 insertions(+), 12 deletions(-) create mode 100755 init.sh create mode 100755 start.sh diff --git a/docker-compose.yml b/docker-compose.yml index cf8e041..2b01382 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,17 @@ --- services: - app: + guacamole: + image: guacamole/guacamole:${GUACAMOLE_VERSION} restart: unless-stopped + depends_on: + - guacd + - mariadb + environment: + - GUACD_HOSTNAME=guacd + - MYSQL_HOSTNAME=mariadb + - MYSQL_DATABASE=${MARIADB_NAME} + - MYSQL_USER=${MARIADB_USER} + - MYSQL_PASSWORD=${MARIADB_PASS} labels: ### Section Træfik - traefik.enable=${TRAEFIK_ENABLED} @@ -22,15 +32,48 @@ services: # specify a service so a custom port can be used - traefik.http.services.${TRAEFIK_SERVICE}.loadbalancer.server.port=${TRAEFIK_SERVICE_PORT} ### Section Diun - - diun.enable=${DIUN_ENABLE} - - diun.watch_repo=${DIUN_WATCHREPO} - - diun.sort_tags=${DIUN_SORTALGO} - - diun.include_tags=${DIUN_INCLUDE} - - diun.exclude_tags=${DIUN_EXCLUDE} + - diun.enable=${DIUN_GUACAMOLE_ENABLE} + - diun.watch_repo=${DIUN_GUACAMOLE_WATCHREPO} + - diun.sort_tags=${DIUN_GUACAMOLE_SORTALGO} + - diun.include_tags=${DIUN_GUACAMOLE_INCLUDE} + - diun.exclude_tags=${DIUN_GUACAMOLE_EXCLUDE} networks: + - internal - traefik + guacd: + image: guacamole/guacd:${GUACD_VERSION} + restart: unless-stopped + labels: + ### Section Diun + - diun.enable=${DIUN_GUACD_ENABLE} + - diun.watch_repo=${DIUN_GUACD_WATCHREPO} + - diun.sort_tags=${DIUN_GUACD_SORTALGO} + - diun.include_tags=${DIUN_GUACD_INCLUDE} + - diun.exclude_tags=${DIUN_GUACD_EXCLUDE} + networks: + - internal + mariadb: + image: mariadb:${MARIADB_VERSION} + restart: unless-stopped + environment: + - MARIADB_ROOT_PASSWORD=${MARIADB_ROOT} + - MARIADB_DATABASE=${MARIADB_NAME} + - MARIADB_USER=${MARIADB_USER} + - MARIADB_PASSWORD=${MARIADB_PASS} + labels: + ### Section Diun + - diun.enable=${DIUN_MARIADB_ENABLE} + - diun.watch_repo=${DIUN_MARIADB_WATCHREPO} + - diun.sort_tags=${DIUN_MARIADB_SORTALGO} + - diun.include_tags=${DIUN_MARIADB_INCLUDE} + - diun.exclude_tags=${DIUN_MARIADB_EXCLUDE} + networks: + - internal + volumes: + - ${MARIADB_DATA}:/var/lib/mysql networks: + internal: traefik: external: true name: ${TRAEFIK_NETWORK} diff --git a/env.example b/env.example index 263f7aa..6a6bc1f 100644 --- a/env.example +++ b/env.example @@ -3,7 +3,7 @@ TRAEFIK_ENABLED=true TRAEFIK_NETWORK=traefik TRAEFIK_ROUTER=app_example_com TRAEFIK_SERVICE=app_example_com -TRAEFIK_SERVICE_PORT=80 +TRAEFIK_SERVICE_PORT=8080 TRAEFIK_MATCHRULE=Host(`app.example.com`) TRAEFIK_TLSENABLED=true TRAEFIK_CERTRESOLVER=letsencrypt @@ -11,8 +11,32 @@ TRAEFIK_HTTP_MIDDLEWARES=http-to-https TRAEFIK_HTTPS_MIDDLEWARES=hsts # Diun -DIUN_ENABLE=true -DIUN_WATCHREPO=true -DIUN_SORTALGO=semver -DIUN_INCLUDE= -DIUN_EXCLUDE= +DIUN_GUACAMOLE_ENABLE=true +DIUN_GUACAMOLE_WATCHREPO=true +DIUN_GUACAMOLE_SORTALGO=semver +DIUN_GUACAMOLE_INCLUDE=([0-9]+)\.([0-9]+)\.([0-9]+) +DIUN_GUACAMOLE_EXCLUDE= +DIUN_GUACD_ENABLE=true +DIUN_GUACD_WATCHREPO=true +DIUN_GUACD_SORTALGO=semver +DIUN_GUACD_INCLUDE=([0-9]+)\.([0-9]+)\.([0-9]+) +DIUN_GUACD_EXCLUDE= +DIUN_MARIADB_ENABLE=true +DIUN_MARIADB_WATCHREPO=true +DIUN_MARIADB_SORTALGO=semver +DIUN_MARIADB_INCLUDE=([0-9]+)\.([0-9]+)\.([0-9]+) +DIUN_MARIADB_EXCLUDE= + +# Guacamole +GUACAMOLE_VERSION=1.4.0 + +# Guacd +GUACD_VERSION=1.4.0 + +# MariaDB +MARIADB_VERSION=10.9.3 +MARIADB_DATA=./data/mariadb +MARIADB_ROOT= +MARIADB_NAME=guacamole +MARIADB_USER=guacamole +MARIADB_PASS= diff --git a/init.sh b/init.sh new file mode 100755 index 0000000..b355029 --- /dev/null +++ b/init.sh @@ -0,0 +1,37 @@ +#!/usr/bin/env bash +set -e +WAIT_TIMEOUT=10 + +# Retrieve proper environment variables +GUACAMOLE_VERSION=$(cat .env | grep GUACAMOLE_VERSION | sed 's/GUACAMOLE_VERSION=//') +MARIADB_NAME=$(cat .env | grep MARIADB_NAME | sed 's/MARIADB_NAME=//') + +# Pull the Guacamole image +docker pull guacamole/guacamole:"${GUACAMOLE_VERSION}" + +# Generate initial database schema from Guacamole's image +docker run -it --rm \ + guacamole/guacamole:"${GUACAMOLE_VERSION}" \ + /opt/guacamole/bin/initdb.sh \ + --mysql > initdb.sql + +# Start the database instance +docker compose up -d mariadb + +# Wait a couple of seconds that the database is ready +for I in $(eval echo "{$WAIT_TIMEOUT..1}"); do + printf " ${I}" + sleep 1 +done +echo + +# Initialize the database +docker compose exec \ + --no-TTY -e MARIADB_NAME="${MARIADB_NAME}" mariadb \ + sh -c 'exec mysql -uroot -p"$MARIADB_ROOT_PASSWORD" "$MARIADB_NAME"' < initdb.sql + +# Remove the unnecessary database init file +rm -rf initdb.sql + +# Stop & remove the database container for good measure +docker compose rm -fs mariadb diff --git a/start.sh b/start.sh new file mode 100755 index 0000000..cb93000 --- /dev/null +++ b/start.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -e +WAIT_TIMEOUT=5 + +# Start the database instance +docker compose up -d mariadb + +# Wait a couple of seconds that the database is ready +for I in $(eval echo "{$WAIT_TIMEOUT..1}"); do + printf " ${I}" + sleep 1 +done +echo + +# Start the rest of the containers +docker compose up -d