Skip to content

Commit 2a3e569

Browse files
authored
Enable Multi-Arch Building and Pushing for registry viewer (#125)
* update projects to use multi arch build Signed-off-by: Jordan Dubrick <[email protected]> * update dockerfile to customize timeout value Signed-off-by: Jordan Dubrick <[email protected]> * add new script for building/pushing multi arch registry viewer Signed-off-by: Jordan Dubrick <[email protected]> * free disk space and add qemu emulator Signed-off-by: Jordan Dubrick <[email protected]> * use new build/push script and add qemu emulator Signed-off-by: Jordan Dubrick <[email protected]> * add buildx setup to actions Signed-off-by: Jordan Dubrick <[email protected]> * pin sha for buildx setup Signed-off-by: Jordan Dubrick <[email protected]> * increase parallel to 4 Signed-off-by: Jordan Dubrick <[email protected]> * break nx command into 2 separate commands Signed-off-by: Jordan Dubrick <[email protected]> --------- Signed-off-by: Jordan Dubrick <[email protected]>
1 parent 055be42 commit 2a3e569

File tree

6 files changed

+116
-11
lines changed

6 files changed

+116
-11
lines changed

.github/workflows/ci.yaml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,23 @@ jobs:
9999
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
100100
with:
101101
fetch-depth: 0
102+
103+
- name: Free Disk Space
104+
uses: jlumbroso/free-disk-space@54081f138730dfa15788a46383842cd2f914a1be #v1.3.1
105+
with:
106+
tool-cache: false
107+
android: true
108+
dotnet: true
109+
haskell: true
110+
large-packages: true
111+
docker-images: true
112+
swap-storage: true
113+
114+
- name: Set up QEMU # Enables arm64 image building
115+
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 #v3.0.0
116+
117+
- name: Set up Docker Buildx
118+
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb #v3.3.0
102119

103120
- uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 #v4.0.0
104121
with:
@@ -111,9 +128,14 @@ jobs:
111128
run: |
112129
yarn install --frozen-lockfile
113130
114-
- name: Docker Build
131+
- name: Docker Build for linux/amd64
115132
run: |
116-
yarn nx affected --target=docker-build --parallel=3
133+
yarn nx affected --target=docker-build-amd64 --parallel=3
134+
135+
- name: Docker Build for linux/arm64
136+
run: |
137+
yarn nx affected --target=docker-build-arm64 --parallel=3
138+
117139
118140
e2e:
119141
name: E2E

.github/workflows/pushimage-next.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,18 @@ jobs:
3131
steps:
3232
- name: Check out devfile web source code
3333
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
34+
- name: Set up QEMU # Enables arm64 image building
35+
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 #v3.0.0
36+
- name: Set up Docker Buildx
37+
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb #v3.3.0
3438
- name: Login to Quay
3539
uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc # v2.2.0
3640
with:
3741
registry: quay.io
3842
username: ${{ secrets.QUAY_USERNAME }}
3943
password: ${{ secrets.QUAY_PASSWORD }}
40-
- name: Build the registry viewer image
41-
run: bash ./scripts/build_viewer.sh
42-
- name: Push the registry viewer image
43-
run: bash ./scripts/push.sh registry-viewer:latest quay.io/devfile/registry-viewer:next
44+
- name: Build and push the registry viewer image
45+
run: bash ./scripts/build_multi_arch.sh
4446
dispatch:
4547
needs: registry-viewer-build
4648
strategy:

Dockerfile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ ARG NEXT_PUBLIC_DOCSEARCH_APP_ID
3333
ARG NEXT_PUBLIC_DOCSEARCH_API_KEY
3434
ARG NEXT_PUBLIC_DOCSEARCH_INDEX_NAME
3535

36+
# Building different architectures via emulation is slow with Yarn
37+
# This increases the timeout period so it can properly download dependencies
38+
# Value is in milliseconds and is set to 60 minutes
39+
# To increase/decrease you can override via --build-arg YARN_TIMEOUT=x in your build command
40+
ARG YARN_TIMEOUT=3600000
41+
3642
# Check if the PROJECT_NAME build argument is set
3743
RUN \
3844
if [ "$PROJECT_NAME" == "landing-page" ] || [ "$PROJECT_NAME" == "registry-viewer" ]; then echo "Building project \"${PROJECT_NAME}\"."; \
@@ -43,7 +49,7 @@ WORKDIR /app
4349
# Install dependencies
4450
COPY package.json yarn.lock* ./
4551
RUN \
46-
if [ -f yarn.lock ]; then yarn --frozen-lockfile; \
52+
if [ -f yarn.lock ]; then yarn --frozen-lockfile --network-timeout $YARN_TIMEOUT; \
4753
else echo "Lockfile not found." && exit 1; \
4854
fi
4955

apps/landing-page/project.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,18 @@
5959
"command": "cd ./apps/landing-page/ && next-sitemap --config ./next-sitemap.config.mjs && cp -a ./dist/public/. ./dist/exported"
6060
}
6161
},
62-
"docker-build": {
62+
"docker-build-amd64": {
6363
"executor": "nx:run-commands",
64+
"description": "Build docker image for the linux/amd64 architecture",
6465
"options": {
65-
"command": "docker build -t nextjs-docker . --build-arg PROJECT_NAME=landing-page"
66+
"command": "docker build --platform=linux/amd64 -t nextjs-docker-amd64 . --build-arg PROJECT_NAME=landing-page"
67+
}
68+
},
69+
"docker-build-arm64": {
70+
"executor": "nx:run-commands",
71+
"description": "Build docker image for the linux/arm64 architecture",
72+
"options": {
73+
"command": "docker build --platform=linux/arm64 -t nextjs-docker-arm64 . --build-arg PROJECT_NAME=landing-page"
6674
}
6775
},
6876
"test": {

apps/registry-viewer/project.json

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,18 @@
5858
"command": "cd ./apps/registry-viewer/ && next-sitemap --config ./next-sitemap.config.mjs && cp -a ./dist/public/. ./dist/exported"
5959
}
6060
},
61-
"docker-build": {
61+
"docker-build-amd64": {
6262
"executor": "nx:run-commands",
63+
"description": "Build docker image for the linux/amd64 architecture",
6364
"options": {
64-
"command": "docker build -t nextjs-docker . --build-arg PROJECT_NAME=registry-viewer"
65+
"command": "docker build --platform=linux/amd64 -t nextjs-docker-amd64 . --build-arg PROJECT_NAME=registry-viewer"
66+
}
67+
},
68+
"docker-build-arm64": {
69+
"executor": "nx:run-commands",
70+
"description": "Build docker image for the linux/arm64 architecture",
71+
"options": {
72+
"command": "docker build --platform=linux/arm64 -t nextjs-docker-arm64 . --build-arg PROJECT_NAME=registry-viewer"
6573
}
6674
},
6775
"test": {

scripts/build_multi_arch.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/sh
2+
3+
#
4+
# Copyright Red Hat
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
18+
ABSOLUTE_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
19+
BUILD_DIR=$ABSOLUTE_PATH/..
20+
# Due to command differences between podman and docker we need to separate the process
21+
# for creating and adding images to a multi-arch manifest
22+
podman=${USE_PODMAN:-false}
23+
# Base Repository
24+
BASE_REPO="quay.io/devfile/registry-viewer"
25+
BASE_TAG="next"
26+
DEFAULT_IMG="$BASE_REPO:$BASE_TAG"
27+
# Platforms to build for
28+
PLATFORMS="linux/amd64,linux/arm64"
29+
30+
if [ ${podman} == true ]; then
31+
echo "Executing with podman"
32+
33+
podman manifest create "$DEFAULT_IMG"
34+
35+
podman build --platform="$PLATFORMS" --manifest "$DEFAULT_IMG" "$BUILD_DIR" \
36+
--no-cache \
37+
--build-arg PROJECT_NAME=registry-viewer \
38+
--build-arg NEXT_PUBLIC_BASE_PATH=${NEXT_PUBLIC_BASE_PATH:-"/viewer"}
39+
40+
podman manifest push "$DEFAULT_IMG"
41+
42+
podman manifest rm "$DEFAULT_IMG"
43+
44+
else
45+
echo "Executing with docker"
46+
47+
docker buildx create --name registry-viewer-builder
48+
49+
docker buildx use registry-viewer-builder
50+
51+
docker buildx build --push --platform="$PLATFORMS" --tag "$DEFAULT_IMG" "$BUILD_DIR" \
52+
--no-cache \
53+
--provenance=false \
54+
--build-arg PROJECT_NAME=registry-viewer \
55+
--build-arg NEXT_PUBLIC_BASE_PATH=${NEXT_PUBLIC_BASE_PATH:-"/viewer"}
56+
57+
docker buildx rm registry-viewer-builder
58+
59+
fi

0 commit comments

Comments
 (0)