-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
153 lines (124 loc) · 4.78 KB
/
Dockerfile
File metadata and controls
153 lines (124 loc) · 4.78 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
# ==========================================================================
# ## Cosine docker image ##
# ==========================================================================
# This image provides a fully working Cosine instance
# It provides the following build arguments:
# - PHP_VERSION: The version of PHP to use
# - UID: The user ID of the cmfive user
# - GID: The group ID of the cmfive group
# NOTE: See the .dockerignore file to see what is excluded from the image.
# Define the Alpine version to use
ARG ALPINE_VERSION=3.22
# ==========================================================================
# STAGE 1: Build the theme
# ==========================================================================
FROM --platform=$BUILDPLATFORM node:20 AS theme-build
WORKDIR /var/www/html
# Copy modules for the build
COPY system/modules/ system/modules/
COPY modules/ modules/
# Install dependencies
COPY system/templates/base/package*.json system/templates/base/
RUN cd system/templates/base/ && (npm ci || npm install)
# Build the theme
COPY system/templates/base/ system/templates/base/
RUN cd system/templates/base/ && npm run prod
# ==========================================================================
# STAGE 2: Build the final image
# ==========================================================================
FROM alpine:${ALPINE_VERSION}
# PHP version
# note: see Alpine packages for available versions
ARG PHP_VERSION=84
ENV PHP_VERSION=$PHP_VERSION
ARG UID=1000
ARG GID=1000
# Create cmfive user and group
RUN addgroup -g ${GID} cmfive && \
adduser -u ${UID} -G cmfive -s /bin/bash -D cmfive
# Link PHP Config
RUN mkdir -p /etc/php && \
ln -s /etc/php /etc/php$PHP_VERSION
# Install required packages for PHP, Nginx etc
RUN apk --no-cache add \
php$PHP_VERSION \
php$PHP_VERSION-fpm \
php$PHP_VERSION-cli \
php$PHP_VERSION-curl \
php$PHP_VERSION-gd \
php$PHP_VERSION-iconv \
php$PHP_VERSION-imap \
php$PHP_VERSION-json \
php$PHP_VERSION-mbstring \
php$PHP_VERSION-mysqli \
php$PHP_VERSION-xml \
php$PHP_VERSION-zip \
php$PHP_VERSION-pdo \
php$PHP_VERSION-pdo_mysql \
php$PHP_VERSION-phar \
php$PHP_VERSION-intl \
php$PHP_VERSION-gettext \
php$PHP_VERSION-session \
php$PHP_VERSION-simplexml \
php$PHP_VERSION-fileinfo \
php$PHP_VERSION-opcache \
php$PHP_VERSION-dom \
nginx \
mysql-client \
mariadb-connector-c-dev \
supervisor \
bash \
openssl \
memcached \
curl \
wget \
unzip \
icu-data-full \
git
# Link PHP cli
RUN ln -s /usr/bin/php${PHP_VERSION} /usr/bin/php
# Create necessary directories
RUN mkdir -p /var/www && \
mkdir -p /run/nginx
# Generate dev/placeholder self-signed SSL certificate
RUN openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout /etc/nginx/nginx.key \
-out /etc/nginx/nginx.crt \
-subj "/C=AU/ST=NSW/L=Bega/O=2pisoftware/OU=Development/CN=2pisoftware.com"
# Copy configuration files
COPY /.codepipeline/docker/configs/supervisord/supervisord.conf /etc/supervisord.conf
COPY /.codepipeline/docker/configs/nginx/nginx.conf /etc/nginx/nginx.conf
COPY /.codepipeline/docker/configs/nginx/default.conf /etc/nginx/conf.d/default.conf
COPY /.codepipeline/docker/configs/fpm/ /etc/php/
COPY /.codepipeline/docker/setup.sh /bootstrap/setup.sh
COPY /.codepipeline/docker/start.sh /bootstrap/start.sh
COPY /.codepipeline/docker/config.default.php /bootstrap/config.default.php
# Copy source
COPY --chown=cmfive:cmfive . /var/www/html
# Set working directory
WORKDIR /var/www/html
# Remove .codepipeline
RUN rm -rf .codepipeline
# Create a link to installation tools
RUN ln -s /var/www/html/cmfive.php /usr/local/bin/tools
# Install composer modules
RUN touch /var/www/html/config.php
RUN su cmfive -c 'INSTALL_ENV=docker tools install core'
# Fix permissions
RUN chmod -R ugo=rwX cache/ storage/ uploads/ && \
chown -R cmfive:cmfive /var/lib/nginx /var/log/nginx
# Install the theme
COPY --from=theme-build /var/www/html/system/templates/base/dist /var/www/html/system/templates/base/dist
# Install startup banner
COPY --chown=cmfive:cmfive /.codepipeline/docker/banner_starting.php /var/www/html/banner.php
COPY --chown=cmfive:cmfive /.codepipeline/docker/banner_starting.php /bootstrap/banner_starting.php
COPY --chown=cmfive:cmfive /.codepipeline/docker/banner_error.php /bootstrap/banner_error.php
# Expose HTTP, HTTPS
EXPOSE 80 443
# Healthcheck to ensure nginx and php-fpm is running and cmfive is installed
HEALTHCHECK --interval=15s --timeout=5m --start-period=5s --retries=15 \
CMD supervisorctl status nginx | grep -q "RUNNING" && \
supervisorctl status php-fpm | grep -q "RUNNING" && \
test -f /home/cmfive/.cmfive-installed
# Start supervisord
CMD ["supervisord", "--nodaemon", "--configuration", "/etc/supervisord.conf"]