Skip to content

Commit

Permalink
Add support to build arm64 image
Browse files Browse the repository at this point in the history
Stolen from sameersbn#2732

Signed-off-by: Hermann Mayer <hermann.mayer92@gmail.com>
  • Loading branch information
Jack12816 committed Aug 9, 2023
1 parent 2a7e489 commit ff22eb0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
29 changes: 23 additions & 6 deletions assets/build/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,27 @@ RUBY_SRC_URL=https://cache.ruby-lang.org/pub/ruby/${RUBY_VERSION%.*}/ruby-${RUBY

GEM_CACHE_DIR="${GITLAB_BUILD_DIR}/cache"

# check system platform
# TODO: cover as many variations as possible (depending on the platform supported by golang)
case "$(uname -m)" in
"x86_64")
PLATFORM_NAME="amd64"
;;
"aarch64")
PLATFORM_NAME="arm64"
;;
*)
echo "The platform not supported ($(uname -a))"
exit 1
esac

GOLANG_ARCHIVE="go${GOLANG_VERSION}.linux-${PLATFORM_NAME}.tar.gz"

GOROOT=/tmp/go
PATH=${GOROOT}/bin:$PATH

export GOROOT PATH
export GOPROXY="https://proxy.golang.org"

BUILD_DEPENDENCIES="gcc g++ make patch pkg-config cmake paxctl \
libc6-dev \
Expand Down Expand Up @@ -97,9 +114,9 @@ BUNDLER_VERSION="$(grep "BUNDLED WITH" ${GITLAB_INSTALL_DIR}/Gemfile.lock -A 1 |
gem install bundler:"${BUNDLER_VERSION}"

# download golang
echo "Downloading Go ${GOLANG_VERSION}..."
wget -cnv https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-amd64.tar.gz -P ${GITLAB_BUILD_DIR}/
tar -xf ${GITLAB_BUILD_DIR}/go${GOLANG_VERSION}.linux-amd64.tar.gz -C /tmp/
echo "Downloading Go ${GOLANG_VERSION} for ${PLATFORM_NAME}..."
wget -cnv https://storage.googleapis.com/golang/${GOLANG_ARCHIVE} -P ${GITLAB_BUILD_DIR}/
tar -xf ${GITLAB_BUILD_DIR}/${GOLANG_ARCHIVE} -C /tmp/

# install gitlab-shell
echo "Downloading gitlab-shell v.${GITLAB_SHELL_VERSION}..."
Expand Down Expand Up @@ -147,7 +164,7 @@ git clone -q -b v${GITALY_SERVER_VERSION} --depth 1 ${GITLAB_GITALY_URL} ${GITLA
make -C ${GITLAB_GITALY_BUILD_DIR} install
mkdir -p ${GITLAB_GITALY_INSTALL_DIR}
# The following line causes some issues. However, according to
# <https://gitlab.com/gitlab-org/gitaly/-/merge_requests/5512> and
# <https://gitlab.com/gitlab-org/gitaly/-/merge_requests/5512> and
# <https://gitlab.com/gitlab-org/gitaly/-/merge_requests/5671> there seems to
# be some attempts to remove ruby from gitaly.
#
Expand All @@ -164,7 +181,7 @@ rm -rf ${GITLAB_GITALY_BUILD_DIR}

# remove go
go clean --modcache
rm -rf ${GITLAB_BUILD_DIR}/go${GOLANG_VERSION}.linux-amd64.tar.gz ${GOROOT}
rm -rf ${GITLAB_BUILD_DIR:?}/${GOLANG_ARCHIVE} ${GOROOT}

# remove HSTS config from the default headers, we configure it in nginx
exec_as_git sed -i "/headers\['Strict-Transport-Security'\]/d" ${GITLAB_INSTALL_DIR}/app/controllers/application_controller.rb
Expand Down Expand Up @@ -206,7 +223,7 @@ exec_as_git yarn install --production --pure-lockfile
exec_as_git yarn add ajv@^4.0.0

echo "Compiling assets. Please be patient, this could take a while..."
exec_as_git bundle exec rake gitlab:assets:compile USE_DB=false SKIP_STORAGE_VALIDATION=true NODE_OPTIONS="--max-old-space-size=4096"
exec_as_git bundle exec rake gitlab:assets:compile USE_DB=false SKIP_STORAGE_VALIDATION=true NODE_OPTIONS="--max-old-space-size=8192"

# remove auto generated ${GITLAB_DATA_DIR}/config/secrets.yml
rm -rf ${GITLAB_DATA_DIR}/config/secrets.yml
Expand Down
13 changes: 13 additions & 0 deletions custom-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

set -e

# Takes ages on a beefy Xeon workstation (5h+ due to arm64 emulation via qemu)
# docker buildx create --name multi-platform-builder --use --bootstrap || true
# time docker buildx build \
# --push --platform linux/amd64,linux/arm64 \
# -t jack12816/private:gitlab-16.1.2 .

# Run on a AWS/EC2/t4g.2xlarge 8vCPU/32GB memory (0.2944 USD per Hour)
# for ~45 min (with manual Docker installation on Ubuntu)
time docker buildx build --push -t jack12816/private:gitlab-16.1.2 .

0 comments on commit ff22eb0

Please sign in to comment.