-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
114 lines (88 loc) · 3.01 KB
/
Dockerfile
File metadata and controls
114 lines (88 loc) · 3.01 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
FROM node:11 AS frontend-static
WORKDIR /usr/src/app
# VOLUME /usr/src/app/public
RUN npm install -g npm-run-all webpack bower gulp
# todo refuse from bower at all
COPY bower.json package.json ./
RUN <<EOF
set -eux
bower install
npm install
EOF
COPY webpack.config.js gulpfile.js .babelrc ./
COPY ./frontend_src ./frontend_src
ENV NODE_ENV=production
RUN npm run build
ENTRYPOINT ["npm", "run", "build"]
FROM php:8.4-fpm AS php-fpm-base
WORKDIR /usr/src/app
VOLUME /usr/src/app/var
RUN <<EOF
set -eux
apt-get update
apt-get install -y --no-install-recommends --no-install-suggests git libzip-dev libicu-dev
pecl install apcu
docker-php-ext-install pdo zip opcache intl
docker-php-ext-enable apcu
rm -rf /var/lib/apt/lists/*
EOF
COPY --from=composer:2 /usr/bin/composer /usr/bin/composer
# https://getcomposer.org/doc/03-cli.md#composer-allow-superuser
# ENV COMPOSER_ALLOW_SUPERUSER=1
ENV PHP_INI_SCAN_DIR=":$PHP_INI_DIR/app.conf.d"
COPY --link docker/php/conf.d/10-app.ini "$PHP_INI_DIR/app.conf.d/"
ENV PATH "$PATH:/usr/src/app/vendor/bin:/usr/src/app/bin"
# todo add healthcheck
EXPOSE 9000
FROM php-fpm-base AS php-fpm-dev
ENV ENV=dev APP_ENV=dev SYMFONY_ENV=dev XDEBUG_MODE=off
RUN pecl install xdebug-3.4.0 && docker-php-ext-enable xdebug
RUN mv "$PHP_INI_DIR/php.ini-development" "$PHP_INI_DIR/php.ini"
COPY --link docker/php/conf.d/20-app.dev.ini "$PHP_INI_DIR/app.conf.d/"
# Next two steps are for correct directories initialization for the first time build:
RUN <<EOF
set -eux
mkdir -p var/cache var/logs var/data var/sessions
chown -R www-data var
chmod -R u+w var
EOF
VOLUME /usr/src/app/
FROM php-fpm-base AS php-fpm-prod
ENV ENV=prod APP_ENV=prod SYMFONY_ENV=prod
RUN mv "$PHP_INI_DIR/php.ini-production" "$PHP_INI_DIR/php.ini"
COPY --link docker/php/conf.d/20-app.prod.ini "$PHP_INI_DIR/app.conf.d/"
# prevent the reinstallation of vendors at every changes in the source code
COPY --link composer.* ./
RUN <<EOF
set -eux
php -d memory_limit=-1 \
/usr/bin/composer install --no-cache --prefer-dist --no-dev --no-autoloader --no-scripts --no-progress -v
EOF
# copy sources
COPY --link . ./
RUN rm -rf docker/
RUN <<EOF
set -eux
composer dump-autoload --classmap-authoritative --no-dev
chmod +x bin/console
sync
bin/console cache:warmup --env=prod --no-debug
bin/console assets:install
EOF
# Create static shared volume
RUN <<EOF
set -eux
# Hack to initialize a volume. See https://forums.docker.com/t/volume-subpath-in-docker-compose/143463/5
mkdir -p /usr/src/shared/public/misc \
/usr/src/shared/public/media \
/usr/src/shared/app/Resources/main
# Copy vendors assets # fixme dirty ?
cp -rL /usr/src/app/public/bundles \
/usr/src/shared/public/bundles
EOF
# Next step covers two things:
# 1. Forces docker to build `frontend-static` container with assets,
# avoiding redudant container decaration in compose file
# 2. Moves built assets into `php-fpm` image for build consistency purspose
COPY --from=frontend-static /usr/src/app/public/static/assets /usr/src/shared/public/static/assets
VOLUME /usr/src/shared/