From ca316437033def8b1354a0821d0240126fc22588 Mon Sep 17 00:00:00 2001 From: Tino Hager Date: Fri, 20 Dec 2024 14:00:32 +0100 Subject: [PATCH 1/5] Add an example config with caddy, ready to run with automatic Let's Encrypt integration --- configuration-with-caddy/.env | 2 + configuration-with-caddy/Caddyfile | 14 +++++ configuration-with-caddy/README.md | 10 +++ configuration-with-caddy/docker-compose.yml | 67 +++++++++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 configuration-with-caddy/.env create mode 100644 configuration-with-caddy/Caddyfile create mode 100644 configuration-with-caddy/README.md create mode 100644 configuration-with-caddy/docker-compose.yml diff --git a/configuration-with-caddy/.env b/configuration-with-caddy/.env new file mode 100644 index 0000000..954d005 --- /dev/null +++ b/configuration-with-caddy/.env @@ -0,0 +1,2 @@ +MYSQL_ROOT_PASSWORD=b815b2339e946f5b1d8846010dc16228a45691a152b3a02b40b4da3ee6 +MYSQL_LYCHEE_PASSWORD=6ae740224fede615aac0de31add0d9b8d16ba6d1718b115b530b diff --git a/configuration-with-caddy/Caddyfile b/configuration-with-caddy/Caddyfile new file mode 100644 index 0000000..ba4b040 --- /dev/null +++ b/configuration-with-caddy/Caddyfile @@ -0,0 +1,14 @@ +(common) { + encode zstd gzip + header /* { + -Server + -x-powered-by + } +} + +lychee.mydomain.com { + handle /* { + reverse_proxy lychee + } + import common +} diff --git a/configuration-with-caddy/README.md b/configuration-with-caddy/README.md new file mode 100644 index 0000000..3d24ffd --- /dev/null +++ b/configuration-with-caddy/README.md @@ -0,0 +1,10 @@ +# Configuration with caddy + +This is an example configuration for using the Lychee photo management tool with the Caddy web server. Make sure to adjust the domain in the Caddyfile and set the MYSQL_ROOT_PASSWORD and MYSQL_LYCHEE_PASSWORD in the .env file to secure your database. + +## Start Lychee Docker + +``` +docker-compose pull +docker-compose up -d +``` \ No newline at end of file diff --git a/configuration-with-caddy/docker-compose.yml b/configuration-with-caddy/docker-compose.yml new file mode 100644 index 0000000..d2cae78 --- /dev/null +++ b/configuration-with-caddy/docker-compose.yml @@ -0,0 +1,67 @@ + +services: + + caddy: + container_name: caddy + image: caddy:2 + restart: unless-stopped + ports: + - 80:80 + - 443:443 + - 443:443/udp + volumes: + - ./Caddyfile:/etc/caddy/Caddyfile:ro + - ./caddy-config:/config + - ./caddy-data:/data + networks: + - lychee + + lychee_db: + container_name: lychee_db + image: mariadb:10 + restart: unless-stopped + environment: + - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD} + - MYSQL_DATABASE=lychee + - MYSQL_USER=lychee + - MYSQL_PASSWORD=${MYSQL_LYCHEE_PASSWORD} + expose: + - 3306 + volumes: + - mysql:/var/lib/mysql + networks: + - lychee + + lychee: + container_name: lychee + image: lycheeorg/lychee:dev + restart: unless-stopped + environment: + - PHP_TZ=UTC + - TIMEZONE=UTC + - DB_CONNECTION=mysql + - DB_HOST=lychee_db + - DB_PORT=3306 + - DB_DATABASE=lychee + - DB_USERNAME=lychee + - DB_PASSWORD=${MYSQL_LYCHEE_PASSWORD} + - STARTUP_DELAY=10 + - TRUSTED_PROXIES=* + expose: + - 80 + volumes: + - ./lychee/conf:/conf + - ./lychee/uploads:/uploads + - ./lychee/sym:/sym + - ./lychee/logs:/logs + - ./lychee/tmp:/lychee-tmp + depends_on: + - lychee_db + networks: + - lychee + +networks: + lychee: + +volumes: + mysql: From dc39294204e393b3c7e3b965cfb041099b7ace61 Mon Sep 17 00:00:00 2001 From: Tino Hager Date: Sat, 21 Dec 2024 20:57:32 +0100 Subject: [PATCH 2/5] Optimize setup --- configuration-with-caddy/.env | 4 ++-- configuration-with-caddy/Caddyfile | 2 +- configuration-with-caddy/install.sh | 0 3 files changed, 3 insertions(+), 3 deletions(-) create mode 100644 configuration-with-caddy/install.sh diff --git a/configuration-with-caddy/.env b/configuration-with-caddy/.env index 954d005..ff3d725 100644 --- a/configuration-with-caddy/.env +++ b/configuration-with-caddy/.env @@ -1,2 +1,2 @@ -MYSQL_ROOT_PASSWORD=b815b2339e946f5b1d8846010dc16228a45691a152b3a02b40b4da3ee6 -MYSQL_LYCHEE_PASSWORD=6ae740224fede615aac0de31add0d9b8d16ba6d1718b115b530b +MYSQL_ROOT_PASSWORD=Enter a secret value here +MYSQL_LYCHEE_PASSWORD=Enter a secret value here diff --git a/configuration-with-caddy/Caddyfile b/configuration-with-caddy/Caddyfile index ba4b040..d07fad7 100644 --- a/configuration-with-caddy/Caddyfile +++ b/configuration-with-caddy/Caddyfile @@ -6,7 +6,7 @@ } } -lychee.mydomain.com { + { handle /* { reverse_proxy lychee } diff --git a/configuration-with-caddy/install.sh b/configuration-with-caddy/install.sh new file mode 100644 index 0000000..e69de29 From 9846e717c3f737a08dcbdcffab6c014de083d880 Mon Sep 17 00:00:00 2001 From: Tino Hager Date: Sat, 21 Dec 2024 21:05:14 +0100 Subject: [PATCH 3/5] Update install.sh --- configuration-with-caddy/install.sh | 45 +++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/configuration-with-caddy/install.sh b/configuration-with-caddy/install.sh index e69de29..ac1433c 100644 --- a/configuration-with-caddy/install.sh +++ b/configuration-with-caddy/install.sh @@ -0,0 +1,45 @@ +#!/bin/bash + +# Set variables +REPO_URL="https://raw.githubusercontent.com/LycheeOrg/Lychee-Docker/refs/heads/master/configuration-with-caddy/" +DOCKER_COMPOSE_FILE="docker-compose.yml" +ENV_FILE=".env" +CADDYFILE="Caddyfile" + +# Prompt for domain +read -p "Enter your domain name: " DOMAIN + +# Download files from GitHub +curl -O "$REPO_URL/$DOCKER_COMPOSE_FILE" || { echo "Failed to download $DOCKER_COMPOSE_FILE"; exit 1; } +curl -O "$REPO_URL/$ENV_FILE" || { echo "Failed to download $ENV_FILE"; exit 1; } +curl -O "$REPO_URL/$CADDYFILE" || { echo "Failed to download $CADDYFILE"; exit 1; } + +# Set MYSQL_ROOT_PASSWORD and MYSQL_LYCHEE_PASSWORD in the .env file +MYSQL_ROOT_PASSWORD="$(openssl rand -base64 12)" +MYSQL_LYCHEE_PASSWORD="$(openssl rand -base64 12)" + +if [ -f "$ENV_FILE" ]; then + sed -i "s/^MYSQL_ROOT_PASSWORD=.*/MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD/" "$ENV_FILE" + sed -i "s/^MYSQL_LYCHEE_PASSWORD=.*/MYSQL_LYCHEE_PASSWORD=$MYSQL_LYCHEE_PASSWORD/" "$ENV_FILE" +else + echo "$ENV_FILE not found. Creating the file." + echo "MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD" > "$ENV_FILE" + echo "MYSQL_LYCHEE_PASSWORD=$MYSQL_LYCHEE_PASSWORD" >> "$ENV_FILE" +fi + +# Replace domain placeholder in the Caddyfile +if [ -f "$CADDYFILE" ]; then + sed -i "s//$DOMAIN/" "$CADDYFILE" +else + echo "$CADDYFILE not found." + exit 1 +fi + +# Display success message +echo "Files successfully downloaded and passwords set:" +echo "MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD" +echo "MYSQL_LYCHEE_PASSWORD=$MYSQL_LYCHEE_PASSWORD" + +echo "Caddyfile updated with domain: $DOMAIN" + +echo "You can now run 'docker-compose up -d'." From 21063d6de9ed8edbc978b1ba1ff03bdb83001756 Mon Sep 17 00:00:00 2001 From: Tino Hager Date: Sat, 21 Dec 2024 21:17:32 +0100 Subject: [PATCH 4/5] optimize setup logic --- configuration-with-caddy/README.md | 8 ++++++++ configuration-with-caddy/{install.sh => setup.sh} | 6 +++--- 2 files changed, 11 insertions(+), 3 deletions(-) rename configuration-with-caddy/{install.sh => setup.sh} (90%) diff --git a/configuration-with-caddy/README.md b/configuration-with-caddy/README.md index 3d24ffd..70ad9b5 100644 --- a/configuration-with-caddy/README.md +++ b/configuration-with-caddy/README.md @@ -2,6 +2,14 @@ This is an example configuration for using the Lychee photo management tool with the Caddy web server. Make sure to adjust the domain in the Caddyfile and set the MYSQL_ROOT_PASSWORD and MYSQL_LYCHEE_PASSWORD in the .env file to secure your database. +## Start Setup + +The setup.sh script downloads necessary files, generates strong MySQL passwords, and updates the domain in the Caddyfile. + +``` +curl -O https://raw.githubusercontent.com/LycheeOrg/Lychee-Docker/refs/heads/master/configuration-with-caddy/setup.sh && chmod +x setup.sh && ./setup.sh +``` + ## Start Lychee Docker ``` diff --git a/configuration-with-caddy/install.sh b/configuration-with-caddy/setup.sh similarity index 90% rename from configuration-with-caddy/install.sh rename to configuration-with-caddy/setup.sh index ac1433c..84f7cb8 100644 --- a/configuration-with-caddy/install.sh +++ b/configuration-with-caddy/setup.sh @@ -1,7 +1,7 @@ #!/bin/bash # Set variables -REPO_URL="https://raw.githubusercontent.com/LycheeOrg/Lychee-Docker/refs/heads/master/configuration-with-caddy/" +REPO_URL="https://raw.githubusercontent.com/LycheeOrg/Lychee-Docker/refs/heads/master/configuration-with-caddy" DOCKER_COMPOSE_FILE="docker-compose.yml" ENV_FILE=".env" CADDYFILE="Caddyfile" @@ -15,8 +15,8 @@ curl -O "$REPO_URL/$ENV_FILE" || { echo "Failed to download $ENV_FILE"; exit 1; curl -O "$REPO_URL/$CADDYFILE" || { echo "Failed to download $CADDYFILE"; exit 1; } # Set MYSQL_ROOT_PASSWORD and MYSQL_LYCHEE_PASSWORD in the .env file -MYSQL_ROOT_PASSWORD="$(openssl rand -base64 12)" -MYSQL_LYCHEE_PASSWORD="$(openssl rand -base64 12)" +MYSQL_ROOT_PASSWORD="$(openssl rand -base64 24)" +MYSQL_LYCHEE_PASSWORD="$(openssl rand -base64 24)" if [ -f "$ENV_FILE" ]; then sed -i "s/^MYSQL_ROOT_PASSWORD=.*/MYSQL_ROOT_PASSWORD=$MYSQL_ROOT_PASSWORD/" "$ENV_FILE" From 19f8057eec966fedec55142be3abfc7a57a1114e Mon Sep 17 00:00:00 2001 From: Tino Hager Date: Sat, 21 Dec 2024 21:24:07 +0100 Subject: [PATCH 5/5] Update README.md --- configuration-with-caddy/README.md | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/configuration-with-caddy/README.md b/configuration-with-caddy/README.md index 70ad9b5..21cc58c 100644 --- a/configuration-with-caddy/README.md +++ b/configuration-with-caddy/README.md @@ -1,18 +1,22 @@ # Configuration with caddy -This is an example configuration for using the Lychee photo management tool with the Caddy web server. Make sure to adjust the domain in the Caddyfile and set the MYSQL_ROOT_PASSWORD and MYSQL_LYCHEE_PASSWORD in the .env file to secure your database. +This is an example configuration for using the Lychee photo management tool with the Caddy web server. Make sure to adjust the domain in the Caddyfile and set the `MYSQL_ROOT_PASSWORD` and `MYSQL_LYCHEE_PASSWORD` in the .env file to secure your database. -## Start Setup +These configurations are automatically applied when using the `setup.sh` script. -The setup.sh script downloads necessary files, generates strong MySQL passwords, and updates the domain in the Caddyfile. +## Setup + +The `setup.sh` script downloads necessary files, generates strong MySQL passwords, and updates the domain in the Caddyfile. ``` curl -O https://raw.githubusercontent.com/LycheeOrg/Lychee-Docker/refs/heads/master/configuration-with-caddy/setup.sh && chmod +x setup.sh && ./setup.sh ``` -## Start Lychee Docker +## Start + +Docker pulls the containers and then starts them as services running in the background. ``` docker-compose pull docker-compose up -d -``` \ No newline at end of file +```