Skip to content

Commit 052aa94

Browse files
committed
6601: Updated and simplifyed docker image build
1 parent 2c76f56 commit 052aa94

6 files changed

Lines changed: 41 additions & 134 deletions

File tree

.github/workflows/github_build_release.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@ jobs:
9494
password: ${{ secrets.GITHUB_TOKEN }}
9595

9696
# Build main
97-
9897
- name: Docker meta (main)
9998
id: meta-main
10099
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
@@ -125,7 +124,6 @@ jobs:
125124
push-to-registry: true
126125

127126
# Build Nginx (depends on main)
128-
129127
- name: Docker meta (nginx)
130128
id: meta-nginx
131129
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
File renamed without changes.

infrastructure/build-n-push.sh

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,26 @@
22

33
set -eux
44

5-
APP_VERSION=develop
5+
APP_VERSION=3.0.0-beta1
66

77
docker pull itkdev/php8.4-fpm:alpine
88
docker pull nginxinc/nginx-unprivileged:alpine
99

10-
docker build --build-context repository-root=.. \
10+
docker buildx build \
1111
--platform linux/amd64,linux/arm64 \
12-
--pull \
1312
--no-cache \
13+
--pull \
1414
--build-arg APP_VERSION=${APP_VERSION} \
15-
--tag=turegjorup/display-api-service:${APP_VERSION} \
16-
--file="display-api-service/Dockerfile" display-api-service
15+
--tag=ghcr.io/itk-dev/display-api-service:${APP_VERSION} \
16+
--file="display-api-service/Dockerfile" ../
1717

18-
19-
docker build --build-context repository-root=.. \
18+
docker buildx build \
2019
--platform linux/amd64,linux/arm64 \
2120
--no-cache \
21+
--pull \
2222
--build-arg VERSION=${APP_VERSION} \
23-
--tag=turegjorup/display-api-service-nginx:${APP_VERSION} \
23+
--tag=ghcr.io/itk-dev/display-api-service-nginx:${APP_VERSION} \
2424
--file="nginx/Dockerfile" nginx
2525

26-
docker push os2display/display-api-service:${APP_VERSION}
27-
docker push os2display/display-api-service-nginx:${APP_VERSION}
26+
#docker push ghcr.io/itk-dev/display-api-service:${APP_VERSION}
27+
#docker push ghcr.io/itk-dev/display-api-service-nginx:${APP_VERSION}

infrastructure/display-api-service/Dockerfile

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
######## Clients [Screen|Admin] build ########
2-
FROM node:24-alpine AS client_app_builder
2+
FROM --platform=$BUILDPLATFORM node:24-alpine AS client_app_builder
33
LABEL maintainer="ITK Dev <itkdev@mkb.aarhus.dk>"
44

55
ARG APP_VERSION="develop"
@@ -10,44 +10,37 @@ ENV APP_CLIENT_PATH=/app
1010
WORKDIR ${APP_CLIENT_PATH}
1111

1212
# Copy only necessary files for npm install
13-
COPY --from=repository-root package.json package-lock.json vite.config.js ./
13+
COPY package.json package-lock.json vite.config.js ./
1414

1515
# Install dependencies
1616
RUN npm ci --no-audit --no-fund
1717

1818
# Copy source files needed for build
19-
COPY --from=repository-root assets/ ./assets/
20-
COPY --from=repository-root public/client/ ./public/client/
19+
COPY assets/ ./assets/
20+
COPY public/client/ ./public/client/
2121

2222
# Build the application with version info
2323
RUN npm run build
2424

2525

2626
######### API backend build ########
27-
FROM itkdev/php8.4-fpm:alpine AS api_app_builder
27+
FROM --platform=$BUILDPLATFORM itkdev/php8.4-fpm:latest AS api_app_builder
2828
LABEL maintainer="ITK Dev <itkdev@mkb.aarhus.dk>"
2929

3030
ARG APP_VERSION="develop"
3131
ENV APP_CLIENT_PATH=/app \
3232
APP_API_PATH=/var/www/html
3333

34-
USER root
35-
36-
# Add composer in from the official composer image (also alpine).
37-
COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer
38-
3934
WORKDIR ${APP_API_PATH}
4035

41-
USER deploy
42-
4336
# Copy only composer files first for better layer caching
44-
COPY --chown=deploy:deploy --from=repository-root composer.json composer.lock symfony.lock ${APP_API_PATH}/
37+
COPY composer.json composer.lock symfony.lock ${APP_API_PATH}/
4538

4639
# Pre-install composer packages first (better image layer caching) - application code not present so have to be re-run
4740
RUN APP_ENV=prod composer install --no-dev -o --classmap-authoritative --no-scripts
4841

4942
# Copy application source (needed for build step)
50-
COPY --chown=deploy:deploy --from=repository-root ./ ${APP_API_PATH}/
43+
COPY ./ ${APP_API_PATH}/
5144

5245
# Copy javascript build files. This ensures that vite manifest files are availiable when "composer insatll"
5346
# triggers a "cache:clear" enabling the vite bundle to generate cache configuration files
@@ -57,43 +50,41 @@ COPY --chown=deploy:deploy --from=client_app_builder ${APP_CLIENT_PATH}/public/b
5750
# Re-run composer install after application code copied to image to complete install
5851
RUN APP_ENV=prod composer install --no-dev --optimize-autoloader --classmap-authoritative
5952

53+
# Remove files we do not need to the final image
54+
RUN rm -rf \
55+
docker-compose.* \
56+
package* \
57+
phpstan.dist.neon \
58+
psalm* \
59+
playwright.* \
60+
phpunit.* \
61+
rector.php \
62+
Taskfile.yml \
63+
.markdown* \
64+
.php-cs-fixer.dist.php \
65+
.twig-cs-fixer.dist.php \
66+
.prettier \
67+
vite.config.js
6068

6169
######## PHP-FPM (API) production image ########
62-
FROM itkdev/php8.4-fpm:alpine
70+
FROM --platform=$BUILDPLATFORM itkdev/php8.4-fpm:alpine
6371
LABEL maintainer="ITK Dev <itkdev@mkb.aarhus.dk>"
6472

6573
ENV APP_CLIENT_PATH=/app \
6674
APP_API_PATH=/var/www/html \
6775
APP_ENV=prod \
6876
COMPOSER_VERSION=2 \
69-
70-
# OpCache
7177
PHP_OPCACHE_ENABLED=1 \
7278
PHP_OPCACHE_VALIDATE_TIMESTAMPS=0 \
7379
PHP_OPCACHE_MAX_ACCELERATED_FILES=20000 \
7480
PHP_OPCACHE_MEMORY_CONSUMPTION=256 \
75-
76-
# FPM pool
7781
PHP_PM_TYPE="dynamic" \
7882
PHP_PM_MAX_CHILDREN="24" \
7983
PHP_PM_MAX_REQUESTS="0" \
8084
PHP_PM_START_SERVERS="5" \
8185
PHP_PM_MIN_SPARE_SERVERS="5" \
8286
PHP_PM_MAX_SPARE_SERVERS="10"
8387

84-
USER root
85-
86-
# Add composer needed to run optimizations after config is loaded.
87-
COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer
88-
89-
# Download Prometheus php-fpm export.
90-
COPY --from=hipages/php-fpm_exporter:2.2.0 /php-fpm_exporter /usr/local/bin/php-fpm_exporter
91-
92-
COPY docker-entrypoint.sh /usr/local/bin/
93-
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
94-
95-
USER deploy
96-
9788
WORKDIR ${APP_API_PATH}
9889

9990
# Install the api application.

infrastructure/display-api-service/docker-entrypoint.sh

Lines changed: 0 additions & 23 deletions
This file was deleted.

infrastructure/nginx/Dockerfile

Lines changed: 8 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,14 @@
1-
######## Clients [Screen|Admin] build ########
2-
FROM node:24-alpine AS client_app_builder
3-
LABEL maintainer="ITK Dev <itkdev@mkb.aarhus.dk>"
4-
51
ARG APP_VERSION="develop"
6-
ARG APP_RELEASE_VERSION="develop"
7-
ARG APP_RELEASE_TIMESTAMP=0
8-
9-
ENV APP_CLIENT_PATH=/app
10-
WORKDIR ${APP_CLIENT_PATH}
11-
12-
# Copy only necessary files for npm install
13-
COPY --from=repository-root package.json package-lock.json vite.config.js ./
14-
15-
# Install dependencies
16-
RUN npm ci --no-audit --no-fund
17-
18-
# Copy source files needed for build
19-
COPY --from=repository-root assets/ ./assets/
20-
21-
# Build the application with version info
22-
RUN npm run build
23-
24-
25-
######### API backend build ########
26-
FROM itkdev/php8.4-fpm:alpine AS api_app_builder
27-
LABEL maintainer="ITK Dev <itkdev@mkb.aarhus.dk>"
28-
29-
ARG APP_VERSION="develop"
30-
ENV APP_CLIENT_PATH=/app \
31-
APP_API_PATH=/var/www/html
32-
33-
USER root
34-
35-
# Add composer in from the official composer image (also alpine).
36-
COPY --from=composer:2 /usr/bin/composer /usr/local/bin/composer
37-
38-
WORKDIR ${APP_API_PATH}
39-
40-
USER deploy
41-
42-
# Copy only composer files first for better layer caching
43-
COPY --chown=deploy:deploy --from=repository-root composer.json composer.lock symfony.lock ${APP_API_PATH}/
44-
45-
# Pre-install composer packages first (better image layer caching) - application code not present so have to be re-run
46-
RUN APP_ENV=prod composer install --no-dev -o --classmap-authoritative --no-scripts
47-
48-
# Copy application source (needed for build step)
49-
COPY --chown=deploy:deploy --from=repository-root ./ ${APP_API_PATH}/
50-
51-
# Copy javascript build files. This ensures that vite manifest files are availiable when "composer insatll"
52-
# triggers a "cache:clear" enabling the vite bundle to generate cache configuration files
53-
# @see https://symfony-vite.pentatrion.com/guide/performance.html#caching-configuration-files-%F0%9F%8F%83
54-
COPY --chown=deploy:deploy --from=client_app_builder ${APP_CLIENT_PATH}/public/build ./public/build
55-
56-
# Re-run composer install after application code copied to image to complete install
57-
RUN APP_ENV=prod composer install --no-dev --optimize-autoloader --classmap-authoritative
58-
2+
FROM --platform=$BUILDPLATFORM ghcr.io/itk-dev/display-api-service:${APP_VERSION} AS app
593

604

615
######## Nginx production image ########
62-
FROM nginxinc/nginx-unprivileged:alpine
6+
FROM --platform=$BUILDPLATFORM nginxinc/nginx-unprivileged:alpine
637
LABEL maintainer="ITK Dev <itkdev@mkb.aarhus.dk>"
648

659
ARG APP_VERSION="develop"
6610
ARG APP_RELEASE_VERSION="develop"
6711
ARG APP_RELEASE_TIMESTAMP=0
68-
ARG UID=101
69-
ARG GID=101
7012

7113
ENV APP_CLIENT_PATH=/app \
7214
APP_API_PATH=/var/www/html \
@@ -76,21 +18,20 @@ ENV APP_CLIENT_PATH=/app \
7618

7719
WORKDIR ${APP_API_PATH}
7820

21+
USER root
22+
7923
# Create directory and copy built client assets
8024
RUN mkdir -p ${APP_API_PATH}/public
81-
COPY --from=api_app_builder --chown=$UID:0 ${APP_API_PATH}/public ./public
82-
83-
# Copy configuration and entrypoint script
84-
COPY --chown=$UID:0 etc /etc/nginx
25+
COPY --from=app --chown=nginx:nginx ${APP_API_PATH}/public ./public
8526

86-
# Set proper permissions (files are already owned by $UID:0 from COPY --chown)
87-
RUN chmod -R g+w ${APP_API_PATH}
27+
# Copy configuration
28+
COPY --chown=nginx:nginx etc /etc/nginx
8829

8930
# Add health check
9031
HEALTHCHECK --interval=30s --timeout=3s --start-period=5s --retries=3 \
9132
CMD wget --no-verbose --tries=1 --spider http://localhost:${NGINX_PORT}/health || exit 1
9233

93-
USER $UID
34+
USER nginx
9435

9536
EXPOSE ${NGINX_PORT}
9637

0 commit comments

Comments
 (0)