-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
100 lines (75 loc) · 2.44 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
# ================ Stage 1: Composer dependencies =====================
FROM composer:2 as composer_prod
WORKDIR /app
COPY . .
RUN composer install --no-interaction --no-dev --prefer-dist --optimize-autoloader
RUN rm -rf /root/.composer/cache
# =============== Stage 1b: Composer for testing =======================
FROM composer:2 as composer_test
WORKDIR /app
COPY . .
RUN composer install --no-interaction
RUN rm -rf /root/.composer/cache
# =============== Stage 2: Frontend build with Node.js ===============
FROM node:alpine AS frontend
WORKDIR /app
COPY package.json package-lock.json vite.config.js ./
RUN npm ci
COPY . .
COPY --from=composer_prod /app/vendor ./vendor
RUN npm run build && npm cache clean --force
# ============== Stage 3: Setup PHP and Laravel for production ===============
FROM php:8.2-fpm-alpine AS prod
# Install system dependencies
RUN apk update && apk add --no-cache \
curl \
zip \
unzip \
git \
oniguruma-dev \
icu-dev \
libzip-dev \
nginx
# Configure PHP extensions
RUN docker-php-ext-install \
pdo_mysql \
mbstring \
zip \
intl
# Copy vendor files from composer stage
COPY --from=composer_prod /app/vendor /var/www/html/vendor
# Copy frontend build files
COPY --from=frontend /app/public /var/www/html/public
# Copy project files
COPY . /var/www/html
# Set workdir
WORKDIR /var/www/html
# Copy our prod script and set permissions
COPY start_prod.sh /start.sh
RUN chmod +x /start.sh
# Remove the 'tests' directory (to ensure they are not in prod image, they can be added back later for testing)
RUN rm -rf /var/www/html/tests
#-----Setup permissions------
RUN addgroup -g 1000 web
RUN addgroup nginx web && \
addgroup www-data web
RUN chown -R www-data:web /var/www/html && \
chmod -R g+rwxs /var/www/html && \
chmod -R 775 /var/www/html
# Copy Nginx config file
COPY nginx.conf /etc/nginx/http.d/default.conf
# Expose port 80
EXPOSE 80
# Run our prod script (this is overriden when running tests below.)
CMD /bin/sh /start.sh
# ================= Stage 4: Setup PHP and Laravel for testing ==========================
FROM prod AS test
# Copy test vendor files from composer stage
COPY --from=composer_test /app/vendor /var/www/html/vendor
# Copy test project files
COPY tests /var/www/html/tests
# Copy testing .env file to use as the main .env
COPY .env.testing /var/www/html/.env
# Copy our testing script and set permissions
COPY start_tests.sh /start.sh
RUN chmod +x /start.sh