Skip to content

Commit

Permalink
cleanup: test multiarch
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Riobo Lorenzo <[email protected]>
  • Loading branch information
adrianriobo committed Jul 31, 2024
1 parent f6be286 commit f3b0a87
Show file tree
Hide file tree
Showing 18 changed files with 991 additions and 10 deletions.
22 changes: 20 additions & 2 deletions .github/workflows/build-oci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ on:
branches: [ main ]

jobs:
build-mapt:
name: build-mapt
build-oci:
name: build-oci
runs-on: ubuntu-24.04
steps:
- name: Checkout code
Expand All @@ -22,4 +22,22 @@ jobs:
run: |
SNC_RUNNER=ghcr.io/crc-org/ci-definitions SNC_RUNNER_V=pr-${{ github.event.number }} make oci-build
build-multiarch-oci:
name: build-multiarch-oci
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Prepare runner
shell: bash
run: |
sudo apt-get install -y qemu-user-static
- name: Build image for PR
if: ${{ github.event_name == 'pull_request' }}
shell: bash
run: |
CRC_BUILDER=ghcr.io/crc-org/ci-definitions CRC_BUILDER_V=pr-${{ github.event.number }} make build-crc-builder-oci
36 changes: 28 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,43 @@ include tools/tools.mk
# Registries and versions
SNC_RUNNER ?= $(shell sed -n 1p snc-runner/release-info)
SNC_RUNNER_V ?= $(shell sed -n 2p snc-runner/release-info)
# CRC_BUILDER ?= $(shell sed -n 1p crc-builder/release-info)
# CRC_BUILDER_V ?= $(shell sed -n 2p crc-builder/release-info)

.PHONY: oci-build oci-push tkn-create tkn-push
.PHONY: oci-build build-crc-builder-oci oci-push tkn-create tkn-push

## Functions
oci_builder = ${CONTAINER_MANAGER} build -t $(1):$(2) -f $(3)/oci/Containerfile $(3)/oci
define oci_builder
${CONTAINER_MANAGER} build -t $(1):$(2) -f $(3)/oci/$(4) $(3)/oci
endef
oci_pusher = ${CONTAINER_MANAGER} push $(1):$(2)
tkn_creator = sed -e 's%cimage%$(1)%g' -e 's%cversion%$(2)%g' $(3)/tkn/tpl/task.tpl.yaml > $(3)/tkn/task.yaml
tkn_pusher = $(TOOLS_BINDIR)/tkn bundle push $(1):$(2)-tkn -f $(3)/tkn/task.yaml

oci-build:
$(call oci_builder,$(SNC_RUNNER),$(SNC_RUNNER_V),snc-runner)

oci-push:
oci-build:
# snc-runner
$(call oci_builder,$(SNC_RUNNER),$(SNC_RUNNER_V),snc-runner,Containerfile)

build-crc-builder-oci:
CONTEXT=crc-builder/oci
MANIFEST=$(CRC_BUILDER):$(CRC_BUILDER_V)
ifndef CRC_BUILDER
CRC_BUILDER=$(shell sed -n 1p crc-builder/release-info)
endif
ifndef CRC_BUILDER_V
CRC_BUILDER_V=v$(shell sed -n 2p crc-builder/release-info)
endif
build-crc-builder-oci:
${CONTAINER_MANAGER} manifest create $(MANIFEST)-linux
${CONTAINER_MANAGER} build --platform linux/arm64 --build-arg=TARGETARCH=arm64 --manifest $(MANIFEST)-linux -f $(CONTEXT)/Containerfile.linux $(CONTEXT)
${CONTAINER_MANAGER} build --platform linux/amd64 --build-arg=TARGETARCH=amd64 --manifest $(MANIFEST)-linux -f $(CONTEXT)/Containerfile.linux $(CONTEXT)

oci-push:
$(call oci_pusher,$(SNC_RUNNER),$(SNC_RUNNER_V))
$(call oci_pusher,$(CRC_BUILDER),$(CRC_BUILDER_V)-linux)

tkn-create:
tkn-create:
$(call tkn_creator,$(SNC_RUNNER),$(SNC_RUNNER_V),snc-runner)

tkn-push: install-out-of-tree-tools
$(call tkn_pusher,$(SNC_RUNNER),$(SNC_RUNNER_V),snc-runner)
$(call tkn_pusher,$(SNC_RUNNER),$(SNC_RUNNER_V),snc-runner)
9 changes: 9 additions & 0 deletions crc-builder/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog

## 1.0.0

* Initial version for managinig 2 types of builders
* linux multi arch container based
* windows and mac build on remote target


35 changes: 35 additions & 0 deletions crc-builder/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# CRC Builder

## Modifications to the image

Changes to `crc-builder/os/macos/builder/build.sh` require re-building and pushing the image to internal registry (ImageStream). Make sure the changes are pushed to some `mybranch` on your fork of the QE platform repo (`github.com/<your-username>/qe-platform`). Since the `crc-builder/manifests/buildconfig.yaml` will be guiding the build of the image, it needs to specify your branch on your fork as the source.

```diff
source:
contextDir: support/images/crc-builder
git:
# dev
+ ref: 'mybranch'
+ uri: 'https://gitlab.cee.redhat.com/<your-username>/qe-platform.git'
- ref: v2.14.0
- uri: 'https://gitlab.cee.redhat.com/crc/qe-platform.git'
type: Git
```

Log in to `codeready-container` project, apply the changes in `crc-builder/manifests/buildconfig.yaml` and start the build from the corresponding `BuildConfig` (depending on the platform).

```bash
oc apply -f support/images/crc-builder/manifests/buildconfig.yaml
oc start-build image-crc-builder-<platform>
```

Lastly, make sure that `imagePullPolicy` is set to `Always` in all places that use this imageStreamTag (e.g. `crc-builder:v0.0.3-macos`). In our case, we needed to change and re-apply the following YAML.

```bash
oc apply -f orchestrator/catalog/task/crc-builder-installer/0.3/crc-builder-installer.yaml
```

Then undo changes to `crc-builder/manifests/buildconfig.yaml` so it points to the upstream repository.

_If everything works as expected, send an MR to `gitlab.cee.redhat.com/crc/qe-platform`._

21 changes: 21 additions & 0 deletions crc-builder/oci/Containerfile.linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#8.10
FROM quay.io/almalinuxorg/8-minimal@sha256:6c50656775e5971f7fb5e0d0d5b17f246873408a67b571ef720b7c1324118433

ARG TARGETARCH

LABEL org.opencontainers.image.authors="CodeReady Containers <[email protected]>"

ENV GO_VERSION 1.21.11

RUN microdnf -y install git make gcc libvirt-devel perl-Digest-SHA xz findutils diffutils tar \
&& curl -Lo /tmp/${GO_VERSION}.tar.gz https://go.dev/dl/go${GO_VERSION}.linux-${TARGETARCH}.tar.gz \
&& tar -xzvf /tmp/${GO_VERSION}.tar.gz -C /usr/lib > /dev/null \
&& ln -s /usr/lib/go/bin/go /usr/local/bin/go \
&& curl -k -Lo /usr/local/bin/mc https://dl.min.io/client/mc/release/linux-${TARGETARCH}/mc \
&& chmod +x /usr/local/bin/mc \
&& rm /tmp/${GO_VERSION}.tar.gz

COPY lib/common.sh /usr/local/bin
COPY lib/linux/entrypoint.sh /usr/local/bin/entrypoint.sh

ENTRYPOINT entrypoint.sh
28 changes: 28 additions & 0 deletions crc-builder/oci/Containerfile.non-linux
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM registry.access.redhat.com/ubi8/ubi-minimal as preparer

ARG OS
ENV OS ${OS}

COPY lib/${OS}/builder/* /usr/local/crc-builder/
COPY lib/${OS}/entrypoint.sh /usr/local/bin/entrypoint.sh

RUN cd /usr/local/crc-builder && \
if [[ ${OS} == 'windows' ]]; then \
curl -k -LO https://dl.minio.io/client/mc/release/windows-amd64/mc.exe; \
else \
curl -k -LO https://dl.min.io/client/mc/release/darwin-amd64/mc; \
chmod +x mc; \
fi;

FROM quay.io/rhqp/support-tools:v0.0.2

LABEL org.opencontainers.image.authors="CodeReady Containers <[email protected]>"

ENV PLATFORM ${PLATFORM}
ENV BUILDER_RESOURCES "/usr/local/crc-builder"

COPY --from=preparer /usr/local/crc-builder ${BUILDER_RESOURCES}
COPY --from=preparer /usr/local/bin/entrypoint.sh /usr/local/bin
COPY lib/common.sh /usr/local/bin

ENTRYPOINT entrypoint.sh
83 changes: 83 additions & 0 deletions crc-builder/oci/lib/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
#!/bin/sh

# Validate required envs are setup to run the container
validate_envs () {
local validate=1

[[ -z "${TARGET_HOST+x}" ]] \
&& echo "TARGET_HOST required" \
&& validate=0

[[ -z "${TARGET_HOST_USERNAME+x}" ]] \
&& echo "TARGET_HOST_USERNAME required" \
&& validate=0

[[ -z "${TARGET_HOST_KEY_PATH+x}" && -z "${TARGET_HOST_PASSWORD+x}" ]] \
&& echo "TARGET_HOST_KEY_PATH or TARGET_HOST_PASSWORD required" \
&& validate=0

return $validate
}

validate_assets_info () {
local validate=1

[[ -z "${TRAY_URL+x}" ]] \
&& echo "TRAY_URL required" \
&& validate=0

return $validate
}

validate_s3_configuration () {
local validate=1

[[ -z "${DATALAKE_URL}" || -z "${DATALAKE_ACCESS_KEY}" || -z "${DATALAKE_SECRET_KEY}" ]] \
&& echo "s3 credentials are required, binary can not be updaloaded" \
&& validate=0

return $validate
}

# Define remote connection
remote_connection () {
local remote="${TARGET_HOST_USERNAME}@${TARGET_HOST}"
if [[ ! -z "${TARGET_HOST_DOMAIN+x}" ]]; then
remote="${TARGET_HOST_USERNAME}@${TARGET_HOST_DOMAIN}@${TARGET_HOST}"
fi
echo "${remote}"
}

# scp connection string
scp_cmd () {
local options='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
if [[ ! -z "${TARGET_HOST_KEY_PATH+x}" ]]; then
echo "scp -r ${options} -i ${TARGET_HOST_KEY_PATH} "
else
echo "sshpass -p ${TARGET_HOST_PASSWORD} scp -r ${options} "
fi
}

# ssh connection string
ssh_cmd () {
local options='-o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null'
local connection_string=$(remote_connection)
if [[ ! -z "${TARGET_HOST_KEY_PATH+x}" ]]; then
echo "ssh ${options} -i ${TARGET_HOST_KEY_PATH} ${connection_string}"
else
echo "sshpass -p ${TARGET_HOST_PASSWORD} ssh ${options} ${connection_string}"
fi
}

upload_path() {
path="distributables/app"
if [[ -z ${CRC_VERSION+x} ]]; then
if [[ ! -z ${PULL_REQUEST+x} ]]; then
echo "${path}/pr-${PULL_REQUEST}"
else
echo "${path}/${REF}"
fi
else
echo "${path}/release/${CRC_VERSION}"
fi
}
109 changes: 109 additions & 0 deletions crc-builder/oci/lib/darwin/builder/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#!/bin/sh
# Script to be executed on macos machine to build a crc macos installer
# and upload it to s3 compatible storage

# Execution is controlled based on ENVS:

# CUSTOM_BUNDLE_VERSION_VARIABLE When build based on a custom bundle need to set type: PODMAN_VERSION or OPENSHIFT_VERSION
# CUSTOM_BUNDLE_VERSION When build based on a custom bundle need to set version
# CRC_SCM: Source code repository for crc
# CRC_SCM_PR: Optional parameter to build an specific PR for crc
# CRC_SCM_REF: Optional parameter to build an specific PR for crc
# CRC_VERSION: Build based on crc version
# DATALAKE_URL: url for remote s3 compatible storage where build bits will be stored
# DATALAKE_ACCESS_KEY: remote s3 credential
# DATALAKE_SECRET_KEY:remote s3 credential

# Defaults
CRC_SCM="${CRC_SCM:-"https://github.com/code-ready/crc.git"}"
CRC_SCM_REF="${CRC_SCM_REF:-"main"}"
ADMINHELPER_SCM="${ADMINHELPER_SCM:-"https://github.com/code-ready/admin-helper.git"}"
VFKIT_SCM="${VFKIT_SCM:-"https://github.com/code-ready/vfkit.git"}"

set -exuo pipefail

# Upload content to S3 compatible
# $1 remote path
# $2 local path to be uploaded
s3_upload() {
[[ -z "${DATALAKE_URL}" || -z "${DATALAKE_ACCESS_KEY}" || -z "${DATALAKE_SECRET_KEY}" ]] \
&& echo "s3 credentials are required, binary can not be updaloaded" \
&& exit 1

./mc alias set datalake \
${DATALAKE_URL} \
${DATALAKE_ACCESS_KEY} \
${DATALAKE_SECRET_KEY} \
--api S3v4

# Create bucket if not exits
./mc mb "datalake/${1}"
# Copy files to datalake
./mc cp "${2}/crc-macos-installer.pkg" "datalake/${1}/crc-macos-installer.pkg"
./mc cp "${2}/crc-macos-installer.sha256sum" "datalake/${1}/crc-macos-installer.pkg.sha256sum"
# Make bucket public
# ./mc anonymous set public "datalake/${1}/"
}

#####################
####### MAIN ########
#####################

# Custom setup for git
git config --global http.version "HTTP/1.1"
git config --global http.lowSpeedLimit 0
git config --global http.lowSpeedTime 999999

# Get crc code
git clone ${CRC_SCM}

# Fetch according to parameters provided
if [[ -z ${CRC_VERSION+x} ]]; then
CRC_VERSION_PARTIAL=$(date +'%y.%m.%d')
if [[ ! -z ${CRC_SCM_PR+x} ]]; then
git -C crc fetch origin pull/${CRC_SCM_PR}/head:pr-${CRC_SCM_PR}
git -C crc checkout pr-${CRC_SCM_PR}
else
git -C crc checkout ${CRC_SCM_REF}
fi
# In case we build for a custom bundle we need to match the version
# if [[ ! -z ${CUSTOM_BUNDLE_VERSION_VARIABLE+x} ]] && [[ ! -z ${CUSTOM_BUNDLE_VERSION+x} ]]; then
# sed -i.bak "s/${CUSTOM_BUNDLE_VERSION_VARIABLE} ?= .*/${CUSTOM_BUNDLE_VERSION_VARIABLE} = ${CUSTOM_BUNDLE_VERSION}/g" crc/Makefile
# fi
sed -i.bak "s/CRC_VERSION = .*/CRC_VERSION = ${CRC_VERSION_PARTIAL}/g" crc/Makefile
else
git -C crc checkout "tags/v${CRC_VERSION}" -b "v${CRC_VERSION}"
fi

# Build admin-helper
git clone ${ADMINHELPER_SCM}
admin_version_line=$(cat admin-helper/crc-admin-helper.spec.in | grep Version:)
admin_version=${admin_version_line##*:}
admin_version=$(echo $admin_version | xargs)
make -C admin-helper out/macos-amd64/crc-admin-helper VERSION=$admin_version

# Build vfkit
git clone ${VFKIT_SCM}
sudo make -C vfkit all

# Build pkg
pushd crc
# custom resources to be included
mkdir custom_embedded
cp ./../admin-helper/out/macos-amd64/crc-admin-helper custom_embedded/crc-admin-helper-darwin
cp ./../vfkit/out/vfkit custom_embedded/vfkit
cp ./../vfkit/vf.entitlements custom_embedded/vf.entitlements

# Match admin-helper version with latest from master head
sed -i '' "s/crcAdminHelperVersion =.*/crcAdminHelperVersion = \"${admin_version}\"/g" pkg/crc/version/version.go

# create pkg
make out/macos-universal/crc-macos-installer.pkg NO_CODESIGN=1 CUSTOM_EMBED=true EMBED_DOWNLOAD_DIR=custom_embedded
# check sum
pushd out/macos-universal
shasum -a 256 * > crc-macos-installer.sha256sum
popd
popd

# Upload
s3_upload ${UPLOAD_PATH} crc/out/macos-universal
Loading

0 comments on commit f3b0a87

Please sign in to comment.