Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multi-Arch Support for oci-registry builds and CI #240

Merged
merged 12 commits into from
May 21, 2024
5 changes: 4 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ jobs:
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0
with:
go-version: ${{ env.GO_VERSION }}

- name: Set up QEMU # Enables arm64 image building
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 #v3.0.0

- name: Check license
run: |
Expand All @@ -113,7 +116,7 @@ jobs:
run: cd index/server && go test ./... -coverprofile cover.out

- name: Check if oci server build is working
run: cd oci-registry && bash ./build.sh
run: cd oci-registry && bash ./build.sh && bash ./build.sh linux/arm64

- name: Check if devfile-registry-integration build is working
run: cd tests/integration && bash ./docker-build.sh
Expand Down
15 changes: 7 additions & 8 deletions .github/workflows/pushimage-next.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,16 @@
steps:
- name: Check out registry support source code
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3
- name: Build and push oci-registry docker image
uses: docker/[email protected]
- name: Set up QEMU # Enables arm64 image building
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3 #v3.0.0
- name: Login to Quay.io
uses: docker/login-action@v3
github-advanced-security[bot] marked this conversation as resolved.
Fixed
Show resolved Hide resolved
with:
path: ./oci-registry
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
registry: quay.io
repository: devfile/oci-registry
dockerfile: ./oci-registry/Dockerfile
tags: next
tag_with_sha: true
- name: Build and push oci-registry docker image
run: bash ./oci-registry/build-multi-arch.sh

devfileRegistryIntegrationBuild:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion oci-registry/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ This folder contains the Dockerfile for the OCI registry server. It is based off
## Build
The scripts in this project support both `Docker` and `Podman` container engines. By default the scripts will run using `Docker`, to use `Podman` first run `export USE_PODMAN=true`.

To build the image, run `bash build.sh`.
The build script enables users to build for different architectures, by default running `bash build.sh` will build for `linux/amd64`. If you would like to build for a different architecture simply add it as an argument to the script. E.g. `bash build.sh linux/arm64` for `linux/arm64` builds.

To push the image to a repository of your choice, you can run `bash push.sh <repository-tag>`.

Expand Down
80 changes: 80 additions & 0 deletions oci-registry/build-multi-arch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/sh

#
# Copyright Red Hat
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

buildfolder="$(basename "$(dirname "$0")")"
# Due to command differences between podman and docker we need to separate the process
# for creating and adding images to a multi-arch manifest
podman=${USE_PODMAN:-false}
# Stores all created image tags
images=()
# Base Repository
BASE_REPO="quay.io/devfile/oci-registry"
BASE_TAG="next"

function build {
IMAGE="$BASE_REPO:$2"

echo "Building: ${IMAGE}"
$1 build -t $IMAGE --platform "linux/$2" "$buildfolder"

echo "Tagging: ${IMAGE}"
$1 tag "$IMAGE" "$IMAGE"

echo "Pushing: ${IMAGE}"
$1 push "$IMAGE"

# Add image to list of all images to be added to a manifest
images+=("${IMAGE}")
}

function engine-handler {
for arch in amd64 arm64 ; do
build "$1" "$arch"
done
}


if [ ! ${podman} == true ]; then
echo "Executing with podman"

# Build and push multi-arch images
engine-handler podman

# Create manifest and add images
podman manifest create oci-registry-manifest
for img in "${images[@]}" ; do
podman manifest add oci-registry-manifest "$img"
done

# Push and delete local manifest
podman manifest push oci-registry-manifest "$BASE_REPO":"$BASE_TAG"
thepetk marked this conversation as resolved.
Show resolved Hide resolved
podman manifest rm oci-registry-manifest

else
echo "Executing with docker"

# Build and push multi-arch images
engine-handler docker
thepetk marked this conversation as resolved.
Show resolved Hide resolved

# Create manifest and add images
docker manifest create "$BASE_REPO:$BASE_TAG" "${images[@]}"

# Push and delete local manifest
docker manifest push "$BASE_REPO:$BASE_TAG"
docker manifest rm "$BASE_REPO:$BASE_TAG"

fi
13 changes: 12 additions & 1 deletion oci-registry/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,18 @@
# Build the index container for the registry
buildfolder="$(basename "$(dirname "$0")")"

DEFAULT_ARCH="linux/amd64"

# Check if different architecture was passed for image build
# Will default to $DEFAULT_ARCH if unset
if [ ! -z "$1" ]
then
arch="$1"
else
arch="$DEFAULT_ARCH"
fi

# set podman alias if necessary
. ${buildfolder}/../setenv.sh

docker build -t oci-registry:next $buildfolder
docker build -t oci-registry:next --platform "${arch}" "$buildfolder"
Loading