From bbde558e8fccbdc2450368cc831e706f8a0f09d5 Mon Sep 17 00:00:00 2001 From: ChiaraBm Date: Sat, 17 May 2025 21:47:39 +0200 Subject: [PATCH] Updated compose to build the docker image when required. Added env customisation options. Added update script --- .env.example | 29 +++++++++++++++++++++++++++++ .gitignore | 3 ++- compose.yml | 29 ++++++++++++++++------------- update.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 95 insertions(+), 14 deletions(-) create mode 100644 .env.example create mode 100755 update.sh diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..ba41321 --- /dev/null +++ b/.env.example @@ -0,0 +1,29 @@ +# This defines the way to get the moonlight docker image +# By default moonlight will build the image locally. To pull +# it from the registry, set the value to 'pull' +MOONLIGHT_BUILD=build + +# This defines the image name to use when building/pulling +# the moonlight docker image +MOONLIGHT_IMAGE=moonlightpanel/panel:2.1 + +# Specify where the fetch the moonlight source code when building +# Uncomment this if you want to select a specific version of moonlight +# Or you want to deploy a custom fork +# MOONLIGHT_REPOSITORY=https://github.com/Moonlight-Panel/Moonlight +# MOONLIGHT_BRANCH=v2_ChangeArchitecture + +# Set this to the url moonlight is accessible through the internet +MOONLIGHT_URL=http://localhost:9069 + +# This defines the port moonlight should run on +MOONLIGHT_PORT=9069 + +# Here you can adjust where the moonlight instance will save +# the application and database data +MOONLIGHT_DATA=./data + +# With the following settings you can adjust the database configuration +MOONLIGHT_DATABASE_USER=moonlight +MOONLIGHT_DATABASE_PASSWORD=s3cret +MOONLIGHT_DATABASE_NAME=moonlight \ No newline at end of file diff --git a/.gitignore b/.gitignore index 3490e4c..e8db029 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ **/.idea/** -**/data/** \ No newline at end of file +**/data/** +**/.env \ No newline at end of file diff --git a/compose.yml b/compose.yml index 4fc8c45..32d5d15 100644 --- a/compose.yml +++ b/compose.yml @@ -2,38 +2,41 @@ services: api-server: user: 0:0 restart: always - image: moonlightpanel/panel:custom + image: ${MOONLIGHT_IMAGE} build: context: . - dockerfile: ./Moonlight.ApiServer/Dockerfile + dockerfile: ./Dockerfile + args: + - MOONLIGHT_REPO=${MOONLIGHT_REPOSITORY:-https://github.com/Moonlight-Panel/Moonlight} + - MOONLIGHT_BRANCH=${MOONLIGHT_BRANCH:-v2_ChangeArchitecture} ports: - - "9069:8080" + - "${MOONLIGHT_PORT}:8080" depends_on: db: condition: service_healthy environment: - MOONLIGHT_DATABASE_HOST=db - MOONLIGHT_DATABASE_PORT=5432 - - MOONLIGHT_DATABASE_USERNAME=moonlight - - MOONLIGHT_DATABASE_PASSWORD=s3cret - - MOONLIGHT_DATABASE_DATABASE=moonlight - - MOONLIGHT_PUBLICURL=http://localhost:9069 + - MOONLIGHT_DATABASE_USERNAME=${MOONLIGHT_DATABASE_USER} + - MOONLIGHT_DATABASE_PASSWORD=${MOONLIGHT_DATABASE_PASSWORD} + - MOONLIGHT_DATABASE_DATABASE=${MOONLIGHT_DATABASE_NAME} + - MOONLIGHT_PUBLICURL=${MOONLIGHT_URL} - MOONLIGHT_AUTHENTICATION_OAUTH2_ACCESSENDPOINT=http://localhost:8080/oauth2/handle # Use this when moonlight is using local oauth2 and a different port as the public url volumes: - - ./data/moonlight:/app/storage + - ${MOONLIGHT_DATA}/moonlight:/app/storage links: - db - pull_policy: never + pull_policy: build db: image: postgres:latest restart: always environment: - - POSTGRES_USER=moonlight - - POSTGRES_DB=moonlight - - POSTGRES_PASSWORD=s3cret + - POSTGRES_USER=${MOONLIGHT_DATABASE_USER} + - POSTGRES_DB=${MOONLIGHT_DATABASE_NAME} + - POSTGRES_PASSWORD=${MOONLIGHT_DATABASE_PASSWORD} volumes: - - ./data/database:/var/lib/postgresql/data + - .${MOONLIGHT_DATA}/database:/var/lib/postgresql/data healthcheck: test: ["CMD-SHELL", "pg_isready"] interval: 10s diff --git a/update.sh b/update.sh new file mode 100755 index 0000000..bcf6a8c --- /dev/null +++ b/update.sh @@ -0,0 +1,48 @@ +#!/bin/bash + +set -e + +source .env + +echo "[i] Updating your moonlight instance" + +echo "[i] Checking for updates on deploy repo" + +# Fetch remote updates +git fetch + +# Get current branch name +branch=$(git rev-parse --abbrev-ref HEAD) + +# Compare local and remote branch +local_commit=$(git rev-parse "$branch") +remote_commit=$(git rev-parse "origin/$branch") + +if [ "$local_commit" != "$remote_commit" ]; then + echo "[i] The deploy repository has updates. Fetching changes" + git pull + echo "[i] Updated deploy tools. Please rerun the update.sh" + exit 0 +else + echo "[i] No update of the deploy repository available" +fi + +if [ "$MOONLIGHT_BUILD" == "build" ]; then + echo "[i] Rebuilding the docker image" + docker compose build + echo "[i] Rebuild done" +fi + +if [ "$MOONLIGHT_BUILD" == "pull" ]; then + echo "[i] Pulling the latest docker image" + docker compose build + echo "[i] Pulling completed" +fi + +echo "[i] Stopping containers" +docker compose down + +echo "[i] Starting containers" +docker compose up -d + +echo "[i] Update done :>" \ No newline at end of file