Skip to content

Commit

Permalink
Example config with caddy, ready to run (#212)
Browse files Browse the repository at this point in the history
  • Loading branch information
tinohager authored Dec 26, 2024
1 parent 8e03b69 commit d73e485
Show file tree
Hide file tree
Showing 5 changed files with 150 additions and 0 deletions.
2 changes: 2 additions & 0 deletions configuration-with-caddy/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
MYSQL_ROOT_PASSWORD=Enter a secret value here
MYSQL_LYCHEE_PASSWORD=Enter a secret value here
14 changes: 14 additions & 0 deletions configuration-with-caddy/Caddyfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(common) {
encode zstd gzip
header /* {
-Server
-x-powered-by
}
}

<YOUR_DOMAIN> {
handle /* {
reverse_proxy lychee
}
import common
}
22 changes: 22 additions & 0 deletions configuration-with-caddy/README.md
Original file line number Diff line number Diff line change
@@ -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
```
67 changes: 67 additions & 0 deletions configuration-with-caddy/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -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:
45 changes: 45 additions & 0 deletions configuration-with-caddy/setup.sh
Original file line number Diff line number Diff line change
@@ -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/<YOUR_DOMAIN>/$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'."

0 comments on commit d73e485

Please sign in to comment.