Updated compose to build the docker image when required. Added env customisation options. Added update script

This commit is contained in:
2025-05-17 21:47:39 +02:00
parent 4b4fff43ce
commit bbde558e8f
4 changed files with 95 additions and 14 deletions

29
.env.example Normal file
View File

@@ -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

3
.gitignore vendored
View File

@@ -1,2 +1,3 @@
**/.idea/** **/.idea/**
**/data/** **/data/**
**/.env

View File

@@ -2,38 +2,41 @@ services:
api-server: api-server:
user: 0:0 user: 0:0
restart: always restart: always
image: moonlightpanel/panel:custom image: ${MOONLIGHT_IMAGE}
build: build:
context: . 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: ports:
- "9069:8080" - "${MOONLIGHT_PORT}:8080"
depends_on: depends_on:
db: db:
condition: service_healthy condition: service_healthy
environment: environment:
- MOONLIGHT_DATABASE_HOST=db - MOONLIGHT_DATABASE_HOST=db
- MOONLIGHT_DATABASE_PORT=5432 - MOONLIGHT_DATABASE_PORT=5432
- MOONLIGHT_DATABASE_USERNAME=moonlight - MOONLIGHT_DATABASE_USERNAME=${MOONLIGHT_DATABASE_USER}
- MOONLIGHT_DATABASE_PASSWORD=s3cret - MOONLIGHT_DATABASE_PASSWORD=${MOONLIGHT_DATABASE_PASSWORD}
- MOONLIGHT_DATABASE_DATABASE=moonlight - MOONLIGHT_DATABASE_DATABASE=${MOONLIGHT_DATABASE_NAME}
- MOONLIGHT_PUBLICURL=http://localhost:9069 - 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 - 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: volumes:
- ./data/moonlight:/app/storage - ${MOONLIGHT_DATA}/moonlight:/app/storage
links: links:
- db - db
pull_policy: never pull_policy: build
db: db:
image: postgres:latest image: postgres:latest
restart: always restart: always
environment: environment:
- POSTGRES_USER=moonlight - POSTGRES_USER=${MOONLIGHT_DATABASE_USER}
- POSTGRES_DB=moonlight - POSTGRES_DB=${MOONLIGHT_DATABASE_NAME}
- POSTGRES_PASSWORD=s3cret - POSTGRES_PASSWORD=${MOONLIGHT_DATABASE_PASSWORD}
volumes: volumes:
- ./data/database:/var/lib/postgresql/data - .${MOONLIGHT_DATA}/database:/var/lib/postgresql/data
healthcheck: healthcheck:
test: ["CMD-SHELL", "pg_isready"] test: ["CMD-SHELL", "pg_isready"]
interval: 10s interval: 10s

48
update.sh Executable file
View File

@@ -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 :>"