-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
178 lines (141 loc) · 6.21 KB
/
Dockerfile
File metadata and controls
178 lines (141 loc) · 6.21 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
# syntax=docker/dockerfile:1.23
#########################################
# Base stage - minimal runtime dependencies
# Pin to digest for supply chain security (renovate will update)
FROM php:8.5-alpine@sha256:dccc3abcf3d37a6bb081477a66ed4344716784a6ef5107625ae6ba9ec52df778 AS base
# Security: Create non-root user early
RUN addgroup -g 1000 phpbu && \
adduser -D -u 1000 -G phpbu -s /sbin/nologin phpbu
# Install runtime dependencies only
# Note: redis package includes redis-cli for Redis backups
# hadolint ignore=DL3018
RUN apk --no-cache --update upgrade && \
apk --no-cache add \
mysql-client \
postgresql-client \
mongodb-tools \
redis \
ca-certificates \
tzdata && \
# Remove apk cache, temp files, and unnecessary files
rm -rf /var/cache/apk/* /tmp/* /root/.cache /var/log/*
WORKDIR /app
#########################################
# Base-full stage - additional tools for full variant
FROM base AS base-full
# Additional tools for sync adapters and encryption
# hadolint ignore=DL3018
RUN apk --no-cache add \
rsync \
gnupg \
openssh-client \
curl && \
rm -rf /var/cache/apk/* /tmp/*
# Install PHP FTP extension for FTP sync adapter
RUN docker-php-ext-install ftp
#########################################
# Build stage - compile dependencies (minimal)
FROM base AS build-minimal
# Composer in build stage only (not in final image)
ENV COMPOSER_ALLOW_SUPERUSER=1 \
COMPOSER_HOME=/tmp/composer
# Install Composer from official image (pinned for reproducibility)
COPY --from=composer:2@sha256:dc292c5c0f95f526b051d4c341bf08e7e2b18504c74625e3203d7f123050e318 /usr/bin/composer /usr/bin/composer
# Copy dependency files first (layer caching)
COPY --chown=phpbu:phpbu app/composer.json app/composer.lock ./
# Install dependencies with optimization
RUN composer install \
--no-ansi \
--no-dev \
--no-interaction \
--no-scripts \
--prefer-dist \
--optimize-autoloader \
--classmap-authoritative && \
# Clean up composer cache
rm -rf /tmp/composer
#########################################
# Build stage - compile dependencies (full)
FROM base-full AS build-full
# Composer in build stage only (not in final image)
ENV COMPOSER_ALLOW_SUPERUSER=1 \
COMPOSER_HOME=/tmp/composer
# Note: PHP FTP extension already installed in base-full stage
# Install Composer from official image (pinned for reproducibility)
COPY --from=composer:2@sha256:dc292c5c0f95f526b051d4c341bf08e7e2b18504c74625e3203d7f123050e318 /usr/bin/composer /usr/bin/composer
# Copy full variant dependency files
COPY --chown=phpbu:phpbu app/full/composer.json ./composer.json
COPY --chown=phpbu:phpbu app/full/composer.lock ./composer.lock
# Install dependencies with optimization
RUN composer install \
--no-ansi \
--no-dev \
--no-interaction \
--no-scripts \
--prefer-dist \
--optimize-autoloader \
--classmap-authoritative && \
# Clean up composer cache
rm -rf /tmp/composer
#########################################
# Final stage - minimal production image
FROM base AS minimal
# PHP security hardening
COPY app/php-hardening.ini /usr/local/etc/php/conf.d/99-hardening.ini
# OCI image labels
LABEL org.opencontainers.image.title="phpbu-docker" \
org.opencontainers.image.description="PHP Backup Utility Docker Image (minimal)" \
org.opencontainers.image.vendor="Netresearch DTT GmbH" \
org.opencontainers.image.source="https://github.com/netresearch/phpbu-docker" \
org.opencontainers.image.documentation="https://github.com/netresearch/phpbu-docker#readme" \
org.opencontainers.image.licenses="LGPL-3.0" \
org.opencontainers.image.base.name="docker.io/library/php:8.5-alpine" \
org.opencontainers.image.variant="minimal"
# Copy built application from build stage
COPY --from=build-minimal --chown=phpbu:phpbu /app /app
# Copy entrypoint script (not in build stage, must be copied separately)
COPY --chmod=755 --chown=phpbu:phpbu app/docker-entrypoint.sh /app/docker-entrypoint.sh
# Create directories with correct permissions
# tz.ini owned by phpbu so entrypoint can set timezone from TZ env var
RUN mkdir -p /backups && chown phpbu:phpbu /backups && \
touch /usr/local/etc/php/conf.d/tz.ini && chown phpbu:phpbu /usr/local/etc/php/conf.d/tz.ini
# Security: Switch to non-root user
USER phpbu
# Volumes for config and backup output
VOLUME ["/backups"]
# Healthcheck - verify phpbu is functional
HEALTHCHECK --interval=60s --timeout=10s --start-period=5s --retries=3 \
CMD ["/app/vendor/bin/phpbu", "--version"]
ENTRYPOINT ["/app/docker-entrypoint.sh"]
CMD ["--help"]
#########################################
# Final stage - full production image
FROM base-full AS full
# PHP security hardening
COPY app/php-hardening.ini /usr/local/etc/php/conf.d/99-hardening.ini
# OCI image labels
LABEL org.opencontainers.image.title="phpbu-docker" \
org.opencontainers.image.description="PHP Backup Utility Docker Image (full - all sync adapters)" \
org.opencontainers.image.vendor="Netresearch DTT GmbH" \
org.opencontainers.image.source="https://github.com/netresearch/phpbu-docker" \
org.opencontainers.image.documentation="https://github.com/netresearch/phpbu-docker#readme" \
org.opencontainers.image.licenses="LGPL-3.0" \
org.opencontainers.image.base.name="docker.io/library/php:8.5-alpine" \
org.opencontainers.image.variant="full"
# Copy built application from build stage
COPY --from=build-full --chown=phpbu:phpbu /app /app
# Copy entrypoint script (not in build stage, must be copied separately)
COPY --chmod=755 --chown=phpbu:phpbu app/docker-entrypoint.sh /app/docker-entrypoint.sh
# Create directories with correct permissions
# tz.ini owned by phpbu so entrypoint can set timezone from TZ env var
RUN mkdir -p /backups && chown phpbu:phpbu /backups && \
touch /usr/local/etc/php/conf.d/tz.ini && chown phpbu:phpbu /usr/local/etc/php/conf.d/tz.ini
# Security: Switch to non-root user
USER phpbu
# Volumes for config and backup output
VOLUME ["/backups"]
# Healthcheck - verify phpbu is functional
HEALTHCHECK --interval=60s --timeout=10s --start-period=5s --retries=3 \
CMD ["/app/vendor/bin/phpbu", "--version"]
ENTRYPOINT ["/app/docker-entrypoint.sh"]
CMD ["--help"]