From ca02e0c220f009a7b0758bb32ff43d20b448d52f Mon Sep 17 00:00:00 2001 From: Balasankar 'Balu' C Date: Wed, 20 Mar 2024 15:09:24 +0530 Subject: [PATCH] Enable building arm64 images Modify the Dockerfile and library code around Docker image builds to support building multiarch images. The Dockerfile will download the package for the correct architecture based on TARGETARCH variable. Closes: https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/8470 Signed-off-by: Balasankar 'Balu' C --- docker/Dockerfile | 5 +++++ docker/assets/setup | 10 ++++++++++ gitlab-ci-config/dev-gitlab-org.yml | 2 ++ lib/gitlab/build/info/docker.rb | 10 +++++++--- spec/lib/gitlab/build/image_spec.rb | 12 ++++++++---- 5 files changed, 32 insertions(+), 7 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index e0f31b2d8..9f8c77ca7 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -10,6 +10,8 @@ ENV LANG=C.UTF-8 COPY locale.gen /etc/locale.gen # Install required packages +# Note: libatomic1 is only required for arm64, but it is small enough to not +# bother about the conditional inclusion logic RUN apt-get update -q \ && DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \ busybox \ @@ -20,6 +22,7 @@ RUN apt-get update -q \ wget \ perl \ libperl5.34 \ + libatomic1 \ && locale-gen \ && cp -a /usr/lib/locale/locale-archive /tmp/locale-archive \ && DEBIAN_FRONTEND=noninteractive apt-get purge -yq locales \ @@ -43,6 +46,8 @@ RUN ln -fs /dev/null /run/motd.dynamic # Legacy code to be removed on 17.0. See: https://gitlab.com/gitlab-org/omnibus-gitlab/-/merge_requests/7035 ENV GITLAB_ALLOW_SHA1_RSA=false +ARG TARGETARCH + # Copy assets COPY RELEASE / COPY assets/ /assets/ diff --git a/docker/assets/setup b/docker/assets/setup index 5e0c77b9b..2d0f2c6ff 100755 --- a/docker/assets/setup +++ b/docker/assets/setup @@ -10,9 +10,19 @@ source /RELEASE sed -i "/DOWNLOAD_URL/d;/CI_JOB_TOKEN/d;" /RELEASE # Install GitLab +if [[ "${TARGETARCH}" == "amd64" ]]; then + export DOWNLOAD_URL=${DOWNLOAD_URL_amd64} +elif [[ "${TARGETARCH}" == "arm64" ]]; then + export DOWNLOAD_URL=${DOWNLOAD_URL_arm64} +else + echo "Unknown TARGETARCH: DOWNLOAD_URL not set" +fi + DOWNLOAD_URL=${DOWNLOAD_URL} CI_JOB_TOKEN=${CI_JOB_TOKEN} /assets/download-package && dpkg -i /tmp/gitlab.deb rm -rf /tmp/gitlab.deb /var/lib/apt/lists/* +unset DOWNLOAD_URL_amd64 +unset DOWNLOAD_URL_arm64 unset DOWNLOAD_URL unset CI_JOB_TOKEN diff --git a/gitlab-ci-config/dev-gitlab-org.yml b/gitlab-ci-config/dev-gitlab-org.yml index 7958917ce..0acde9984 100644 --- a/gitlab-ci-config/dev-gitlab-org.yml +++ b/gitlab-ci-config/dev-gitlab-org.yml @@ -315,6 +315,8 @@ Ubuntu-22.04-arm64-branch: - !reference [.default_rules, rules] - if: '$PIPELINE_TYPE =~ /_(NIGHTLY|BRANCH)_BUILD_PIPELINE$/' - if: '$PIPELINE_TYPE =~ /TRIGGERED_(CE|EE)_PIPELINE/' + # TODO: When multi-arch images are built by default, make this an + # automatic job when: manual allow_failure: true CentOS-7-branch: diff --git a/lib/gitlab/build/info/docker.rb b/lib/gitlab/build/info/docker.rb index 06be3ea0a..45b536a7f 100644 --- a/lib/gitlab/build/info/docker.rb +++ b/lib/gitlab/build/info/docker.rb @@ -13,15 +13,19 @@ module Build def release_file_contents repo = Gitlab::Util.get_env('PACKAGECLOUD_REPO') # Target repository + download_urls = {}.tap do |urls| + urls[:amd64] = Build::Info::CI.package_download_url + urls[:arm64] = Build::Info::CI.package_download_url(arch: 'arm64') + end - download_url = Build::Info::CI.package_download_url - raise "Unable to identify package download URL." unless download_url + raise "Unable to identify package download URLs." if download_urls.empty? contents = [] contents << "PACKAGECLOUD_REPO=#{repo.chomp}\n" if repo && !repo.empty? contents << "RELEASE_PACKAGE=#{Build::Info::Package.name}\n" contents << "RELEASE_VERSION=#{Build::Info::Package.release_version}\n" - contents << "DOWNLOAD_URL=#{download_url}\n" + contents << "DOWNLOAD_URL_amd64=#{download_urls[:amd64]}\n" + contents << "DOWNLOAD_URL_arm64=#{download_urls[:arm64]}\n" contents << "CI_JOB_TOKEN=#{Build::Info::CI.job_token}\n" contents.join end diff --git a/spec/lib/gitlab/build/image_spec.rb b/spec/lib/gitlab/build/image_spec.rb index ad048a2c3..b3d9c8c2c 100644 --- a/spec/lib/gitlab/build/image_spec.rb +++ b/spec/lib/gitlab/build/image_spec.rb @@ -109,7 +109,8 @@ RSpec.describe Build::Image do "PACKAGECLOUD_REPO=download-package", "RELEASE_PACKAGE=gitlab-ce", "RELEASE_VERSION=12.121.12-ce.0", - "DOWNLOAD_URL=https://dev.gitlab.org/api/v4/projects/283/jobs/999999/artifacts/pkg/ubuntu-jammy/gitlab-ce_12.121.12-ce.0_amd64.deb", + "DOWNLOAD_URL_amd64=https://dev.gitlab.org/api/v4/projects/283/jobs/999999/artifacts/pkg/ubuntu-jammy/gitlab-ce_12.121.12-ce.0_amd64.deb", + "DOWNLOAD_URL_arm64=https://dev.gitlab.org/api/v4/projects/283/jobs/999999/artifacts/pkg/ubuntu-jammy_aarch64/gitlab-ce_12.121.12-ce.0_arm64.deb", "CI_JOB_TOKEN=NOT-CI-JOB-TOKEN\n" ].join("\n") end @@ -130,7 +131,8 @@ RSpec.describe Build::Image do "PACKAGECLOUD_REPO=download-package", "RELEASE_PACKAGE=gitlab-ee", "RELEASE_VERSION=12.121.12-ee.0", - "DOWNLOAD_URL=https://dev.gitlab.org/api/v4/projects/283/jobs/999999/artifacts/pkg/ubuntu-jammy/gitlab-ee_12.121.12-ee.0_amd64.deb", + "DOWNLOAD_URL_amd64=https://dev.gitlab.org/api/v4/projects/283/jobs/999999/artifacts/pkg/ubuntu-jammy/gitlab-ee_12.121.12-ee.0_amd64.deb", + "DOWNLOAD_URL_arm64=https://dev.gitlab.org/api/v4/projects/283/jobs/999999/artifacts/pkg/ubuntu-jammy_aarch64/gitlab-ee_12.121.12-ee.0_arm64.deb", "CI_JOB_TOKEN=NOT-CI-JOB-TOKEN\n" ].join("\n") end @@ -159,7 +161,8 @@ RSpec.describe Build::Image do "PACKAGECLOUD_REPO=download-package", "RELEASE_PACKAGE=gitlab-ce", "RELEASE_VERSION=12.121.12-ce.0", - "DOWNLOAD_URL=https://gitlab.com/api/v4/projects/20699/jobs/999999/artifacts/pkg/ubuntu-jammy/gitlab-ce_12.121.12-ce.0_amd64.deb", + "DOWNLOAD_URL_amd64=https://gitlab.com/api/v4/projects/20699/jobs/999999/artifacts/pkg/ubuntu-jammy/gitlab-ce_12.121.12-ce.0_amd64.deb", + "DOWNLOAD_URL_arm64=https://gitlab.com/api/v4/projects/20699/jobs/999999/artifacts/pkg/ubuntu-jammy_aarch64/gitlab-ce_12.121.12-ce.0_arm64.deb", "CI_JOB_TOKEN=NOT-CI-JOB-TOKEN\n" ].join("\n") end @@ -180,7 +183,8 @@ RSpec.describe Build::Image do "PACKAGECLOUD_REPO=download-package", "RELEASE_PACKAGE=gitlab-ee", "RELEASE_VERSION=12.121.12-ee.0", - "DOWNLOAD_URL=https://gitlab.com/api/v4/projects/20699/jobs/999999/artifacts/pkg/ubuntu-jammy/gitlab-ee_12.121.12-ee.0_amd64.deb", + "DOWNLOAD_URL_amd64=https://gitlab.com/api/v4/projects/20699/jobs/999999/artifacts/pkg/ubuntu-jammy/gitlab-ee_12.121.12-ee.0_amd64.deb", + "DOWNLOAD_URL_arm64=https://gitlab.com/api/v4/projects/20699/jobs/999999/artifacts/pkg/ubuntu-jammy_aarch64/gitlab-ee_12.121.12-ee.0_arm64.deb", "CI_JOB_TOKEN=NOT-CI-JOB-TOKEN\n" ].join("\n") end