-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDockerfile
More file actions
127 lines (97 loc) · 3.68 KB
/
Dockerfile
File metadata and controls
127 lines (97 loc) · 3.68 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
# syntax=docker/dockerfile:1
# Use the official Alpine PHP image as base.
ARG PHP_MINOR_VERSION=8.1
ARG BASE_IMAGE=library/php:${PHP_MINOR_VERSION}-cli-alpine
FROM ${BASE_IMAGE} AS phpdev
ARG PHP_MINOR_VERSION
#------------------------------------------------------------------------------
# Install Composer
COPY --from=composer /usr/bin/composer /usr/local/bin/composer
#------------------------------------------------------------------------------
# Configure PHP in development mode
RUN cp /usr/local/etc/php/php.ini-development /usr/local/etc/php/php.ini
#------------------------------------------------------------------------------
# Install Basic Packages
ARG PACKAGES="\
make \
su-exec \
"
RUN --mount=type=cache,mode=0755,sharing=locked,id=apk-cache,target=/var/cache/apk <<EOT
apk update
apk upgrade
apk add ${PACKAGES}
EOT
#------------------------------------------------------------------------------
# Install PHP Extensions
# https://xdebug.org/docs/compat#versions
ARG XDEBUG_VERSION=3.1.6
ENV XDEBUG_VERSION=${XDEBUG_VERSION}
ARG PECL_PACKAGES="\
xdebug-${XDEBUG_VERSION} \
pcov \
"
ARG PECL_CACHE=/tmp/pecl
RUN --mount=type=cache,mode=0755,sharing=locked,id=apk-cache,target=/var/cache/apk \
--mount=type=cache,mode=0755,sharing=locked,id=pecl-cache-${PHP_MINOR_VERSION},target=${PECL_CACHE} \
<<EOT
set -e -x
# Get the extension directory
PHP_EXT_DIR=$(php-config --extension-dir)
# Restore cache, if some
cp -R ${PECL_CACHE}/* ${PHP_EXT_DIR} || true
# Install build deps
apk add --virtual .build-deps ${PHPIZE_DEPS} linux-headers
# Install missing pecl packages
for package in ${PECL_PACKAGES}; do
[ -z "$(find ${PHP_EXT_DIR} -name ${package%-*}.so)" ] && pecl install ${package}
docker-php-ext-enable ${package%-*}
done
# Update cache
cp -R ${PHP_EXT_DIR}/* ${PECL_CACHE}
# Cleanup build deps
apk del -f .build-deps
EOT
#------------------------------------------------------------------------------
# Create a dedicated user
ARG USER=phpdev
ARG UID=1000
ARG GID=1000
RUN <<EOT
addgroup -g ${GID} ${USER}
adduser -D -s /bin/ash -u ${UID} -G ${USER} -G www-data ${USER}
touch /var/log/xdebug.log && chown ${USER}:www-data /var/log/xdebug.log
EOT
WORKDIR /home/${USER}
# Export user's related variables to the env for use by other containers
ENV CONTAINER_USER_NAME=${USER}
ENV CONTAINER_USER_UID=${UID}
ENV CONTAINER_USER_GID=${GID}
#------------------------------------------------------------------------------
# Entrypoint
COPY ./docker/* /opt/docker/
ENTRYPOINT ["/opt/docker/entrypoint.sh"]
#------------------------------------------------------------------------------
# Labels
ARG BASE_DIGEST
ARG BASE_IMAGE
ARG CREATED_DATE
ARG REPOSITORY
ARG REVISION
ARG URL
LABEL org.opencontainers.image.created=${CREATED_DATE}
LABEL org.opencontainers.image.authors="Richard 'Sylver' Kemp <sylver@materya.io>"
LABEL org.opencontainers.image.url=${URL}
LABEL org.opencontainers.image.documentation=${URL}/README.md
LABEL org.opencontainers.image.source=${URL}
LABEL org.opencontainers.image.version=${PHP_VERSION}
LABEL org.opencontainers.image.revision=${REVISION}
LABEL org.opencontainers.image.vendor="Materya"
LABEL org.opencontainers.image.licenses="GPL-3.0-only"
LABEL org.opencontainers.image.ref.name=${REPOSITORY}:${PHP_MINOR_VERSION}
LABEL org.opencontainers.image.title="PHP ${PHP_MINOR_VERSION} Development Container"
LABEL org.opencontainers.image.description="A lightweight base image for PHP projects development."
LABEL org.opencontainers.image.base.digest=${BASE_DIGEST}
LABEL org.opencontainers.image.base.name=${BASE_IMAGE}
#------------------------------------------------------------------------------
# Final command
CMD ["php", "-a"]