diff options
| author | Ivan Gabaldon <igabaldon@inetol.net> | 2025-08-07 10:46:26 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-08-07 10:46:26 +0200 |
| commit | 3de7a6da2dba72057a75d54b4b9fd864dee230e9 (patch) | |
| tree | 9a3d6c5d42fb8f566be790da2b0597916c10aae0 /utils | |
| parent | 94256e3383211944d76b52779a950d3365d05647 (diff) | |
[enh] container: tidy builds (#5086)
Building the container currently does not work properly.
When rebuilding several times with `make container`, `version_frozen.py`
is recreated, which wouldn't be an issue if the file’s timestamp was constant.
Now, when creating `version_frozen.py`, it will have the same timestamp as the
commit when it was created. (`version_frozen.py` is moved to a dedicated layer).
Reusing "builder" cache when building "dist" could be slow
(CD reports 2 seconds, but locally I've seen it take up to 10 seconds),
so the Dockerfile is now split and we save a couple steps
by importing the "builder" image directly.
The last changes made it possible to remove the layer cache in "builder",
since the overhead is now greater than building the layers from scratch.
Until now, all "dist" layers were squashed into a single layer,
which in most cases is a good idea
(except for storage/delivery pricing/overhead), but in our case,
since we manage the entire pipeline, we can ignore this
and share layers between builds.
This means (for example) that if we change files unrelated to the container
in several consecutive commits (documentation changes), we don't have to push
the entire image to registry, but only the different layers
(`version_frozen.py` in this example).
The same applies when pulling, as only the layers that have changed
compared to the local layers will be downloaded (that's the theory,
we'll see if this works as expected or if we need to tweak something else).
Diffstat (limited to 'utils')
| -rw-r--r-- | utils/lib_sxng_container.sh | 38 |
1 files changed, 12 insertions, 26 deletions
diff --git a/utils/lib_sxng_container.sh b/utils/lib_sxng_container.sh index 072ca8f9b..65b2c4b9b 100644 --- a/utils/lib_sxng_container.sh +++ b/utils/lib_sxng_container.sh @@ -14,7 +14,6 @@ CONTAINER_IMAGE_NAME="searxng" container.build() { local parch=${OVERRIDE_ARCH:-$(uname -m)} local container_engine - local dockerfile local arch local variant local platform @@ -42,19 +41,16 @@ container.build() { # Setup arch specific case $parch in "X64" | "x86_64" | "amd64") - dockerfile="Dockerfile" arch="amd64" variant="" platform="linux/$arch" ;; "ARM64" | "aarch64" | "arm64") - dockerfile="Dockerfile" arch="arm64" variant="" platform="linux/$arch" ;; "ARMV7" | "armhf" | "armv7l" | "armv7") - dockerfile="Dockerfile" arch="arm" variant="v7" platform="linux/$arch/$variant" @@ -86,27 +82,20 @@ container.build() { python -m searx.version freeze eval "$(python -m searx.version)" - info_msg "Set \$VERSION_STRING: $VERSION_STRING" - info_msg "Set \$VERSION_TAG: $VERSION_TAG" info_msg "Set \$DOCKER_TAG: $DOCKER_TAG" info_msg "Set \$GIT_URL: $GIT_URL" - info_msg "Set \$GIT_BRANCH: $GIT_BRANCH" if [ "$container_engine" = "podman" ]; then - params_build_builder="build --format=oci --platform=$platform --target=builder --layers --identity-label=false" - params_build="build --format=oci --platform=$platform --layers --squash-all --omit-history --identity-label=false" + params_build_builder="build --format=oci --platform=$platform --layers --identity-label=false" + params_build=$params_build_builder else - params_build_builder="build --platform=$platform --target=builder" - params_build="build --platform=$platform --squash" + params_build_builder="build --platform=$platform" + params_build=$params_build_builder fi if [ "$GITHUB_ACTIONS" = "true" ]; then - params_build_builder+=" --cache-from=ghcr.io/$CONTAINER_IMAGE_ORGANIZATION/cache --cache-to=ghcr.io/$CONTAINER_IMAGE_ORGANIZATION/cache" - - # Tags params_build+=" --tag=ghcr.io/$CONTAINER_IMAGE_ORGANIZATION/cache:$CONTAINER_IMAGE_NAME-$arch$variant" else - # Tags params_build+=" --tag=localhost/$CONTAINER_IMAGE_ORGANIZATION/$CONTAINER_IMAGE_NAME:latest" params_build+=" --tag=localhost/$CONTAINER_IMAGE_ORGANIZATION/$CONTAINER_IMAGE_NAME:$DOCKER_TAG" fi @@ -115,19 +104,19 @@ container.build() { "$container_engine" $params_build_builder \ --build-arg="TIMESTAMP_SETTINGS=$(git log -1 --format="%cd" --date=unix -- ./searx/settings.yml)" \ --tag="localhost/$CONTAINER_IMAGE_ORGANIZATION/$CONTAINER_IMAGE_NAME:builder" \ - --file="./container/$dockerfile" \ + --file="./container/builder.dockerfile" \ . build_msg CONTAINER "Image \"builder\" built" # shellcheck disable=SC2086 "$container_engine" $params_build \ - --build-arg="TIMESTAMP_SETTINGS=$(git log -1 --format="%cd" --date=unix -- ./searx/settings.yml)" \ - --build-arg="GIT_URL=$GIT_URL" \ - --build-arg="SEARXNG_GIT_VERSION=$VERSION_STRING" \ - --build-arg="LABEL_DATE=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ - --build-arg="LABEL_VCS_REF=$(git rev-parse HEAD)" \ - --build-arg="LABEL_VCS_URL=$GIT_URL" \ - --file="./container/$dockerfile" \ + --build-arg="CONTAINER_IMAGE_ORGANIZATION=$CONTAINER_IMAGE_ORGANIZATION" \ + --build-arg="CONTAINER_IMAGE_NAME=$CONTAINER_IMAGE_NAME" \ + --build-arg="CREATED=$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ + --build-arg="VERSION=$DOCKER_TAG" \ + --build-arg="VCS_URL=$GIT_URL" \ + --build-arg="VCS_REVISION=$(git rev-parse HEAD)" \ + --file="./container/dist.dockerfile" \ . build_msg CONTAINER "Image built" @@ -136,11 +125,8 @@ container.build() { # Output to GHA cat <<EOF >>"$GITHUB_OUTPUT" -version_string=$VERSION_STRING -version_tag=$VERSION_TAG docker_tag=$DOCKER_TAG git_url=$GIT_URL -git_branch=$GIT_BRANCH EOF fi ) |