diff --git a/configuration-with-caddy/.env b/configuration-with-caddy/.env new file mode 100644 index 0000000..ff3d725 --- /dev/null +++ b/configuration-with-caddy/.env @@ -0,0 +1,2 @@ +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 new file mode 100644 index 0000000..d07fad7 --- /dev/null +++ b/configuration-with-caddy/Caddyfile @@ -0,0 +1,14 @@ +(common) { + encode zstd gzip + header /* { + -Server + -x-powered-by + } +} + + { + 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..21cc58c --- /dev/null +++ b/configuration-with-caddy/README.md @@ -0,0 +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. + +These configurations are automatically applied when using the `setup.sh` script. + +## 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 + +Docker pulls the containers and then starts them as services running in the background. + +``` +docker-compose pull +docker-compose up -d +``` 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: diff --git a/configuration-with-caddy/setup.sh b/configuration-with-caddy/setup.sh new file mode 100644 index 0000000..84f7cb8 --- /dev/null +++ b/configuration-with-caddy/setup.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 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" + 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'."