-
-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathDockerfile
More file actions
128 lines (111 loc) · 3.86 KB
/
Copy pathDockerfile
File metadata and controls
128 lines (111 loc) · 3.86 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
# Build stage
FROM --platform=$TARGETPLATFORM php:8.3-fpm-alpine AS builder
# Add QEMU for cross-platform builds
COPY --from=tonistiigi/binfmt:latest /usr/bin/qemu-* /usr/bin/
# Install build dependencies
RUN apk add --no-cache --virtual .build-deps \
$PHPIZE_DEPS \
gcc \
g++ \
openssl-dev \
make \
libxml2-dev \
oniguruma-dev \
openldap-dev \
zstd-dev \
libzip-dev \
freetype-dev \
libpng-dev \
libjpeg-turbo-dev
# Set cross-compilation flags if needed
ARG TARGETPLATFORM
RUN case "${TARGETPLATFORM}" in \
linux/arm64*) export CFLAGS='-march=armv8-a' CXXFLAGS='-march=armv8-a' ;; \
esac
# Install and configure PHP extensions
RUN set -ex; \
# Configure extensions
docker-php-ext-configure gd --with-freetype --with-jpeg; \
# Install extensions one by one to prevent memory issues
docker-php-ext-install mysqli && \
docker-php-ext-install pdo_mysql && \
docker-php-ext-install bcmath && \
docker-php-ext-install mbstring && \
docker-php-ext-install exif && \
docker-php-ext-install pcntl && \
docker-php-ext-install opcache && \
docker-php-ext-install ldap && \
docker-php-ext-install zip && \
pecl install redis && docker-php-ext-enable redis && \
docker-php-ext-install gd && \
rm -rf /tmp/* /var/cache/apk/*
# Production stage
FROM --platform=$TARGETPLATFORM php:8.3-fpm-alpine
# Add production dependencies
RUN apk add --no-cache \
tini \
nginx \
mysql-client \
openssl \
supervisor \
freetype \
libpng \
zstd-libs \
libjpeg-turbo \
libzip \
openldap \
icu-libs && \
rm -rf /var/cache/apk/* /tmp/*
# Copy built extensions from builder
COPY --from=builder /usr/local/lib/php/extensions/ /usr/local/lib/php/extensions/
COPY --from=builder /usr/local/etc/php/conf.d/ /usr/local/etc/php/conf.d/
# Add non-root user
ARG PUID=1000
ARG PGID=1000
# Set working directory
WORKDIR /var/www/html
# Install Leantime
ARG LEAN_VERSION
RUN set -ex; \
curl -fsSL --retry 3 https://github.com/Leantime/leantime/releases/download/v${LEAN_VERSION}/Leantime-v${LEAN_VERSION}.tar.gz -o leantime.tar.gz && \
tar xzf leantime.tar.gz --strip-components 1 && \
rm leantime.tar.gz && \
chown -R www-data:www-data .
# Set Permissions
RUN set -ex; \
# Modify existing www-data user/group
deluser www-data; \
addgroup -g ${PGID} www-data; \
adduser -u ${PUID} -G www-data -h /home/www-data -s /bin/sh -D www-data; \
# Create required directories
mkdir -p /var/www/html/userfiles \
/var/www/html/public/userfiles \
/var/www/html/bootstrap/cache \
/var/www/html/storage/logs \
/var/www/html/storage/framework/cache \
/var/www/html/storage/framework/sessions \
/var/www/html/storage/framework/views \
/var/www/html/app/Plugins \
/run /var/log/nginx /var/lib/nginx; \
chown -R www-data:www-data /var/www/html /run /var/log/nginx /var/lib/nginx && \
chmod 775 /var/www/html/userfiles \
/var/www/html/public/userfiles \
/var/www/html/bootstrap/cache \
/var/www/html/storage/logs \
/var/www/html/storage/framework/cache \
/var/www/html/storage/framework/sessions \
/var/www/html/storage/framework/views \
/var/www/html/app/Plugins;
# Copy configuration files
COPY config/custom.ini /usr/local/etc/php/conf.d/
COPY config/nginx.conf /etc/nginx/nginx.conf
COPY config/php-fpm.conf /usr/local/etc/php-fpm.d/www.conf
COPY config/supervisord.conf /etc/supervisor/conf.d/supervisord.conf
COPY --chmod=0755 start.sh /start.sh
# Switch to non-root user
USER www-data
# Add healthcheck
HEALTHCHECK --interval=30s --timeout=10s --retries=3 \
CMD curl -f http://localhost:8080 || exit 1
EXPOSE 8080
ENTRYPOINT ["/sbin/tini", "--", "/start.sh"]