From 94d88c1970115718171e1adc0110e16594da52ae Mon Sep 17 00:00:00 2001 From: aron Date: Wed, 4 Sep 2024 09:12:29 +0000 Subject: [PATCH] Fix Docker build caching issues. --- .gitlab-ci.yml | 36 +++++++++++------------------------- CHANGELOG.md | 4 ++++ Dockerfile | 11 +++++++++-- 3 files changed, 24 insertions(+), 27 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 39cd053c2..85e57ce6a 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -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 @@ -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 diff --git a/CHANGELOG.md b/CHANGELOG.md index b3a2222e9..fc5d26d6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/Dockerfile b/Dockerfile index e98a4fa4d..77e346045 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 @@ -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