-
Notifications
You must be signed in to change notification settings - Fork 22
/
Dockerfile
129 lines (89 loc) · 3.51 KB
/
Dockerfile
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
### PHP version we are targetting
ARG PHP_VERSION=7.4
### Placeholder for basic dev stage for use with docker-compose
FROM uogsoe/soe-php-apache:${PHP_VERSION} as dev
COPY docker/app-start docker/app-healthcheck /usr/local/bin/
RUN chmod u+x /usr/local/bin/app-start /usr/local/bin/app-healthcheck
CMD ["/usr/local/bin/app-start"]
### Build JS/css assets
FROM node:10 as frontend
# workaround for mix.version() webpack bug
RUN ln -s /home/node/public /public
USER node
WORKDIR /home/node
RUN mkdir -p /home/node/public/css /home/node/public/js /home/node/resources
COPY --chown=node:node package*.json webpack.mix.js .babelrc* tailwind* /home/node/
COPY --chown=node:node resources/js* /home/node/resources/js
COPY --chown=node:node resources/css* /home/node/resources/css
RUN npm install && \
npm run production && \
npm cache clean --force
### Prod php dependencies
FROM uogsoe/soe-php-apache:${PHP_VERSION} as prod-composer
ENV APP_ENV=production
ENV APP_DEBUG=0
WORKDIR /var/www/html
USER nobody
#- make paths that the laravel composer.json expects to exist
RUN mkdir -p database/seeders database/factories
COPY composer.* ./
RUN composer install \
--no-interaction \
--no-plugins \
--no-scripts \
--no-dev \
--prefer-dist
### QA php dependencies
FROM prod-composer as qa-composer
ENV APP_ENV=local
ENV APP_DEBUG=1
RUN composer install \
--no-interaction \
--no-plugins \
--no-scripts \
--prefer-dist
### And build the prod app
FROM dev as prod
WORKDIR /var/www/html
ENV APP_ENV=production
ENV APP_DEBUG=0
#- install the redis php extension
RUN php -m | grep -q redis || pecl install redis-5.0.2 && docker-php-ext-enable redis
#- Copy our start scripts and php/ldap configs in
COPY docker/ldap.conf /etc/ldap/ldap.conf
COPY docker/custom_php.ini /usr/local/etc/php/conf.d/custom_php.ini
#- Copy in our prod php dep's
COPY --from=prod-composer /var/www/html/vendor /var/www/html/vendor
#- Copy in our front-end assets
RUN mkdir -p /var/www/html/public/js /var/www/html/public/css
COPY --from=frontend /home/node/public/js /var/www/html/public/js
COPY --from=frontend /home/node/public/css /var/www/html/public/css
COPY --from=frontend /home/node/mix-manifest.json /var/www/html/mix-manifest.json
#- Copy in our code
COPY . /var/www/html
#- Clear any cached composer stuff
RUN rm -fr /var/www/html/bootstrap/cache/*.php
#- If horizon is installed force it to rebuild it's public assets
RUN if grep -q horizon composer.json; then php /var/www/html/artisan horizon:publish; fi
#- Symlink the docker secret to the local .env so Laravel can see it
RUN ln -sf /run/secrets/.env /var/www/html/.env
#- Clean up and production-cache our apps settings/views/routing
RUN php /var/www/html/artisan storage:link && \
php /var/www/html/artisan view:cache && \
php /var/www/html/artisan route:cache && \
chown -R www-data:www-data storage bootstrap/cache
#- Set up the default healthcheck
HEALTHCHECK --start-period=30s CMD /usr/local/bin/app-healthcheck
#- And off we go...
CMD ["/usr/local/bin/app-start"]
### Build the ci version of the app (prod+dev packages)
FROM prod as ci
ENV APP_ENV=local
ENV APP_DEBUG=1
#- Copy in our QA php dep's
COPY --from=qa-composer /var/www/html/vendor /var/www/html/vendor
#- Install sensiolabs security scanner and clear the caches
RUN composer global require enlightn/security-checker && \
curl -OL -o /usr/local/bin/phpcs https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar && \
php /var/www/html/artisan view:clear && \
php /var/www/html/artisan cache:clear