Skip to content

Commit

Permalink
chore: add crc-builder spec
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 30, 2024
1 parent f6be286 commit 03e15cd
Show file tree
Hide file tree
Showing 18 changed files with 1,009 additions and 8 deletions.
17 changes: 15 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,17 @@ 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: 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 oci-multiarch-build
57 changes: 51 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,68 @@ 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

## Functions
oci_builder = ${CONTAINER_MANAGER} build -t $(1):$(2) -f $(3)/oci/Containerfile $(3)/oci
define oci_manifest
${CONTAINER_MANAGER} manifest create $(1):$(2)
endef
define oci_builder
${CONTAINER_MANAGER} build -t $(1):$(2) -f $(3)/oci/$(4) $(3)/oci
endef
define oci_arch_builder
${CONTAINER_MANAGER} build --platform $(1) --manifest $(2):$(3) -f $(4)/oci/$(5) $(4)/oci
endef

# oci_arch_builder = ${CONTAINER_MANAGER} build -t $(1):$(2) -f $(3)/oci/Containerfile $(3)/oci ${CONTAINER_MANAGER} build --platform $(1),linux/arm64 --manifest quay.io/rhqp/crc-builder:v0.0.8-linux -f oci/Containerfile.ma-linux oci
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-build:
# snc-runner
$(call oci_builder,$(SNC_RUNNER),$(SNC_RUNNER_V),snc-runner,Containerfile)

oci-multiarch-build:
# crc-builder for linux
$(call oci_manifest,$(CRC_BUILDER),$(CRC_BUILDER_V)-linux)
$(call oci_arch_builder,linux/amd64,$(CRC_BUILDER),$(CRC_BUILDER_V)-linux,crc-builder,Containerfile.linux)
$(call oci_arch_builder,linux/arm64,$(CRC_BUILDER),$(CRC_BUILDER_V)-linux,crc-builder,Containerfile.linux)

oci-push:
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)

# ${CONTAINER_MANAGER} manifest create quay.io/rhqp/crc-builder:v0.0.8-linux
# ${CONTAINER_MANAGER} build --platform linux/amd64,linux/arm64 --manifest quay.io/rhqp/crc-builder:v0.0.8-linux -f oci/Containerfile.ma-linux oci


# # Build the container image
# .PHONY: oci-build
# oci-build:
# ${CONTAINER_MANAGER} build -t ${IMG}-linux -f oci/Containerfile.linux oci
# ${CONTAINER_MANAGER} build -t ${IMG}-windows -f oci/Containerfile.non-linux --build-arg=OS=windows oci
# ${CONTAINER_MANAGER} build -t ${IMG}-darwin -f oci/Containerfile.non-linux --build-arg=OS=darwin oci

# # Push the docker image
# .PHONY: oci-push
# oci-push:
# ${CONTAINER_MANAGER} push ${IMG}-linux
# ${CONTAINER_MANAGER} push ${IMG}-windows
# ${CONTAINER_MANAGER} push ${IMG}-darwin

# # Create tekton task bundle
# .PHONY: tkn-push
# tkn-push: install-out-of-tree-tools
# $(TOOLS_BINDIR)/tkn bundle push $(TKN_IMG) \
# -f tkn/crc-builder-installer.yaml \
# -f tkn/crc-builder.yaml \
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 --platform=$TARGETPLATFORM 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 \
&& 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
}
Loading

0 comments on commit 03e15cd

Please sign in to comment.