Skip to content

Commit db21bcc

Browse files
authored
add more flexibility on image building + fix missing JS assets on image construction (#75)
Signed-off-by: Aurelien Fontaine <a.fontaine@naitways.com>
1 parent db02f62 commit db21bcc

File tree

5 files changed

+53
-38
lines changed

5 files changed

+53
-38
lines changed

Dockerfile

Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,47 @@
11
#############################################################
2-
# PHP-FPM #
2+
# GLOBAL ARGS #
33
#############################################################
4+
45
ARG PHP_VERSION=7.4
5-
ARG NODE_VERSION=14
66
ARG NGINX_VERSION=1.21
7+
ARG NODE_VERSION=14
8+
9+
#############################################################
10+
# NODEJS #
11+
#############################################################
12+
13+
FROM node:${NODE_VERSION}-alpine AS server-for-symfony-flex-nodejs
14+
15+
WORKDIR /srv/server-for-symfony-flex
16+
17+
RUN set -eux; \
18+
apk add --no-cache \
19+
g++ \
20+
gcc \
21+
git \
22+
make \
23+
python2 \
24+
;
25+
26+
COPY package.json package-lock.json webpack.config.js ./
27+
COPY assets ./assets
28+
29+
RUN set -eux; \
30+
npm install ; \
31+
npm cache clean --force
32+
33+
RUN npm run build
34+
35+
COPY docker/nodejs/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
36+
RUN chmod +x /usr/local/bin/docker-entrypoint
37+
38+
ENTRYPOINT ["docker-entrypoint"]
39+
CMD ["npm", "run", "watch"]
40+
41+
#############################################################
42+
# PHP-FPM #
43+
#############################################################
44+
745

846
FROM php:${PHP_VERSION}-fpm-alpine AS server-for-symfony-flex-php
947

@@ -71,7 +109,9 @@ RUN set -eux; \
71109

72110
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
73111

74-
COPY docker/php/php.ini /usr/local/etc/php/php.ini
112+
ARG PHP_DATE_TIMEZONE=UTC
113+
COPY docker/php/php.ini.template /usr/local/etc/php/php.ini.template
114+
RUN envsubst '${PHP_DATE_TIMEZONE}' < /usr/local/etc/php/php.ini.template > /usr/local/etc/php/php.ini
75115

76116
ARG FPM_PORT=9000
77117
COPY docker/php/www.conf.template /usr/local/etc/php-fpm.d/www.conf.template
@@ -104,43 +144,14 @@ RUN set -eux; \
104144
chmod +x bin/console; \
105145
sync
106146

147+
COPY --from=server-for-symfony-flex-nodejs /srv/server-for-symfony-flex/public public/
148+
107149
COPY docker/php/php-entrypoint.sh /usr/local/bin/docker-entrypoint
108150
RUN chmod +x /usr/local/bin/docker-entrypoint
109151

110152
ENTRYPOINT ["docker-entrypoint"]
111153
CMD ["php-fpm"]
112154

113-
#############################################################
114-
# NODEJS #
115-
#############################################################
116-
FROM node:${NODE_VERSION}-alpine AS server-for-symfony-flex-nodejs
117-
118-
WORKDIR /srv/server-for-symfony-flex
119-
120-
RUN set -eux; \
121-
apk add --no-cache \
122-
g++ \
123-
gcc \
124-
git \
125-
make \
126-
python2 \
127-
;
128-
129-
COPY package.json package-lock.json webpack.config.js ./
130-
COPY assets ./assets
131-
132-
RUN set -eux; \
133-
npm install ; \
134-
npm cache clean --force
135-
136-
RUN npm run build
137-
138-
COPY docker/nodejs/docker-entrypoint.sh /usr/local/bin/docker-entrypoint
139-
RUN chmod +x /usr/local/bin/docker-entrypoint
140-
141-
ENTRYPOINT ["docker-entrypoint"]
142-
CMD ["npm", "run", "watch"]
143-
144155
#############################################################
145156
# NGINX #
146157
#############################################################
@@ -151,17 +162,18 @@ WORKDIR /srv/server-for-symfony-flex
151162
COPY docker/nginx/nginx.conf /etc/nginx/nginx.conf
152163

153164
ARG NGINX_PORT=8080
165+
ARG FPM_HOSTNAME=localhost
154166
ARG FPM_PORT=9000
155167
COPY docker/nginx/conf.d/default.conf.template /etc/nginx/conf.d/default.conf.template
156-
RUN envsubst '${NGINX_PORT} ${FPM_PORT}' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf
168+
RUN envsubst '${NGINX_PORT} ${FPM_HOSTNAME} ${FPM_PORT}' < /etc/nginx/conf.d/default.conf.template > /etc/nginx/conf.d/default.conf
157169

158170
COPY --from=server-for-symfony-flex-php /srv/server-for-symfony-flex/public public/
159-
COPY --from=server-for-symfony-flex-nodejs /srv/server-for-symfony-flex/public public/
160171

161172
RUN apk add --no-cache bash
162173

163174
COPY docker/nginx/wait-for-it.sh /
164175
RUN chmod +x /wait-for-it.sh
165176

166177
ENV FPM_PORT=$FPM_PORT
167-
CMD /wait-for-it.sh -t 0 localhost:$FPM_PORT -- nginx -g "daemon off;"
178+
ENV FPM_HOSTNAME=$FPM_HOSTNAME
179+
CMD /wait-for-it.sh -t 0 $FPM_HOSTNAME:$FPM_PORT -- nginx -g "daemon off;"

docker-compose.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ services:
77
target: server-for-symfony-flex-php
88
args:
99
- FPM_PORT=${FPM_PORT:-9000}
10+
- PHP_DATE_TIMEZONE=${PHP_DATE_TIMEZONE:-UTC}
1011
env_file:
1112
- .env.local
1213
volumes:
@@ -20,6 +21,7 @@ services:
2021
target: server-for-symfony-flex-nginx
2122
args:
2223
- NGINX_PORT=${NGINX_PORT:-8080}
24+
- FPM_HOSTNAME=${FPM_HOSTNAME:-localhost}
2325
- FPM_PORT=${FPM_PORT:-9000}
2426
depends_on:
2527
- php

docker/nginx/conf.d/default.conf.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ server {
99

1010
location ~ ^/index\.php(/|$) {
1111
# Comment the next line and uncomment the next to enable dynamic resolution (incompatible with Kubernetes)
12-
fastcgi_pass localhost:${FPM_PORT};
12+
fastcgi_pass ${FPM_HOSTNAME}:${FPM_PORT};
1313
#resolver 127.0.0.11;
1414
#set $upstream_host php;
1515
#fastcgi_pass $upstream_host:9000;

docker/php/php-entrypoint.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ fi
88

99
if [ "$1" = 'php-fpm' ]; then
1010
bin/console recipes:initialize
11+
bin/console system:status
1112
fi
1213

1314
exec docker-php-entrypoint "$@"
File renamed without changes.

0 commit comments

Comments
 (0)