B
B
bengur22021-09-30 16:30:58
GitLab
bengur2, 2021-09-30 16:30:58

Gitlab Auto DevOps - how to run buildx (build container for arm64)?

Created a Gitlab Runner on a virtual machine (it has the "devops" tag).
I want to use Auto DevOps and build a container for arm64 at the build stage (amd64 by default).

I use this .gitlab-ci.yml :

default:
  tags:
    - devops

include:
  - template: Auto-DevOps.gitlab-ci.yml

variables:
  AUTO_DEVOPS_BUILD_IMAGE_EXTRA_ARGS: '--platform linux/amd64,linux/arm64'
  DOCKER_BUILDKIT: 1


The GitLab repository contains the actual build.sh :
https://gitlab.com/gitlab-org/cluster-integration/...
Here DOCKER_BUILDKIT is by default = 1, and setting its value does not affect anything.

I assume that at the end of the file the condition will be met:
if ; then


And we will build the container along with my $AUTO_DEVOPS_BUILD_IMAGE_EXTRA_ARGS :
docker buildx build \
    "${build_args[@]}" \
    --progress=plain \
    --push \
    . 2>&1


But for some reason we end up with this line:
echo "Attempting to pull a previously built image for use with --cache-from..."


And here there is no buildx, and I get an error:
Error response from daemon: "amd64,linux" is an invalid component of "linux/amd64,linux/arm64": platform specifier component must match "^[A-Za-z0-9_-]+$": invalid argument


y8mHnuo.png

UPD 1:
I was embarrassed that I was studying the /src/build.sh file, and /build/build.sh was executed in the code.
I printed the executable file.
cat /build/build.sh
And it turned out that some unknown build.sh is being executed, it is different from the one that I found in the GitLab repository.
Does anyone know how to find this file in the GitLab repository?
/build/build.sh

#!/bin/bash -e
# build stage script for Auto-DevOps
if ! docker info &>/dev/null; then
  if [ -z "$DOCKER_HOST" ] && [ "$KUBERNETES_PORT" ]; then
    export DOCKER_HOST='tcp://localhost:2375'
  fi
fi
if ; then
  echo "Logging in to GitLab Container Registry with CI credentials..."
  echo "$CI_REGISTRY_PASSWORD" | docker login -u "$CI_REGISTRY_USER" --password-stdin "$CI_REGISTRY"
fi
image_previous="$CI_APPLICATION_REPOSITORY:$CI_COMMIT_BEFORE_SHA"
image_tagged="$CI_APPLICATION_REPOSITORY:$CI_APPLICATION_TAG"
image_latest="$CI_APPLICATION_REPOSITORY:latest"
if ; then
  builder=${AUTO_DEVOPS_BUILD_IMAGE_CNB_BUILDER:-"heroku/buildpacks:18"}
  echo "Building Cloud Native Buildpack-based application with builder ${builder}..."
  buildpack_args=()
  if ; then
    buildpack_args=('--buildpack' "$BUILDPACK_URL")
  fi
  env_args=()
  if ; then
    mapfile -t env_arg_names < <(echo "$AUTO_DEVOPS_BUILD_IMAGE_FORWARDED_CI_VARIABLES" | tr ',' "\n")
    for env_arg_name in "${env_arg_names[@]}"; do
      env_args+=('--env' "$env_arg_name")
    done
  fi
  pack build tmp-cnb-image \
    --builder "$builder" \
    "${env_args[@]}" \
    "${buildpack_args[@]}" \
    --env HTTP_PROXY \
    --env http_proxy \
    --env HTTPS_PROXY \
    --env https_proxy \
    --env FTP_PROXY \
    --env ftp_proxy \
    --env NO_PROXY \
    --env no_proxy
  cp /build/cnb.Dockerfile Dockerfile
  docker build \
    --build-arg source_image=tmp-cnb-image \
    --tag "$image_tagged" \
    --tag "$image_latest" \
    .
  docker push "$image_tagged"
  docker push "$image_latest"
  exit 0
fi
if ; then
  echo "Building Dockerfile-based application using '${DOCKERFILE_PATH}'..."
else
  export DOCKERFILE_PATH="Dockerfile"
  if ; then
    echo "Building Dockerfile-based application..."
  else
    echo "Building Heroku-based application using gliderlabs/herokuish docker image..."
    erb -T - /build/Dockerfile.erb > "${DOCKERFILE_PATH}"
  fi
fi
if ; then
  echo "Unable to find '${DOCKERFILE_PATH}'. Exiting..." >&2
  exit 1
fi
build_secret_args=''
if ; then
  build_secret_file_path=/tmp/auto-devops-build-secrets
  "$(dirname "$0")"/export-build-secrets > "$build_secret_file_path"
  build_secret_args="--secret id=auto-devops-build-secrets,src=$build_secret_file_path"
  echo 'Activating Docker BuildKit to forward CI variables with --secret'
  export DOCKER_BUILDKIT=1
fi
echo "Attempting to pull a previously built image for use with --cache-from..."
docker image pull --quiet "$image_previous" || \
  docker image pull --quiet "$image_latest" || \
  echo "No previously cached image found. The docker build will proceed without using a cached image"
# shellcheck disable=SC2154 # missing variable warning for the lowercase variables
# shellcheck disable=SC2086 # double quoting for globbing warning for $build_secret_args and $AUTO_DEVOPS_BUILD_IMAGE_EXTRA_ARGS
docker build \
  --cache-from "$image_previous" \
  --cache-from "$image_latest" \
  $build_secret_args \
  -f "$DOCKERFILE_PATH" \
  --build-arg BUILDPACK_URL="$BUILDPACK_URL" \
  --build-arg HTTP_PROXY="$HTTP_PROXY" \
  --build-arg http_proxy="$http_proxy" \
  --build-arg HTTPS_PROXY="$HTTPS_PROXY" \
  --build-arg https_proxy="$https_proxy" \
  --build-arg FTP_PROXY="$FTP_PROXY" \
  --build-arg ftp_proxy="$ftp_proxy" \
  --build-arg NO_PROXY="$NO_PROXY" \
  --build-arg no_proxy="$no_proxy" \
  $AUTO_DEVOPS_BUILD_IMAGE_EXTRA_ARGS \
  --tag "$CI_APPLICATION_REPOSITORY:$CI_APPLICATION_TAG" \
  --tag "$image_latest" .
docker push "$image_tagged"
docker push "$image_latest"

Answer the question

In order to leave comments, you need to log in

2 answer(s)
B
bengur2, 2021-10-01
@bengur2

Build.gitlab -ci.yml doesn't use /src/build.sh
Look at /build/build.sh - it doesn't use buildx.

A
Alexander Karabanov, 2021-09-30
@karabanov

In the script, the variable DOCKER_BUILDKITis defined and the default value "1" is assigned to it:

# By default we support DOCKER_BUILDKIT, however it can be turned off
# by explicitly setting this to an empty string
DOCKER_BUILDKIT=${DOCKER_BUILDKIT:-1}

Try to remove DOCKER_BUILDKITfrom variables:in .gitlab-ci.yml

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question