-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
125 lines (88 loc) · 3.47 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
### PHP version we are targetting
ARG PHP_VERSION=8.1
### 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 ["tini", "--", "/usr/local/bin/app-start"]
### Build JS/css assets
FROM node:16.14.2 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 vite.config.js .babelrc* /home/node/
COPY --chown=node:node resources/js* /home/node/resources/js
COPY --chown=node:node resources/sass* /home/node/resources/sass
COPY --chown=node:node resources/scss* /home/node/resources/scss
COPY --chown=node:node resources/css* /home/node/resources/css
RUN npm install && \
npm run build && \
npm cache clean --force
### Prod php dependencies
FROM dev 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
#- copy the seeds and factories so that composer generates autoload entries for them
COPY database/seeders database/seeders
COPY database/factories 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
#- 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/build/assets
COPY --from=frontend /home/node/public/build/assets /var/www/html/public/build/assets
COPY --from=frontend /home/node/public/build/manifest.json /var/www/html/public/build/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
### Build the ci version of the app (prod+dev packages)
FROM prod as ci
ENV APP_ENV=local
ENV APP_DEBUG=0
#- Copy in our QA php dep's
COPY --from=qa-composer /var/www/html/vendor /var/www/html/vendor
#- Install phpcs style checker and clear the caches
RUN 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