Skip to content

Commit

Permalink
Fix Docker build caching issues.
Browse files Browse the repository at this point in the history
  • Loading branch information
aronmolnar committed Sep 4, 2024
1 parent 48580e8 commit 94d88c1
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 27 deletions.
36 changes: 11 additions & 25 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,32 +181,18 @@ build-release:
if [[ $CI_COMMIT_TAG =~ '^prod-.*' ]]; then
grep -qE "^## (v${VERSION_NUMBER})" CHANGELOG.md || exit 1
TEST_CI_COMMIT_TAG=test-$VERSION_NUMBER_LEADING_ZEROS
cd languagetool
docker buildx imagetools create $CI_REGISTRY_IMAGE/languagetool:$TEST_CI_COMMIT_TAG --tag $CI_REGISTRY_IMAGE/languagetool:$CI_COMMIT_TAG
cd ..
# Build api image
docker buildx build --provenance false --build-arg VERSION="$VERSION_NUMBER" --build-arg TESTED_API_IMAGE="$CI_REGISTRY_IMAGE:$TEST_CI_COMMIT_TAG" --platform linux/amd64,linux/arm64 --push --target=api-prod -t $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG .
else
TEST_CI_COMMIT_TAG=$CI_COMMIT_TAG
# Build/push depending stages
# rendering
docker buildx imagetools create $CI_REGISTRY_IMAGE/rendering:$ISO_WEEK --tag $CI_REGISTRY_IMAGE/rendering:$TEST_CI_COMMIT_TAG
# pdfviewer
docker buildx imagetools create $CI_REGISTRY_IMAGE/pdfviewer:$ISO_WEEK --tag $CI_REGISTRY_IMAGE/pdfviewer:$TEST_CI_COMMIT_TAG
# frontend
if ! docker manifest inspect $CI_REGISTRY_IMAGE/frontend:$TEST_CI_COMMIT_TAG > /dev/null; then
docker buildx build --provenance false --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from $CI_REGISTRY_IMAGE/frontend-test:$CI_COMMIT_SHORT_SHA --cache-from $CI_REGISTRY_IMAGE/pdfviewer:$TEST_CI_COMMIT_TAG --target=frontend --platform linux/amd64,linux/arm64 --push -t $CI_REGISTRY_IMAGE/frontend:$TEST_CI_COMMIT_TAG .
fi
# api-statics
if ! docker manifest inspect $CI_REGISTRY_IMAGE/api-statics:$TEST_CI_COMMIT_TAG > /dev/null; then
docker buildx build --provenance false --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from $CI_REGISTRY_IMAGE/frontend:$TEST_CI_COMMIT_TAG --cache-from $CI_REGISTRY_IMAGE/pdfviewer:$TEST_CI_COMMIT_TAG --cache-from $CI_REGISTRY_IMAGE/api-test:$CI_COMMIT_SHORT_SHA --cache-from $CI_REGISTRY_IMAGE/rendering:$TEST_CI_COMMIT_TAG --target=api-statics --platform linux/amd64,linux/arm64 --push -t $CI_REGISTRY_IMAGE/api-statics:$TEST_CI_COMMIT_TAG .
fi
fi
# Build containers
- cd languagetool
- docker buildx build --provenance false --build-arg BUILDKIT_INLINE_CACHE=1 --cache-from $CI_REGISTRY_IMAGE/languagetool:$TEST_CI_COMMIT_TAG --platform linux/amd64,linux/arm64 --push -t $CI_REGISTRY_IMAGE/languagetool:$CI_COMMIT_TAG .
- cd ..
- export VERSION_NUMBER
- |
if ! docker manifest inspect $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG > /dev/null; then
docker buildx build --provenance false --build-arg BUILDKIT_INLINE_CACHE=1 --build-arg VERSION="$VERSION_NUMBER" --cache-from $CI_REGISTRY_IMAGE/api-test:$CI_COMMIT_SHORT_SHA --cache-from $CI_REGISTRY_IMAGE/api-statics:$TEST_CI_COMMIT_TAG --cache-from $CI_REGISTRY_IMAGE/frontend:$TEST_CI_COMMIT_TAG --cache-from $CI_REGISTRY_IMAGE/pdfviewer:$TEST_CI_COMMIT_TAG --cache-from $CI_REGISTRY_IMAGE/rendering:$TEST_CI_COMMIT_TAG --target=api --platform linux/amd64,linux/arm64 --push --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG .
cd languagetool
docker buildx build --provenance false --platform linux/amd64,linux/arm64 --push -t $CI_REGISTRY_IMAGE/languagetool:$CI_COMMIT_TAG .
cd ..
docker buildx build --provenance false $BASE_IMAGE_BUILD_ARG --build-arg BUILDKIT_INLINE_CACHE=1 --build-arg VERSION="$VERSION_NUMBER" --cache-from $CI_REGISTRY_IMAGE/api-test:$CI_COMMIT_SHORT_SHA --cache-from $CI_REGISTRY_IMAGE/frontend-test:$CI_COMMIT_SHORT_SHA --target=api --platform linux/amd64,linux/arm64 --push --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG .
fi
release-gitlab-release:
stage: release
Expand Down Expand Up @@ -246,7 +232,7 @@ release-prod:
- rm -rf docs/docs/s docs/README.md docs/reporting_software.yml docs/wip docs/hooks.py dev .vscode api/.vscode

# Build container with copyleft source code
- docker buildx build --provenance false --build-arg BUILDKIT_INLINE_CACHE=1 --build-arg VERSION="$VERSION_NUMBER" --cache-from $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG --cache-from $CI_REGISTRY_IMAGE/api-statics:$TEST_CI_COMMIT_TAG --cache-from $CI_REGISTRY_IMAGE/frontend:$TEST_CI_COMMIT_TAG --cache-from $CI_REGISTRY_IMAGE/pdfviewer:$TEST_CI_COMMIT_TAG --cache-from $CI_REGISTRY_IMAGE/rendering:$TEST_CI_COMMIT_TAG --target=api-src --platform linux/amd64,linux/arm64 --push --tag $DOCKER_HUB_IMAGE:$VERSION_NUMBER-src .
- docker buildx build --provenance false --build-arg PROD_API_IMAGE=$CI_REGISTRY_IMAGE:$CI_COMMIT_TAG --target=api-src --platform linux/amd64,linux/arm64 --push --tag $DOCKER_HUB_IMAGE:$VERSION_NUMBER-src .
# Push containers to Docker Hub
- docker buildx imagetools create $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG --tag $DOCKER_HUB_IMAGE:$VERSION_NUMBER
- docker buildx imagetools create $DOCKER_HUB_IMAGE:$VERSION_NUMBER --tag $DOCKER_HUB_IMAGE:latest
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## Upcoming
* Set custom database credentials in languagetool container
* Fix bug when using custom CA

## v2024.69 - 2024-08-30
* Fix install and update procedures
* Fix error importing designs without ordering fields
Expand Down
11 changes: 9 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Globally defined ARGS
ARG TESTED_API_IMAGE=undefined_test_image
ARG PROD_API_IMAGE=undefined_prod_image

FROM --platform=$BUILDPLATFORM node:20-alpine3.19 AS pdfviewer-dev

# Install dependencies
Expand Down Expand Up @@ -191,10 +195,13 @@ ARG VERSION=dev
ENV VERSION=${VERSION}
USER 1000

FROM $TESTED_API_IMAGE AS api-prod
ARG VERSION
ENV VERSION=${VERSION}
COPY CHANGELOG.md /app/



FROM api AS api-src
FROM ${PROD_API_IMAGE} AS api-src
USER 0
RUN dpkg-query -W -f='${binary:Package}=${Version}\n' > /src/post_installed.txt \
&& bash /app/api/download_sources.sh
Expand Down

0 comments on commit 94d88c1

Please sign in to comment.