Skip to content

Multi Arch Image Building for Devfile Index #414

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

Merged
merged 4 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .ci/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ FROM registry.access.redhat.com/ubi8/go-toolset:1.19 AS builder
# Set user as root
USER root

# Automatically set when --platform flag is set, will default to amd64 if no platform is given
ARG TARGETARCH=amd64

# Install yq
ENV YQ_VERSION=v4.44.1
RUN curl -sL -O https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64 -o /usr/local/bin/yq && mv ./yq_linux_amd64 /usr/local/bin/yq && chmod +x /usr/local/bin/yq
RUN curl -sL -O https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_${TARGETARCH} -o /usr/local/bin/yq && mv ./yq_linux_${TARGETARCH} /usr/local/bin/yq && chmod +x /usr/local/bin/yq

COPY . /registry

Expand Down
5 changes: 4 additions & 1 deletion .ci/Dockerfile.offline
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ FROM registry.access.redhat.com/ubi8/go-toolset:1.19 AS builder
# Set user as root
USER root

# Automatically set when --platform flag is set, will default to amd64 if no platform is given
ARG TARGETARCH=amd64

# Install yq
ENV YQ_VERSION=v4.44.1
RUN curl -sL -O https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_amd64 -o /usr/local/bin/yq && mv ./yq_linux_amd64 /usr/local/bin/yq && chmod +x /usr/local/bin/yq
RUN curl -sL -O https://github.com/mikefarah/yq/releases/download/${YQ_VERSION}/yq_linux_${TARGETARCH} -o /usr/local/bin/yq && mv ./yq_linux_${TARGETARCH} /usr/local/bin/yq && chmod +x /usr/local/bin/yq

COPY . /registry

Expand Down
52 changes: 52 additions & 0 deletions .ci/build-multi-arch.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/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.

# Build the index container for the registry
ABSOLUTE_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
# 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}
# Base Repository
BASE_REPO="quay.io/devfile/devfile-index"
BASE_TAG="next"
DEFAULT_IMG="$BASE_REPO:$BASE_TAG"
# Platforms to build for
PLATFORMS="linux/amd64,linux/arm64"

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

podman manifest create "$DEFAULT_IMG"

podman build --platform="$PLATFORMS" --manifest "$DEFAULT_IMG" --no-cache -f $ABSOLUTE_PATH/Dockerfile $ABSOLUTE_PATH/..

podman manifest push "$DEFAULT_IMG"

podman manifest rm "$DEFAULT_IMG"

else
echo "Executing with docker"

docker buildx create --name index-builder

docker buildx use index-builder

docker buildx build --push --platform="$PLATFORMS" --tag "$DEFAULT_IMG" --provenance=false --no-cache -f $ABSOLUTE_PATH/Dockerfile $ABSOLUTE_PATH/..

docker buildx rm index-builder

fi
14 changes: 12 additions & 2 deletions .ci/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ shopt -s expand_aliases

ABSOLUTE_PATH="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
USE_PODMAN=${USE_PODMAN:-false}
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

if [[ ${USE_PODMAN} == true ]]; then
alias docker=podman
Expand All @@ -24,7 +34,7 @@ fi

if [ $# -eq 1 ] && [ $1 == "offline" ]
then
docker build --no-cache -t devfile-index -f $ABSOLUTE_PATH/Dockerfile.offline $ABSOLUTE_PATH/..
docker build --no-cache --platform "${arch}" -t devfile-index -f $ABSOLUTE_PATH/Dockerfile.offline $ABSOLUTE_PATH/..
else
docker build --no-cache -t devfile-index -f $ABSOLUTE_PATH/Dockerfile $ABSOLUTE_PATH/..
docker build --no-cache --platform "${arch}" -t devfile-index -f $ABSOLUTE_PATH/Dockerfile $ABSOLUTE_PATH/..
fi
4 changes: 3 additions & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ jobs:
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version: 1.19
- name: Set up QEMU # Enables arm64 image building
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3

- name: Check if devfile registry build is working
run: bash registry-repo/.ci/build.sh
run: bash registry-repo/.ci/build.sh && bash registry-repo/.ci/build.sh linux/arm64
8 changes: 4 additions & 4 deletions .github/workflows/pushimge-next.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ jobs:
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version: 1.13
- name: Set up QEMU # Enables arm64 image building
uses: docker/setup-qemu-action@68827325e0b33c7199eb31dd4e31fbe9023e06e3
- name: Login to Quay
uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
- name: Build the devfile-index docker image
run: bash registry-repo/.ci/build.sh
- name: Push the devfile-index docker image
run: bash registry-support/build-tools/push.sh quay.io/devfile/devfile-index:next
- name: Build and push the devfile-index docker image
run: bash registry-repo/.ci/build-multi-arch.sh
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,16 @@ If you are a stack owner and need to request an urgent refresh of <https://regis

### Build

To build this devfile registry into a container image run `bash .ci/build.sh`. A container image will be built using the [devfile registry build tools](https://github.com/devfile/registry-support/tree/master/build-tools). By default these scripts will use `docker`, if you want to use `podman` you should first run `export USE_PODMAN=true` before executing the build script.
To build this devfile registry into a container image run `bash .ci/build.sh`. A container image will be built using the [devfile registry build tools](https://github.com/devfile/registry-support/tree/master/build-tools). By default these scripts will use `docker` and be built for the `linux/amd64` architecture.

To build using `podman` first run:
```
export USE_PODMAN=true
```
To build for `linux/arm64` run:
```
bash .ci/build.sh linux/arm64
```

From there, push the container image to a container registry of your choice and deploy using a [devfile adopted devtool](https://devfile.io/docs/2.2.0/developing-with-devfiles#tools-that-provide-devfile-support) or one of the methods outlined [here](https://github.com/devfile/registry-support#deploy).

Expand Down
Loading