Skip to content

Commit 1596ff6

Browse files
committed
Add support to build arm64 image
Stolen from sameersbn#2732 Signed-off-by: Hermann Mayer <[email protected]>
1 parent cfad6e9 commit 1596ff6

File tree

2 files changed

+56
-6
lines changed

2 files changed

+56
-6
lines changed

assets/build/install.sh

+23-6
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,27 @@ RUBY_SRC_URL=https://cache.ruby-lang.org/pub/ruby/${RUBY_VERSION%.*}/ruby-${RUBY
1414

1515
GEM_CACHE_DIR="${GITLAB_BUILD_DIR}/cache"
1616

17+
# check system platform
18+
# TODO: cover as many variations as possible (depending on the platform supported by golang)
19+
case "$(uname -m)" in
20+
"x86_64")
21+
PLATFORM_NAME="amd64"
22+
;;
23+
"aarch64")
24+
PLATFORM_NAME="arm64"
25+
;;
26+
*)
27+
echo "The platform not supported ($(uname -a))"
28+
exit 1
29+
esac
30+
31+
GOLANG_ARCHIVE="go${GOLANG_VERSION}.linux-${PLATFORM_NAME}.tar.gz"
32+
1733
GOROOT=/tmp/go
1834
PATH=${GOROOT}/bin:$PATH
1935

2036
export GOROOT PATH
37+
export GOPROXY="https://proxy.golang.org"
2138

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

99116
# download golang
100-
echo "Downloading Go ${GOLANG_VERSION}..."
101-
wget -cnv https://storage.googleapis.com/golang/go${GOLANG_VERSION}.linux-amd64.tar.gz -P ${GITLAB_BUILD_DIR}/
102-
tar -xf ${GITLAB_BUILD_DIR}/go${GOLANG_VERSION}.linux-amd64.tar.gz -C /tmp/
117+
echo "Downloading Go ${GOLANG_VERSION} for ${PLATFORM_NAME}..."
118+
wget -cnv https://storage.googleapis.com/golang/${GOLANG_ARCHIVE} -P ${GITLAB_BUILD_DIR}/
119+
tar -xf ${GITLAB_BUILD_DIR}/${GOLANG_ARCHIVE} -C /tmp/
103120

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

165182
# remove go
166183
go clean --modcache
167-
rm -rf ${GITLAB_BUILD_DIR}/go${GOLANG_VERSION}.linux-amd64.tar.gz ${GOROOT}
184+
rm -rf ${GITLAB_BUILD_DIR:?}/${GOLANG_ARCHIVE} ${GOROOT}
168185

169186
# remove HSTS config from the default headers, we configure it in nginx
170187
exec_as_git sed -i "/headers\['Strict-Transport-Security'\]/d" ${GITLAB_INSTALL_DIR}/app/controllers/application_controller.rb
@@ -205,7 +222,7 @@ chown ${GITLAB_USER}: ${GITLAB_INSTALL_DIR}/config/database.yml
205222
exec_as_git yarn install --production --pure-lockfile
206223

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

210227
# remove auto generated ${GITLAB_DATA_DIR}/config/secrets.yml
211228
rm -rf ${GITLAB_DATA_DIR}/config/secrets.yml

custom-build.sh

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Takes ages on a beefy Xeon workstation (5h+ due to arm64 emulation via qemu)
6+
# docker buildx create --name multi-platform-builder --use --bootstrap || true
7+
# time docker buildx build \
8+
# --push --platform linux/amd64,linux/arm64 \
9+
# -t jack12816/private:gitlab-16.1.2 .
10+
11+
# Sync repo to AWS EC2
12+
rsync -avz app [email protected]:/tmp/
13+
14+
# Install Docker on Ubuntu
15+
sudo su
16+
apt-get update
17+
apt-get install -y ca-certificates curl gnupg
18+
install -m 0755 -d /etc/apt/keyrings
19+
curl -fsSL https://download.docker.com/linux/ubuntu/gpg \
20+
| gpg --dearmor -o /etc/apt/keyrings/docker.gpg
21+
chmod a+r /etc/apt/keyrings/docker.gpg
22+
echo \
23+
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
24+
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" \
25+
| tee /etc/apt/sources.list.d/docker.list > /dev/null
26+
apt-get update
27+
apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
28+
docker login
29+
cd /tmp/app
30+
31+
# Run on a AWS/EC2/t4g.2xlarge 8vCPU/32GB memory (0.2944 USD per Hour)
32+
# for ~45 min (with manual Docker installation on Ubuntu)
33+
time docker buildx build --push -t jack12816/private:gitlab-16.2.3 .

0 commit comments

Comments
 (0)