Skip to content
This repository was archived by the owner on Jan 7, 2026. It is now read-only.

Commit e047a4a

Browse files
ildyriad7415
andauthored
Add redis to docker compose (#216)
--------- Co-authored-by: Martin Stone <1611702+d7415@users.noreply.github.com>
1 parent 543b63c commit e047a4a

File tree

9 files changed

+125
-70
lines changed

9 files changed

+125
-70
lines changed

.env.example

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# ID to uses in docker file.
2+
PUID=1000
3+
PGID=1000
4+
5+
# Timezone of the application.
6+
TIMEZONE=UTC
7+
8+
# If `SKIP_PERMISSIONS_CHECKS` is set to "yes", the entrypoint script will not check or set the permissions of files and directories on startup.
9+
# SKIP_PERMISSIONS_CHECKS=false
10+
11+
# Set up the cache driver, use either "redis" or "file"
12+
# CACHE_DRIVER=redis
13+
14+
# It is safer to use file cache driver for the log viewer.
15+
# That way, if your application is running Redis and crashes, you will still be able to access the logs.
16+
LOG_VIEWER_CACHE_DRIVER=file
17+
18+
# Default app URL
19+
# APP_URL=http://localhost
20+
21+
# Redis configuration
22+
# REDIS_PORT=6379
23+
# REDIS_USERNAME=default
24+
# REDIS_PASSWORD=
25+
# REDIS_HOST=lychee_redis
26+
27+
# Database configuration
28+
# DB_ROOT_PASSWORD=rootpassword
29+
# DB_DATABASE=lychee
30+
# DB_USERNAME=lychee
31+
# DB_PASSWORD=lychee

.github/workflows/build_branch.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ jobs:
118118
steps:
119119
-
120120
name: Checkout
121-
uses: actions/checkout@v3
121+
uses: actions/checkout@v4
122122
-
123123
name: Set Password
124124
run: "sed -i 's/<.*_PASSWORD>/password/g' docker-compose.yml"

.github/workflows/pull.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
uses: docker/setup-buildx-action@v3
2626
-
2727
name: Test multiarch building
28-
uses: docker/build-push-action@v5
28+
uses: docker/build-push-action@v6
2929
with:
3030
context: .
3131
platforms: linux/amd64,linux/arm/v7,linux/arm64
@@ -35,7 +35,7 @@ jobs:
3535
lycheeorg/lychee:testing-${{ github.run_id }}
3636
-
3737
name: Save amd64 image to pass to testing
38-
uses: docker/build-push-action@v5
38+
uses: docker/build-push-action@v6
3939
with:
4040
context: .
4141
platforms: linux/amd64
@@ -54,7 +54,7 @@ jobs:
5454
sha256sum artifact/lychee.tar || echo 0
5555
-
5656
name: Store as artifact
57-
uses: actions/upload-artifact@v3
57+
uses: actions/upload-artifact@v4
5858
with:
5959
name: artifact
6060
path: ./artifact

.github/workflows/test_pull.yml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
steps:
2929
-
3030
name: 'Download artifact'
31-
uses: actions/github-script@v3.1.0
31+
uses: actions/github-script@v7
3232
with:
3333
script: |
3434
var artifacts = await github.actions.listWorkflowRunArtifacts({
@@ -59,7 +59,7 @@ jobs:
5959
-
6060
name: "Create check"
6161
id: create_check
62-
uses: actions/github-script@v6
62+
uses: actions/github-script@v7
6363
env:
6464
parameter_url: '${{ github.event.workflow_run.html_url }}'
6565
with:
@@ -80,7 +80,7 @@ jobs:
8080
run: docker image load -i ./lychee.tar
8181
-
8282
name: Login to DockerHub
83-
uses: docker/login-action@v2
83+
uses: docker/login-action@v3
8484
with:
8585
username: ${{ secrets.DOCKERHUB_USERNAME }}
8686
password: ${{ secrets.DOCKERHUB_TOKEN }}
@@ -234,7 +234,7 @@ jobs:
234234
steps:
235235
-
236236
name: "Update check"
237-
uses: actions/github-script@v6
237+
uses: actions/github-script@v7
238238
with:
239239
script: |
240240
await github.rest.checks.update({

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM debian:bookworm-slim as base
1+
FROM debian:bookworm-slim AS base
22

33
# Set version label
44
LABEL maintainer="lycheeorg"
@@ -93,7 +93,7 @@ RUN \
9393

9494
# Multi-stage build: Build static assets
9595
# This allows us to not include Node within the final container
96-
FROM node:20 as static_builder
96+
FROM node:20 AS static_builder
9797

9898
RUN mkdir /app
9999

README.md

Lines changed: 17 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,18 @@
88
![Supports arm64/aarch64 Architecture][arm64-shield]
99
![Supports armv7 Architecture][armv7-shield]
1010

11-
## Notice: Dockerhub repository has been migrated to [lycheeorg/lychee](https://hub.docker.com/r/lycheeorg/lychee)
12-
**Make sure you update your docker-compose files accordingly**
13-
1411
## Table of Contents
1512
<!-- TOC depthFrom:1 depthTo:6 withLinks:1 updateOnSave:1 orderedList:0 -->
16-
- [Image content](#image-content)
13+
- [Table of Contents](#table-of-contents)
14+
- [Image Content](#image-content)
1715
- [Setup](#setup)
1816
- [Quick Start](#quick-start)
1917
- [Prerequisites](#prerequisites)
2018
- [Run with Docker](#run-with-docker)
2119
- [Run with Docker Compose](#run-with-docker-compose)
20+
- [Create admin account during first run](#create-admin-account-during-first-run)
21+
- [Docker secrets](#docker-secrets)
2222
- [Available environment variables and defaults](#available-environment-variables-and-defaults)
23-
- [Advanced configuration](#advanced-configuration)
2423
<!-- /TOC -->
2524

2625
## Image Content
@@ -91,9 +90,19 @@ alter user 'lychee' identified with mysql_native_password by '<your password>';
9190

9291
### Run with Docker Compose
9392

94-
Change the environment variables in the [provided example](./docker-compose.yml) to reflect your database credentials.
93+
You can take the provided docker-compose.yml example as a start and edit it to enable more configuration variables.
94+
95+
Use the `.env.exanple` to create a `.env` at the root of your folder containing your `docker-compose.yml`.
96+
Populate your database credentials and other environment variables.
97+
98+
This `.env` file will be loaded by docker compose and populate environment in the docker container.
99+
Those will then be injected in the Lychee configuration file (located in e.g. `lychee/config/.env`).
95100

96-
Note that in order to avoid writing credentials directly into the file, you can create a `db_secrets.env` and use the `env_file` directive (see the [docs](https://docs.docker.com/compose/environment-variables/#the-env_file-configuration-option)).
101+
![environment-loading.png](./environment-loading.png)
102+
103+
:warning: If you later edit your `lychee/config/.env` file, restarting the container will overwrite those variables with the ones provided in your docker-compose `.env` file.
104+
For this reason it is better to make your changes directly in `docker-compose.yml`/`.env` rather than in `lychee/config/.env` when the values are supported.
105+
Please refer to the [inject.sh](https://github.com/LycheeOrg/Lychee/blob/master/inject.sh) script for more details.
97106

98107
### Create admin account during first run
99108

@@ -114,7 +123,7 @@ The following _FILE variables are supported:
114123

115124
## Available environment variables and defaults
116125

117-
If you do not provide environment variables or `.env` file, the [example .env file](https://github.com/LycheeOrg/Lychee/blob/master/.env.example) will be used with some values already set by default.
126+
If you do not provide environment variables or `.env` file, Lychee's [example .env file](https://github.com/LycheeOrg/Lychee/blob/master/.env.example) will be used with some values already set by default inside the docker container.
118127

119128
Some variables are specific to Docker, and the default values are :
120129

@@ -126,22 +135,6 @@ Some variables are specific to Docker, and the default values are :
126135

127136
Additionally, if `SKIP_PERMISSIONS_CHECKS` is set to "yes", the entrypoint script will not check or set the permissions of files and directories on startup. Users are strongly advised **against** using this option, and efforts have been made to keep the checks as fast as possible. Nonetheless, it may be suitable for some advanced use cases.
128137

129-
## Advanced configuration
130-
131-
Note that nginx will accept by default images up to 100MB (`client_max_body_size 100M`) and that PHP parameters are overridden according to the [recommendations of the Lychee FAQ](https://lycheeorg.github.io/docs/faq.html#i-cant-upload-large-photos).
132-
133-
You may still want to further customize PHP configuration. The first method is to mount a custom `php.ini` to `/etc/php/8.2/fpm/php.ini` when starting the container. However, this method is kind of brutal as it will override all parameters. It will also need to be remapped whenever an image is released with a new version of PHP.
134-
135-
Instead, we recommend to use the `PHP_VALUE` directive of PHP-FPM to override specific parameters. To do so, you will need to mount a custom `nginx.conf` in your container :
136-
137-
1. Take the [default.conf](./default.conf) file as a base
138-
2. Find the line starting by `fastcgi_param PHP_VALUE [...]`
139-
3. Add a new line and set your new parameter
140-
4. Add or change any other parameters (e.g. `client_max_body_size`)
141-
5. Mount your new file to `/etc/nginx/nginx.conf`
142-
143-
If you need to add (not change) nginx directives, files mounted in `/etc/nginx/conf.d/` will be included in the `http` context.
144-
145138
[arm64-shield]: https://img.shields.io/badge/arm64-yes-success.svg?style=flat
146139
[amd64-shield]: https://img.shields.io/badge/amd64-yes-success.svg?style=flat
147140
[armv7-shield]: https://img.shields.io/badge/armv7-yes-success.svg?style=flat

docker-compose.yml

Lines changed: 43 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,33 @@
55
#-------------------------------------------
66

77
services:
8+
lychee_cache:
9+
image: redis:alpine
10+
container_name: lychee_redis
11+
hostname: lychee_redis
12+
security_opt:
13+
- no-new-privileges:true
14+
healthcheck:
15+
test: ["CMD-SHELL", "redis-cli ping || exit 1"]
16+
ports:
17+
- ${REDIS_PORT:-6379}:${REDIS_PORT:-6379}
18+
user: 1026:100
19+
environment:
20+
- TZ=${TIMEZONE:-UTC}
21+
networks:
22+
- lychee
23+
volumes:
24+
- cache:/data:rw
25+
restart: on-failure:5
26+
827
lychee_db:
928
container_name: lychee_db
1029
image: mariadb:10
1130
environment:
12-
- MYSQL_ROOT_PASSWORD=<ROOT_PASSWORD>
13-
- MYSQL_DATABASE=lychee
14-
- MYSQL_USER=lychee
15-
- MYSQL_PASSWORD=<LYCHEE_PASSWORD>
31+
- MYSQL_ROOT_PASSWORD=${DB_ROOT_PASSWORD:-rootpassword}
32+
- MYSQL_DATABASE=${DB_DATABASE:-lychee}
33+
- MYSQL_USER=${DB_USERNAME:-lychee}
34+
- MYSQL_PASSWORD=${DB_PASSWORD}
1635
expose:
1736
- 3306
1837
volumes:
@@ -22,7 +41,7 @@ services:
2241
restart: unless-stopped
2342

2443
lychee:
25-
image: lycheeorg/lychee
44+
image: lycheeorg/lychee:nightly
2645
container_name: lychee
2746
ports:
2847
- 90:80
@@ -38,13 +57,13 @@ services:
3857
#- PUID=1000
3958
#- PGID=1000
4059
# PHP timezone e.g. PHP_TZ=America/New_York
41-
- PHP_TZ=UTC
42-
- TIMEZONE=UTC
60+
- PHP_TZ=${TIMEZONE:-UTC}
61+
- TIMEZONE=${TIMEZONE:-UTC}
4362
#- APP_NAME=Laravel
4463
#- APP_ENV=local
4564
#- APP_DEBUG=true
4665
#- APP_FORCE_HTTPS=false
47-
#- APP_URL=http://localhost
66+
- APP_URL=${APP_URL:-http://localhost}
4867
#- APP_DIR=
4968
#- DEBUGBAR_ENABLEd=false
5069
#- VUEJS_ENABLED=true
@@ -53,10 +72,10 @@ services:
5372
#- DB_OLD_LYCHEE_PREFIX=''
5473
- DB_CONNECTION=mysql
5574
- DB_HOST=lychee_db
56-
- DB_PORT=3306
57-
- DB_DATABASE=lychee
58-
- DB_USERNAME=lychee
59-
- DB_PASSWORD=<LYCHEE_PASSWORD>
75+
- DB_PORT=${DB_PORT:-3306}
76+
- DB_DATABASE=${DB_DATABASE:-lychee}
77+
- DB_USERNAME=${DB_USERNAME:-lychee}
78+
- DB_PASSWORD=${DB_PASSWORD}
6079
#- DB_PASSWORD_FILE=<filename>
6180
#- DB_LOG_SQL=false
6281
#- DB_LOG_SQL_EXPLAIN=false
@@ -79,16 +98,17 @@ services:
7998
#- MAIL_FROM_NAME=
8099
#- MAIL_FROM_ADDRESS=
81100
#- TRUSTED_PROXIES=
82-
#- SKIP_PERMISSIONS_CHECKS
101+
- SKIP_PERMISSIONS_CHECKS=${SKIP_PERMISSIONS_CHECKS:-false}
83102
- STARTUP_DELAY=30
84103
#- ADMIN_USER=admin
85104
#- ADMIN_PASSWORD=<ADMIN_PASSWORD>
86105
#- ADMIN_PASSWORD_FILE=<filename>
87-
### Unused in Lychee
88-
#- REDIS_HOST=127.0.0.1
89-
#- REDIS_PASSWORD=null
90-
#- REDIS_PASSWORD_FILE=<filename>
91-
#- REDIS_PORT=6379
106+
- CACHE_DRIVER=${CACHE_DRIVER:-redis}
107+
- REDIS_URL=redis://${REDIS_USERNAME:-default}:${REDIS_PASSWORD:-}@${REDIS_HOST:-lychee_redis}:${REDIS_PORT:-6379}
108+
- REDIS_HOST=${REDIS_HOST:-lychee_redis}
109+
- REDIS_PORT=${REDIS_PORT:-6379}
110+
- REDIS_PASSWORD=${REDIS_PASSWORD:-}
111+
- LOG_VIEWER_CACHE_DRIVER=${LOG_VIEWER_CACHE_DRIVER:-file}
92112
restart: unless-stopped
93113
depends_on:
94114
- lychee_db
@@ -98,3 +118,8 @@ networks:
98118

99119
volumes:
100120
mysql:
121+
name: lychee_prod_mysql
122+
driver: local
123+
cache:
124+
name: lychee_prod_redis
125+
driver: local

environment-loading.png

334 KB
Loading

inject.sh

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,9 @@ if [ "$ENABLE_TOKEN_AUTH" != '' ]; then
112112
if [ "$CACHE_DRIVER" != '' ]; then
113113
replace_or_insert "CACHE_DRIVER" "$CACHE_DRIVER"
114114
fi
115+
if [ "$LOG_VIEWER_CACHE_DRIVER" != '' ]; then
116+
replace_or_insert "LOG_VIEWER_CACHE_DRIVER" "$LOG_VIEWER_CACHE_DRIVER"
117+
fi
115118
if [ "$SESSION_DRIVER" != '' ]; then
116119
replace_or_insert "SESSION_DRIVER" "$SESSION_DRIVER"
117120
fi
@@ -133,24 +136,27 @@ if [ "$SECURITY_HEADER_SCRIPT_SRC_ALLOW" != '' ]; then
133136
if [ "$SESSION_SECURE_COOKIE" != '' ]; then
134137
replace_or_insert "SESSION_SECURE_COOKIE" "$SESSION_SECURE_COOKIE"
135138
fi
136-
# if [ "$REDIS_SCHEME" != '' ]; then
137-
# sed -i "s|REDIS_SCHEME=.*|REDIS_SCHEME=${REDIS_SCHEME}|i" /conf/.env
138-
# fi
139-
# if [ "$REDIS_PATH" != '' ]; then
140-
# sed -i "s|REDIS_PATH=.*|REDIS_PATH=${REDIS_PATH}|i" /conf/.env
141-
# fi
142-
# if [ "$REDIS_HOST" != '' ]; then
143-
# sed -i "s|REDIS_HOST=.*|REDIS_HOST=${REDIS_HOST}|i" /conf/.env
144-
# fi
145-
# if [ "$REDIS_PORT" != '' ]; then
146-
# sed -i "s|REDIS_PORT=.*|REDIS_PORT=${REDIS_PORT}|i" /conf/.env
147-
# fi
148-
# if [ "$REDIS_PASSWORD" != '' ]; then
149-
# sed -i "s|REDIS_PASSWORD=.*|REDIS_PASSWORD=${REDIS_PASSWORD}|i" /conf/.env
150-
# elif [ "$REDIS_PASSWORD_FILE" != '' ]; then
151-
# value=$(<$REDIS_PASSWORD_FILE)
152-
# sed -i "s|REDIS_PASSWORD=.*|REDIS_PASSWORD=${value}|i" /conf/.env
153-
# fi
139+
if [ "$REDIS_URL" != '' ]; then
140+
replace_or_insert "REDIS_URL" "$REDIS_URL"
141+
fi
142+
if [ "$REDIS_PATH" != '' ]; then
143+
replace_or_insert "REDIS_PATH" "$REDIS_PATH"
144+
fi
145+
if [ "$REDIS_HOST" != '' ]; then
146+
replace_or_insert "REDIS_HOST" "$REDIS_HOST"
147+
fi
148+
if [ "$REDIS_PORT" != '' ]; then
149+
replace_or_insert "REDIS_PORT" "$REDIS_PORT"
150+
fi
151+
if [ "$REDIS_USERNAME" != '' ]; then
152+
replace_or_insert "REDIS_USERNAME" "$REDIS_USERNAME"
153+
fi
154+
if [ "$REDIS_PASSWORD" != '' ]; then
155+
replace_or_insert "REDIS_PASSWORD" "$REDIS_PASSWORD"
156+
elif [ "$REDIS_PASSWORD_FILE" != '' ]; then
157+
value=$(<$REDIS_PASSWORD_FILE)
158+
replace_or_insert "REDIS_PASSWORD" "$value"
159+
fi
154160
if [ "$MAIL_DRIVER" != '' ]; then
155161
replace_or_insert "MAIL_DRIVER" "$MAIL_DRIVER"
156162
fi

0 commit comments

Comments
 (0)