-
-
Notifications
You must be signed in to change notification settings - Fork 364
Expand file tree
/
Copy pathDockerfile-legacy
More file actions
196 lines (164 loc) · 6.4 KB
/
Dockerfile-legacy
File metadata and controls
196 lines (164 loc) · 6.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# Lychee - Laravel Backend Dockerfile
# Multi-stage build with Laravel Octane + FrankenPHP
ARG NODE_ENV=production
# ============================================================================
# Stage 1: Composer Dependencies
# ============================================================================
FROM composer:2.8@sha256:5248900ab8b5f7f880c2d62180e40960cd87f60149ec9a1abfd62ac72a02577c AS composer
WORKDIR /app
# Copy composer files first for layer caching
COPY composer.json composer.lock ./
# Install dependencies (no dev packages for production)
# Remove markdown and test directories to slim down the image
RUN composer install \
--no-dev \
--no-interaction \
--no-progress \
--no-scripts \
--prefer-dist \
--optimize-autoloader \
--ignore-platform-reqs \
&& find vendor \
\( -iname "*.md" -o -iname "test" -o -iname "tests" \) \
-exec rm -rf {} +
# ============================================================================
# Stage 2: Node.js Build for Frontend Assets
# ============================================================================
FROM node:20-alpine@sha256:658d0f63e501824d6c23e06d4bb95c71e7d704537c9d9272f488ac03a370d448 AS node
# Build argument to control dev vs production build
ARG NODE_ENV
ENV NODE_ENV=$NODE_ENV
WORKDIR /app
# Copy package files for layer caching
COPY package.json package-lock.json ./
# Install dependencies
RUN npm ci --no-audit
# Copy frontend source
COPY resources/ ./resources/
COPY public/ ./public/
COPY lang/ ./lang/
COPY vite.config.ts vite.embed.config.ts tsconfig.json ./
# Build frontend assets
# When NODE_ENV=development, Vite sets import.meta.env.DEV=true
RUN npm run build
# TODO: migrate to trixie once php8.5-zip is fixed.
# TODO: Fix Imagick sed once we update the version of Imagick.
FROM debian:bookworm-slim@sha256:d5d3f9c23164ea16f31852f95bd5959aad1c5e854332fe00f7b3a20fcc9f635c AS base
LABEL maintainer="lycheeorg"
LABEL org.opencontainers.image.title="Lychee"
LABEL org.opencontainers.image.description="Self-hosted photo management system done right."
LABEL org.opencontainers.image.authors="LycheeOrg"
LABEL org.opencontainers.image.vendor="LycheeOrg"
LABEL org.opencontainers.image.source="https://github.com/LycheeOrg/Lychee"
LABEL org.opencontainers.image.url="https://lycheeorg.github.io"
LABEL org.opencontainers.image.documentation="https://lycheeorg.dev/docs"
LABEL org.opencontainers.image.licenses="MIT"
LABEL org.opencontainers.image.base.name="debian:bookworm-slim"
# Environment variables
ENV PUID='1000'
ENV PGID='1000'
ENV PHP_TZ=UTC
# https://stackoverflow.com/questions/53377176/change-imagemagick-policy-on-a-dockerfile (for the sed on policy.xml)
# Install base dependencies, add user and group, clone the repo and install php libraries
# hadolint ignore=DL3008
RUN \
set -ev && \
apt-get update && \
apt-get upgrade -qy && \
apt-get install -qy --no-install-recommends\
ca-certificates \
curl \
apt-transport-https && \
curl -sSLo /tmp/debsuryorg-archive-keyring.deb https://packages.sury.org/debsuryorg-archive-keyring.deb && \
dpkg -i /tmp/debsuryorg-archive-keyring.deb && \
sh -c 'echo "deb [signed-by=/usr/share/keyrings/deb.sury.org-php.gpg] https://packages.sury.org/php/ bookworm main" > /etc/apt/sources.list.d/php.list' && \
apt-get update && \
apt-get install -qy --no-install-recommends \
adduser \
procps \
gosu \
nginx-light \
php8.5-mysql \
php8.5-pgsql \
php8.5-sqlite3 \
php8.5-imagick \
php8.5-mbstring \
php8.5-gd \
php8.5-xml \
php8.5-zip \
php8.5-fpm \
php8.5-redis \
php8.5-bcmath \
php8.5-intl \
php8.5-ldap \
netcat-openbsd \
libimage-exiftool-perl \
ffmpeg \
jpegoptim \
optipng \
pngquant \
gifsicle \
webp \
cron \
composer \
ghostscript && \
sed -i 's/<policy domain="coder" rights="none" pattern="PDF" \/>/<policy domain="coder" rights="read|write" pattern="PDF" \/>/g' /etc/ImageMagick-6/policy.xml && \
usermod -o -u "$PUID" "www-data" && \
groupmod -o -g "$PGID" "www-data" && \
echo "* * * * * www-data cd /app && php artisan schedule:run >> /dev/null 2>&1" >> /etc/crontab && \
apt-get clean -qy && \
rm -rf /var/lib/apt/lists/*
WORKDIR /app
# Copy application code
COPY --chown=www-data:www-data . .
# Copy vendor from composer stage
COPY --from=composer --chown=www-data:www-data /app/vendor ./vendor
# Copy built frontend assets from node stage
COPY --from=node --chown=www-data:www-data /app/public/build ./public/build
COPY --from=node --chown=www-data:www-data /app/public/embed ./public/embed
# Ensure storage and bootstrap/cache are writable with minimal permissions
RUN mkdir -p storage/framework/cache \
storage/framework/sessions \
storage/framework/views \
storage/logs \
bootstrap/cache \
public/dist \
&& chown -R www-data:www-data storage bootstrap/cache public/dist \
&& chmod -R 777 storage bootstrap/cache \
&& chmod -R 775 public/dist \
&& touch /app/docker_target \
&& touch /app/public/dist/user.css \
&& touch /app/public/dist/custom.js \
&& chown www-data:www-data /app/public/dist/user.css /app/public/dist/custom.js \
&& chmod 644 /app/public/dist/user.css /app/public/dist/custom.js
# Copy entrypoint and validation scripts
# Copy entrypoint and validation scripts
COPY docker/scripts/00-conf-check.sh /usr/local/bin/00-conf-check.sh
COPY docker/scripts/01-validate-env.sh /usr/local/bin/01-validate-env.sh
COPY docker/scripts/02-dump-env.sh /usr/local/bin/02-dump-env.sh
COPY docker/scripts/03-db-check.sh /usr/local/bin/03-db-check.sh
COPY docker/scripts/04-user-setup.sh /usr/local/bin/04-user-setup.sh
COPY docker/scripts/05-permissions-check.sh /usr/local/bin/05-permissions-check.sh
COPY docker/scripts/create-admin-user.sh /usr/local/bin/create-admin-user.sh
COPY docker/scripts/entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/00-conf-check.sh \
/usr/local/bin/01-validate-env.sh \
/usr/local/bin/02-dump-env.sh \
/usr/local/bin/03-db-check.sh \
/usr/local/bin/04-user-setup.sh \
/usr/local/bin/05-permissions-check.sh \
/usr/local/bin/create-admin-user.sh \
/usr/local/bin/entrypoint.sh \
&& mkdir -p /run/php \
&& mkdir -p /data /config \
&& chmod -R 775 /data /config
COPY docker/nginx.conf /etc/nginx/nginx.conf
# Expose port 8000 (Octane)
EXPOSE 8000
# Set entrypoint
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
# RUN chmod +x /entrypoint.sh && \
# chmod +x /inject.sh && \
# if [ ! -e /run/php ] ; then mkdir /run/php ; fi
HEALTHCHECK CMD curl --fail http://localhost:8000/ || exit 1
CMD [ "nginx" ]