From 005bf5b02204e6849acb385759602042461a01a0 Mon Sep 17 00:00:00 2001 From: Adrian Riobo Lorenzo Date: Thu, 1 Aug 2024 14:13:53 +0200 Subject: [PATCH] chore: initial structure for building / pushing oci images for ci specs Signed-off-by: Adrian Riobo Lorenzo --- .github/workflows/build-oci.yaml | 25 ---- .../workflows/crc-builder-oci-builder.yaml | 66 +++++++++ .github/workflows/crc-builder-oci-pusher.yml | 31 ++++ .github/workflows/snc-runner-oci-builder.yaml | 56 ++++++++ .github/workflows/snc-runner-oci-pusher.yml | 57 ++++++++ Makefile | 81 ++++++++--- crc-builder/CHANGELOG.md | 9 ++ crc-builder/README.md | 35 +++++ crc-builder/oci/Containerfile.linux | 21 +++ crc-builder/oci/Containerfile.non-linux | 28 ++++ crc-builder/oci/lib/common.sh | 83 +++++++++++ crc-builder/oci/lib/darwin/builder/build.sh | 109 ++++++++++++++ crc-builder/oci/lib/darwin/entrypoint.sh | 57 ++++++++ crc-builder/oci/lib/linux/entrypoint.sh | 111 +++++++++++++++ crc-builder/oci/lib/windows/builder/build.ps1 | 131 +++++++++++++++++ crc-builder/oci/lib/windows/entrypoint.sh | 57 ++++++++ crc-builder/release-info | 2 + .../tkn/samples/linux-with-custom-bundle.yaml | 25 ++++ crc-builder/tkn/samples/macos-from-pr.yaml | 16 +++ .../tkn/samples/windows-from-master.yaml | 24 ++++ .../tkn/tpl/crc-builder-installer.tpl.yaml | 133 ++++++++++++++++++ crc-builder/tkn/tpl/crc-builder.tpl.yaml | 102 ++++++++++++++ snc-runner/release-info | 4 +- 23 files changed, 1220 insertions(+), 43 deletions(-) delete mode 100644 .github/workflows/build-oci.yaml create mode 100644 .github/workflows/crc-builder-oci-builder.yaml create mode 100644 .github/workflows/crc-builder-oci-pusher.yml create mode 100644 .github/workflows/snc-runner-oci-builder.yaml create mode 100644 .github/workflows/snc-runner-oci-pusher.yml create mode 100644 crc-builder/CHANGELOG.md create mode 100644 crc-builder/README.md create mode 100644 crc-builder/oci/Containerfile.linux create mode 100644 crc-builder/oci/Containerfile.non-linux create mode 100755 crc-builder/oci/lib/common.sh create mode 100755 crc-builder/oci/lib/darwin/builder/build.sh create mode 100755 crc-builder/oci/lib/darwin/entrypoint.sh create mode 100755 crc-builder/oci/lib/linux/entrypoint.sh create mode 100644 crc-builder/oci/lib/windows/builder/build.ps1 create mode 100755 crc-builder/oci/lib/windows/entrypoint.sh create mode 100644 crc-builder/release-info create mode 100644 crc-builder/tkn/samples/linux-with-custom-bundle.yaml create mode 100644 crc-builder/tkn/samples/macos-from-pr.yaml create mode 100644 crc-builder/tkn/samples/windows-from-master.yaml create mode 100644 crc-builder/tkn/tpl/crc-builder-installer.tpl.yaml create mode 100644 crc-builder/tkn/tpl/crc-builder.tpl.yaml diff --git a/.github/workflows/build-oci.yaml b/.github/workflows/build-oci.yaml deleted file mode 100644 index 809d2af..0000000 --- a/.github/workflows/build-oci.yaml +++ /dev/null @@ -1,25 +0,0 @@ -name: oci-builds - -on: - push: - branches: [ main ] - tags: - - '*' - pull_request: - branches: [ main ] - -jobs: - build-mapt: - name: build-mapt - 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: | - SNC_RUNNER=ghcr.io/crc-org/ci-definitions SNC_RUNNER_V=pr-${{ github.event.number }} make oci-build - - \ No newline at end of file diff --git a/.github/workflows/crc-builder-oci-builder.yaml b/.github/workflows/crc-builder-oci-builder.yaml new file mode 100644 index 0000000..507b3ff --- /dev/null +++ b/.github/workflows/crc-builder-oci-builder.yaml @@ -0,0 +1,66 @@ +name: crc-builder-oci-builder + +on: + push: + # If release-info is not changed we may override a version + tags: [ '*' ] + paths: + - '.github\/workflows\/crc-builder\/release-info' + pull_request: + branches: [ main ] + paths: + - 'crc-builder/**' + - '.github\/workflows\/crc-builder*' + +jobs: + build: + name: build + 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' }} + env: + CRC_BUILDER: ghcr.io/crc-org/ci-crc-builder + CRC_BUILDER_V: pr-${{ github.event.number }} + run: | + make crc-builder-oci-build + CRC_BUILDER_SAVE=crc-builder make crc-builder-oci-save + echo "CRC_BUILDER=${SNC_RUNNER}" >> "$GITHUB_ENV" + echo "CRC_BUILDER_V=${SNC_RUNNER_V}" >> "$GITHUB_ENV" + + - name: Build image for Release + if: ${{ github.event_name == 'push' }} + run: | + make crc-builder-oci-build + CRC_BUILDER_SAVE=crc-builder make crc-builder-oci-save + # Get values from release-info + CRC_BUILDER ?= $(sed -n 1p crc-builder/release-info) + CRC_BUILDER_V ?= v$(sed -n 2p crc-builder/release-info) + echo "CRC_BUILDER=${CRC_BUILDER}" >> "$GITHUB_ENV" + echo "CRC_BUILDER_V=${CRC_BUILDER_V}" >> "$GITHUB_ENV" + + - name: Create image metadata + run: | + echo ${{ env.CRC_BUILDER }}:${{ env.CRC_BUILDER_V }} > crc-builder-info + echo ${{ github.event_name }} > crc-builder-build-event + + - name: Upload crc-builder + uses: actions/upload-artifact@v4 + with: + name: crc-builder + path: crc-builder* + + + + + + + \ No newline at end of file diff --git a/.github/workflows/crc-builder-oci-pusher.yml b/.github/workflows/crc-builder-oci-pusher.yml new file mode 100644 index 0000000..5222559 --- /dev/null +++ b/.github/workflows/crc-builder-oci-pusher.yml @@ -0,0 +1,31 @@ +name: crc-builder-oci-pusher + +on: + workflow_run: + workflows: crc-builder-oci-builder + types: + - completed + +jobs: + push: + name: push + runs-on: ubuntu-24.04 + permissions: + contents: read + packages: write + steps: + - name: Download crc-builder-oci assets + id: download-gh-context-artifact + uses: actions/download-artifact@v4 + with: + name: crc-builder + run-id: ${{ github.event.workflow_run.id }} + github-token: ${{ github.token }} + + - name: Build image for Release + run: | + ls -al + + + + diff --git a/.github/workflows/snc-runner-oci-builder.yaml b/.github/workflows/snc-runner-oci-builder.yaml new file mode 100644 index 0000000..5af8461 --- /dev/null +++ b/.github/workflows/snc-runner-oci-builder.yaml @@ -0,0 +1,56 @@ +name: snc-runner-oci-builder + +on: + push: + tags: [ '*' ] + paths: + - '.github\/workflows\/snc-runner\/release-info' + pull_request: + branches: [ main ] + paths: + - 'snc-runner/**' + - '.github\/workflows\/snc-runner*' +jobs: + build: + name: build + runs-on: ubuntu-24.04 + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Build image for PR + if: ${{ github.event_name == 'pull_request' }} + env: + # SNC_RUNNER: ghcr.io/crc-org/ci-snc-runner + SNC_RUNNER: ghcr.io/adrianriobo/ci-snc-runner + SNC_RUNNER_V: pr-${{ github.event.number }} + run: | + make snc-runner-oci-build + SNC_RUNNER_SAVE=snc-runner make snc-runner-oci-save + echo "image=${SNC_RUNNER}" >> "$GITHUB_ENV" + echo "tag=${SNC_RUNNER_V}" >> "$GITHUB_ENV" + + - name: Build image for Release + if: ${{ github.event_name == 'push' }} + run: | + make snc-runner-oci-build + SNC_RUNNER_SAVE=snc-runner make snc-runner-oci-save + # Get values from release-info + echo "image=$(sed -n 1p snc-runner/release-info)" >> "$GITHUB_ENV" + echo "tag=v$(sed -n 2p snc-runner/release-info)" >> "$GITHUB_ENV" + + - name: Create image metadata + run: | + echo ${{ env.image }}:${{ env.tag }} > snc-runner-image + echo ${{ github.event_name }} > snc-runner-build-event + + - name: Upload snc-runner + uses: actions/upload-artifact@v4 + with: + name: snc-runner + path: snc-runner* + + + + + \ No newline at end of file diff --git a/.github/workflows/snc-runner-oci-pusher.yml b/.github/workflows/snc-runner-oci-pusher.yml new file mode 100644 index 0000000..a09899a --- /dev/null +++ b/.github/workflows/snc-runner-oci-pusher.yml @@ -0,0 +1,57 @@ +name: snc-runner-oci-pusher + +on: + workflow_run: + workflows: snc-runner-oci-builder + types: + - completed + +jobs: + push: + name: push + runs-on: ubuntu-24.04 + permissions: + contents: read + packages: write + steps: + - name: Download snc-runner assets + id: download-gh-context-artifact + uses: actions/download-artifact@v4 + with: + name: snc-runner + run-id: ${{ github.event.workflow_run.id }} + github-token: ${{ github.token }} + + - name: Get snc-runner build informaiton + run: | + echo "source_event=$(cat snc-runner-build-event)" >> "$GITHUB_ENV" + echo "image=$(cat snc-runner-image)" >> "$GITHUB_ENV" + + - name: Log in to ghcr.io for PR + if: ${{ env.source_event == 'pull_request' }} + uses: redhat-actions/podman-login@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Log in to ghcr.io + if: ${{ env.source_event == 'push' }} + uses: redhat-actions/podman-login@v1 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Loginquay.io + if: ${{ env.source_event == 'push' }} + uses: redhat-actions/podman-login@v1 + with: + registry: quay.io + username: ${{ secrets.QUAY_IO_USERNAME }} + password: ${{ secrets.QUAY_IO_PASSWORD }} + + - name: Push snc-runner + run: | + podman load -i snc-runner.tar + podman push ${{ env.image }} \ No newline at end of file diff --git a/Makefile b/Makefile index 3560061..a820426 100644 --- a/Makefile +++ b/Makefile @@ -4,26 +4,75 @@ CONTAINER_MANAGER ?= podman TOOLS_DIR := tools include tools/tools.mk -# Registries and versions +## Functions +# Set image and version on the task +# 1 image +# 2 version +# 3 context +define tkn_template + sed -e 's%cimage%$(1)%g' -e 's%cversion%$(2)%g' $(3)/tkn/tpl/task.tpl.yaml > $(3)/tkn/task.yaml +endef + +# Push task as bundle +# 1 image +# 2 version +# 3 context +define tkn_push + $(TOOLS_BINDIR)/tkn bundle push $(1):$(2)-tkn -f $(3)/tkn/task.yaml +endef + +#### snc-runner #### + +.PHONY: snc-runner-oci-build snc-runner-oci-save snc-runner-oci-push + +# Variables SNC_RUNNER ?= $(shell sed -n 1p snc-runner/release-info) -SNC_RUNNER_V ?= $(shell sed -n 2p snc-runner/release-info) +SNC_RUNNER_V ?= v$(shell sed -n 2p snc-runner/release-info) +SNC_RUNNER_SAVE ?= snc-runner -.PHONY: oci-build oci-push tkn-create tkn-push +snc-runner-oci-build: CONTEXT=snc-runner/oci +snc-runner-oci-build: MANIFEST=$(SNC_RUNNER):$(SNC_RUNNER_V) +snc-runner-oci-build: + ${CONTAINER_MANAGER} build -t $(MANIFEST) -f $(CONTEXT)/Containerfile $(CONTEXT) -## Functions -oci_builder = ${CONTAINER_MANAGER} build -t $(1):$(2) -f $(3)/oci/Containerfile $(3)/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 +snc-runner-oci-save: + ${CONTAINER_MANAGER} save -o $(SNC_RUNNER_SAVE).tar $(SNC_RUNNER):$(SNC_RUNNER_V) + +snc-runner-oci-push: + ${CONTAINER_MANAGER} push $(SNC_RUNNER):$(SNC_RUNNER_V) + +#### crc-builder #### + +.PHONY: crc-builder-oci-build crc-builder-oci-save crc-builder-oci-push + +# Registries and versions +CRC_BUILDER ?= $(shell sed -n 1p crc-builder/release-info) +CRC_BUILDER_V ?= v$(shell sed -n 2p crc-builder/release-info) +CRC_BUILDER_SAVE ?= crc-builder + +crc-builder-oci-build: CONTEXT=crc-builder/oci +crc-builder-oci-build: MANIFEST=$(CRC_BUILDER):$(CRC_BUILDER_V) +crc-builder-oci-build: + ${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) + ${CONTAINER_MANAGER} build -t $(MANIFEST)-windows -f $(CONTEXT)/Containerfile.non-linux --build-arg=OS=windows $(CONTEXT) + ${CONTAINER_MANAGER} build -t $(MANIFEST)-darwin -f $(CONTEXT)/Containerfile.non-linux --build-arg=OS=darwin $(CONTEXT) -oci-build: - $(call oci_builder,$(SNC_RUNNER),$(SNC_RUNNER_V),snc-runner) +crc-builder-oci-save: MANIFEST=$(CRC_BUILDER):$(CRC_BUILDER_V) +crc-builder-oci-save: + ${CONTAINER_MANAGER} save -o $(CRC_BUILDER_SAVE)-linux.tar $(MANIFEST)-linux + ${CONTAINER_MANAGER} save -o $(CRC_BUILDER_SAVE)-windows.tar $(MANIFEST)-windows + ${CONTAINER_MANAGER} save -o $(CRC_BUILDER_SAVE)-darwin.tar $(MANIFEST)-darwin + -oci-push: - $(call oci_pusher,$(SNC_RUNNER),$(SNC_RUNNER_V)) +crc-builder-oci-push: + ${CONTAINER_MANAGER} manifest push $(CRC_BUILDER):$(CRC_BUILDER_V)-linux + ${CONTAINER_MANAGER} push $(CRC_BUILDER):$(CRC_BUILDER_V)-windows + ${CONTAINER_MANAGER} push $(CRC_BUILDER):$(CRC_BUILDER_V)-darwin -tkn-create: - $(call tkn_creator,$(SNC_RUNNER),$(SNC_RUNNER_V),snc-runner) +# 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) \ No newline at end of file +# tkn-push: install-out-of-tree-tools +# $(call tkn_pusher,$(SNC_RUNNER),$(SNC_RUNNER_V),snc-runner) diff --git a/crc-builder/CHANGELOG.md b/crc-builder/CHANGELOG.md new file mode 100644 index 0000000..f92b139 --- /dev/null +++ b/crc-builder/CHANGELOG.md @@ -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 + + diff --git a/crc-builder/README.md b/crc-builder/README.md new file mode 100644 index 0000000..0153b76 --- /dev/null +++ b/crc-builder/README.md @@ -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//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//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- +``` + +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`._ + diff --git a/crc-builder/oci/Containerfile.linux b/crc-builder/oci/Containerfile.linux new file mode 100644 index 0000000..6c14f56 --- /dev/null +++ b/crc-builder/oci/Containerfile.linux @@ -0,0 +1,21 @@ +#8.10 +FROM quay.io/almalinuxorg/8-minimal@sha256:6c50656775e5971f7fb5e0d0d5b17f246873408a67b571ef720b7c1324118433 + +ARG TARGETARCH + +LABEL org.opencontainers.image.authors="CodeReady Containers " + +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 \ No newline at end of file diff --git a/crc-builder/oci/Containerfile.non-linux b/crc-builder/oci/Containerfile.non-linux new file mode 100644 index 0000000..a2293a8 --- /dev/null +++ b/crc-builder/oci/Containerfile.non-linux @@ -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 " + +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 \ No newline at end of file diff --git a/crc-builder/oci/lib/common.sh b/crc-builder/oci/lib/common.sh new file mode 100755 index 0000000..d25e713 --- /dev/null +++ b/crc-builder/oci/lib/common.sh @@ -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 +} \ No newline at end of file diff --git a/crc-builder/oci/lib/darwin/builder/build.sh b/crc-builder/oci/lib/darwin/builder/build.sh new file mode 100755 index 0000000..71df4cd --- /dev/null +++ b/crc-builder/oci/lib/darwin/builder/build.sh @@ -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 \ No newline at end of file diff --git a/crc-builder/oci/lib/darwin/entrypoint.sh b/crc-builder/oci/lib/darwin/entrypoint.sh new file mode 100755 index 0000000..fc60b4c --- /dev/null +++ b/crc-builder/oci/lib/darwin/entrypoint.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +source common.sh + +# Envs +if [ "${DEBUG:-}" = "true" ]; then + set -xuo +fi +if [[ ! validate_envs ]] || [[ ! validate_assets_info ]] || [[ ! validate_s3_configuration ]]; then + exit 1 +fi +SSH=$(ssh_cmd) +SCP=$(scp_cmd) + +# Create target on remote +echo "Create builder folder" +target_folder="/Users/${TARGET_HOST_USERNAME}" +$SSH "mkdir -p ${target_folder}" + +# Copy resources +echo "Copy resources to target" +connection_string=$(remote_connection) +$SCP ${BUILDER_RESOURCES} "${connection_string}:${target_folder}" + +# Run builder +echo "Running builder" +build_cmd="DATALAKE_URL=${DATALAKE_URL} DATALAKE_ACCESS_KEY=${DATALAKE_ACCESS_KEY} DATALAKE_SECRET_KEY=${DATALAKE_SECRET_KEY} " +if [[ ! -z ${CRC_SCM+x} ]]; then + build_cmd="${build_cmd} CRC_SCM=${CRC_SCM} " +fi +if [[ -z ${CRC_VERSION+x} ]]; then + if [[ ! -z ${CUSTOM_BUNDLE_VERSION_VARIABLE+x} ]]; then + build_cmd="${build_cmd} CUSTOM_BUNDLE_VERSION_VARIABLE=${CUSTOM_BUNDLE_VERSION_VARIABLE} " + fi + if [[ ! -z ${CUSTOM_BUNDLE_VERSION+x} ]]; then + build_cmd="${build_cmd} CUSTOM_BUNDLE_VERSION=${CUSTOM_BUNDLE_VERSION} " + fi + if [[ ! -z ${PULL_REQUEST+x} ]]; then + build_cmd="${build_cmd} CRC_SCM_PR=${PULL_REQUEST} " + fi + if [[ ! -z ${REF+x} ]]; then + build_cmd="${build_cmd} CRC_SCM_REF=${REF} " + fi +else + build_cmd="${build_cmd} CRC_VERSION=${CRC_VERSION} " +fi +# UPLOAD PATH, create it as local env and then pass to remote execution +# creating it as local we can pick the value from the task +UPLOAD_PATH="${UPLOAD_PATH:-"$(upload_path)"}" +build_cmd="${build_cmd} UPLOAD_PATH=${UPLOAD_PATH} " + +build_cmd="${build_cmd} ./build.sh" +$SSH "cd ${target_folder}/crc-builder && DEBUG=true ${build_cmd}" + +# Cleanup +echo "Cleanup target" +$SSH "sudo rm -fr ${target_folder}/crc-builder" \ No newline at end of file diff --git a/crc-builder/oci/lib/linux/entrypoint.sh b/crc-builder/oci/lib/linux/entrypoint.sh new file mode 100755 index 0000000..561afe3 --- /dev/null +++ b/crc-builder/oci/lib/linux/entrypoint.sh @@ -0,0 +1,111 @@ +#!/bin/bash + +# Imports +source ./common.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 +GOARCH=$(go env GOARCH) +CRC_SCM="${CRC_SCM:-"https://github.com/code-ready/crc.git"}" +CRC_SCM_REF="${CRC_SCM_REF:-"main"}" +LIBVIRT_DRIVER_SCM="${LIBVIRT_DRIVER_SCM:-"https://github.com/code-ready/machine-driver-libvirt.git"}" +ADMINHELPER_SCM="${ADMINHELPER_SCM:-"https://github.com/code-ready/admin-helper.git"}" +UPLOAD_PATH="${UPLOAD_PATH:-"$(upload_path)"}" + +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-linux-${GOARCH}.tar.xz" "datalake/${1}/crc-linux-${GOARCH}.tar.xz" + mc cp "${2}/sha256sum.txt" "datalake/${1}/crc-linux-${GOARCH}.tar.xz.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 + 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 hyperkit driver +git clone ${LIBVIRT_DRIVER_SCM} +pushd machine-driver-libvirt +mdl_version_line=$(cat pkg/libvirt/constants.go | grep DriverVersion) +mdl_version=${mdl_version_line##*=} +mdl_version=$(echo $mdl_version | xargs) +go build -v -o crc-driver-libvirt-local ./cmd/machine-driver-libvirt +popd + +# 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/linux-${GOARCH}/crc-admin-helper VERSION=$admin_version + +# Build linux distributable with custom admin helper +pushd crc +mkdir custom_embedded +cp ./../machine-driver-libvirt/crc-driver-libvirt-local custom_embedded/crc-driver-libvirt-${GOARCH} +cp ./../admin-helper/out/linux-${GOARCH}/crc-admin-helper custom_embedded/crc-admin-helper-linux-${GOARCH} +# Match admin-helper version with latest from master head +sed -i "s/crcAdminHelperVersion.*=.*/crcAdminHelperVersion = \"${admin_version}\"\n/g" pkg/crc/version/version.go +# Match machine-driver-libvirt version with latest from master head +sed -i "s/MachineDriverVersion =.*/MachineDriverVersion = \"${mdl_version}\"/g" pkg/crc/machine/libvirt/constants.go +make linux-release CUSTOM_EMBED=true EMBED_DOWNLOAD_DIR=custom_embedded +# make release CUSTOM_EMBED=true EMBED_DOWNLOAD_DIR=custom_embedded +popd + +# Upload +s3_upload ${UPLOAD_PATH} crc/release \ No newline at end of file diff --git a/crc-builder/oci/lib/windows/builder/build.ps1 b/crc-builder/oci/lib/windows/builder/build.ps1 new file mode 100644 index 0000000..b2dceb4 --- /dev/null +++ b/crc-builder/oci/lib/windows/builder/build.ps1 @@ -0,0 +1,131 @@ +# Script to be executed on windows machine to build a crc windows installer +# and upload it to s3 compatible storage +param( + [Parameter(HelpMessage='When build based on a custom bundle need to set type: PODMAN_VERSION or OPENSHIFT_VERSION')] + $customBundleVersionVariable, + [Parameter(HelpMessage='When build based on a custom bundle need to set version')] + $customBundleVersion, + [Parameter(HelpMessage='crc scm')] + $crcSCM="https://github.com/code-ready/crc.git", + [Parameter(HelpMessage='Optional parameter to build an specific PR for crc')] + $crcSCMPR, + # Review this one + [Parameter(HelpMessage='Optinal crc version to build an specfic')] + $crcVersion, + [Parameter(HelpMessage='crc scm ref')] + $crcSCMRef="main", + [Parameter(HelpMessage='upload path on remote storage where upload the artifacts')] + $uploadPath, + [Parameter(Mandatory,HelpMessage='url for remote s3 compatible storage where build bits will be stored')] + $datalakeURL, + [Parameter(Mandatory,HelpMessage='remote s3 credential ')] + $datalakeAcessKey, + [Parameter(Mandatory,HelpMessage='remote s3 credential')] + $datalakeSecretKey +) + +# Upload content to S3 compatible +# $1 remote path +# $2 local path to be uploaded +function S3-Upload($uploadPath, $localPath) { + + .\mc.exe alias set datalake $datalakeURL ` + $datalakeAcessKey ` + $datalakeSecretKey ` + --api S3v4 + + # Create bucket if not exits + .\mc.exe mb "datalake/$uploadPath" + # Copy files to datalake + .\mc.exe cp "$localPath/crc-windows-installer.zip" "datalake/$uploadPath/crc-windows-installer.zip" + .\mc.exe cp "$localPath/crc-windows-installer.zip.sha256sum" "datalake/$uploadPath/crc-windows-installer.zip.sha256sum" + # Make bucket public + # .\mc.exe anonymous set public "datalake/$uploadPath/" +} + +function Get-UploadPath($crcVersion, $crcSCMPR, $crcSCMRef) { + $path="distributables/app" + if (([string]::IsNullOrEmpty($crcVersion))) { + if (-not ([string]::IsNullOrEmpty($crcSCMPR))) { + return "$path/pr-$crcSCMPR" + } else { + return "$path/$crcSCMRef" + } + } else { + return "$path/release/$crcVersion" + } +} + +####################### +####### 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 $crcSCM + +pushd crc +# Fetch according to parameters provided +if (! $PSBoundParameters.ContainsKey('crcVersion')) { + $crcVersionPartial=Get-Date -format "yy.MM.dd" + if ($PSBoundParameters.ContainsKey('crcSCMPR')) { + git fetch origin pull/$crcSCMPR/head:pr-$crcSCMPR + git checkout pr-$crcSCMPR + } else { + git checkout $crcSCMRef + } + # In case we build for a custom bundle we need to match the version + # if ($PSBoundParameters.ContainsKey('customBundleVersionVariable') -And $PSBoundParameters.ContainsKey('customBundleVersion')) { + # (Get-Content -path Makefile) ` + # -replace "$customBundleVersionVariable \?= .*","$customBundleVersionVariable ?= $customBundleVersion" ` + # | Set-Content -path Makefile + # } + (Get-Content -path Makefile) ` + -replace 'CRC_VERSION = .*',"CRC_VERSION = $crcVersionPartial" ` + | Set-Content -path Makefile +} +else { + git checkout "v$crcVersion" +} +popd + +# Build admin-helper +git clone https://github.com/code-ready/admin-helper.git +$admin_version=$((cat admin-helper/crc-admin-helper.spec.in | Select-String -Pattern 'Version:') -split ':')[1].Trim() +make -C admin-helper out/windows-amd64/crc-admin-helper.exe VERSION=$admin_version + +# Build win32-background-launcher +git clone https://github.com/crc-org/win32-background-launcher.git +$wbl_version=$((cat win32-background-launcher/Makefile | Select-String -Pattern 'VERSION :=') -split '=')[1].Trim() +make -C win32-background-launcher win32-background-launcher + +# Build msi +pushd crc +mkdir custom_embedded +cp ./../admin-helper/out/windows-amd64/crc-admin-helper.exe custom_embedded/crc-admin-helper-windows.exe +cp ./../win32-background-launcher/bin/win32-background-launcher.exe custom_embedded/win32-background-launcher.exe + +# Match admin-helper version with latest from master head +$content = Get-Content pkg/crc/version/version.go +$oldAdminHelperVersion = $content | Select-String "crcAdminHelperVersion " | Select-Object -ExpandProperty Line +$newAdminHelperVersion="crcAdminHelperVersion = `"$admin_version`"" +$content -replace $oldAdminHelperVersion,$newAdminHelperVersion | Set-Content pkg/crc/version/version.go + +# Match win32-background-launcher version with latest from master head +$content = Get-Content pkg/crc/version/version.go +$oldWBLVersion = $content | Select-String "win32BackgroundLauncherVersion " | Select-Object -ExpandProperty Line +$newWBLVersion="win32BackgroundLauncherVersion = `"$wbl_version`"" +$content -replace $oldWBLVersion,$newWBLVersion | Set-Content pkg/crc/version/version.go + +make out/windows-amd64/crc-windows-installer.zip CUSTOM_EMBED=true EMBED_DOWNLOAD_DIR=custom_embedded +popd + +# Export +if (! $PSBoundParameters.ContainsKey('uploadPath')) { + $uploadPath=Get-UploadPath $crcVersion $crcSCMPR $crcSCMRef +} +S3-Upload $uploadPath crc/out/windows-amd64 \ No newline at end of file diff --git a/crc-builder/oci/lib/windows/entrypoint.sh b/crc-builder/oci/lib/windows/entrypoint.sh new file mode 100755 index 0000000..0637de7 --- /dev/null +++ b/crc-builder/oci/lib/windows/entrypoint.sh @@ -0,0 +1,57 @@ +#!/bin/sh + +source common.sh + +# Envs +if [ "${DEBUG:-}" = "true" ]; then + set -xuo +fi +if [[ ! validate_envs ]] || [[ ! validate_assets_info ]] || [[ ! validate_s3_configuration ]]; then + exit 1 +fi +SSH=$(ssh_cmd) +SCP=$(scp_cmd) + +# Create target on remote +echo "Create builder folder" +target_folder="/Users/${TARGET_HOST_USERNAME}" +$SSH "powershell.exe -c New-Item -ItemType directory -Path ${target_folder}" + +# Copy resources +echo "Copy resources to target" +connection_string=$(remote_connection) +$SCP ${BUILDER_RESOURCES} "${connection_string}:${target_folder}" + +# Run builder +echo "Running builder" +build_cmd=".\build.ps1 -datalakeURL ${DATALAKE_URL} -datalakeAcessKey ${DATALAKE_ACCESS_KEY} -datalakeSecretKey ${DATALAKE_SECRET_KEY} " +if [[ ! -z ${CRC_SCM+x} ]]; then + build_cmd="${build_cmd} -crcSCM ${CRC_SCM} " +fi +if [[ -z ${CRC_VERSION+x} ]]; then + if [[ ! -z ${CUSTOM_BUNDLE_VERSION_VARIABLE+x} ]]; then + build_cmd="${build_cmd} -customBundleVersionVariable ${CUSTOM_BUNDLE_VERSION_VARIABLE} " + fi + if [[ ! -z ${CUSTOM_BUNDLE_VERSION+x} ]]; then + build_cmd="${build_cmd} -customBundleVersion ${CUSTOM_BUNDLE_VERSION} " + fi + if [[ ! -z ${PULL_REQUEST+x} ]]; then + build_cmd="${build_cmd} -crcSCMPR ${PULL_REQUEST} " + fi + if [[ ! -z ${REF+x} ]]; then + build_cmd="${build_cmd} -crcSCMRef ${REF} " + fi +else + build_cmd="${build_cmd} -crcVersion ${CRC_VERSION} " +fi + +# UPLOAD PATH, create it as local env and then pass to remote execution +# creating it as local we can pick the value from the task +UPLOAD_PATH="${UPLOAD_PATH:-"$(upload_path)"}" +build_cmd="${build_cmd} -uploadPath ${UPLOAD_PATH} " + +$SSH "cd ${target_folder}/crc-builder; ${build_cmd}" + +# Cleanup +echo "Cleanup target" +$SSH "rm -r ${target_folder}/crc-builder -Force" \ No newline at end of file diff --git a/crc-builder/release-info b/crc-builder/release-info new file mode 100644 index 0000000..6eb914e --- /dev/null +++ b/crc-builder/release-info @@ -0,0 +1,2 @@ +quay.io/crcont/ci-crc-builder +1.0.0-dev \ No newline at end of file diff --git a/crc-builder/tkn/samples/linux-with-custom-bundle.yaml b/crc-builder/tkn/samples/linux-with-custom-bundle.yaml new file mode 100644 index 0000000..e304c9f --- /dev/null +++ b/crc-builder/tkn/samples/linux-with-custom-bundle.yaml @@ -0,0 +1,25 @@ +--- +apiVersion: tekton.dev/v1beta1 +kind: TaskRun +metadata: + generateName: crc-builder- +spec: + taskRef: + name: crc-builder + params: + - name: custom-bundle-version-variable + value: OPENSHIFT_VERSION + - name: custom-bundle-version + value: 4.13.0-ec.2 + - name: s3-url + value: https://s3.amazonaws.com + - name: s3-access-key + value: XXXX + - name: s3-secret-key + value: XXXXX + - name: s3-folder-path + value: crcqe-asia/nightly/ocp/4.13.0-ec.2 + - name: s3-download-url + value: crcqe-asia/nightly/ocp/4.13.0-ec.2 + timeout: 90m + \ No newline at end of file diff --git a/crc-builder/tkn/samples/macos-from-pr.yaml b/crc-builder/tkn/samples/macos-from-pr.yaml new file mode 100644 index 0000000..9f48865 --- /dev/null +++ b/crc-builder/tkn/samples/macos-from-pr.yaml @@ -0,0 +1,16 @@ +--- +apiVersion: tekton.dev/v1beta1 +kind: TaskRun +metadata: + generateName: crc-builder-installer-macos- +spec: + taskRef: + name: crc-builder-installer + params: + - name: platform + value: macos + - name: crc-scm-pr + value: '2971' + - name: host-config-secret + value: host-mac-1-brno + timeout: 90m diff --git a/crc-builder/tkn/samples/windows-from-master.yaml b/crc-builder/tkn/samples/windows-from-master.yaml new file mode 100644 index 0000000..8cf8613 --- /dev/null +++ b/crc-builder/tkn/samples/windows-from-master.yaml @@ -0,0 +1,24 @@ +--- +apiVersion: tekton.dev/v1beta1 +kind: TaskRun +metadata: + generateName: crc-builder-installer-windows- +spec: + taskRef: + name: crc-builder-installer + params: + # - name: crc-scm + # value: https://github.com/adrianriobo/crc.git + # - name: crc-scm-ref + # value: msi_hyperv_group + - name: platform + value: windows + - name: host-config-secret + value: host-windows-1-blr + - name: tray-url + value: https://github.com/crc-org/tray-electron/releases/download/1.2.9/crc-tray-windows.zip + timeout: 90m + + + + diff --git a/crc-builder/tkn/tpl/crc-builder-installer.tpl.yaml b/crc-builder/tkn/tpl/crc-builder-installer.tpl.yaml new file mode 100644 index 0000000..a7e1a84 --- /dev/null +++ b/crc-builder/tkn/tpl/crc-builder-installer.tpl.yaml @@ -0,0 +1,133 @@ +--- +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: crc-builder-installer + labels: + app.kubernetes.io/version: "0.0.7" + redhat.com/product: openshift-local + dev.lifecycle.io/phase: build + openshift-local.redhat.com/component: installer + annotations: + tekton.dev/pipelines.minVersion: "0.24.x" + tekton.dev/categories: installer + tekton.dev/tags: openshift-local, installer + tekton.dev/displayName: "openshift local installer" + tekton.dev/platforms: "linux/amd64" +spec: + description: >- + This task will build openshift local installers + + params: + - name: crc-scm + default: "''" + - name: crc-scm-pr + default: "''" + - name: crc-scm-ref + default: main + - name: custom-bundle-version-variable + description: | + When building an installer based on a custom bundle it is required + to manipulate the Makefile to match the custom version. + Current variables holding bundle version based on bundle type are + * OPENSHIFT_VERSION + * PODMAN_VERSION + default: "''" + - name: custom-bundle-version + default: "''" + - name: os + description: valid values are macos and windows + - name: host-config-secret + description: secret holding a host config + - name: s3-url + - name: s3-access-key + - name: s3-secret-key + - name: s3-folder-path + - name: s3-download-url + + results: + - name: downloadable-base-url + description: base url where the installer and the shasumfile can be downloaded + - name: distributable-name + description: distributable file name for the installer + - name: shasumfile + description: shasumfile name + + volumes: + - name: host-connection + secret: + secretName: $(params.host-config-secret) + + steps: + - name: crc-executable-builder + image: quay.io/rhqp/crc-builder:v0.0.7-$(params.os) + imagePullPolicy: Always + volumeMounts: + - mountPath: /opt/host/ + name: host-connection + script: | + #!/bin/sh + + # Copy key to connect to machine + cp /opt/host/key id_rsa + chmod 600 id_rsa + + # Run builder on target machine + TARGET_HOST=$(cat /opt/host/host) + TARGET_HOST_USERNAME=$(cat /opt/host/user) + TARGET_HOST_KEY_PATH=id_rsa + # sanitizing permissions for the key + chmod 600 ${TARGET_HOST_KEY_PATH} + + DATALAKE_URL=$(params.s3-url) + DATALAKE_ACCESS_KEY=$(params.s3-access-key) + DATALAKE_SECRET_KEY=$(params.s3-secret-key) + UPLOAD_PATH=$(params.s3-folder-path) + + # Optionals + if [[ $(params.crc-scm) != "" ]]; then + CRC_SCM=$(params.crc-scm) + fi + if [[ $(params.crc-scm-pr) != "" ]]; then + PULL_REQUEST=$(params.crc-scm-pr) + fi + if [[ $(params.crc-scm-ref) != "" ]]; then + REF=$(params.crc-scm-ref) + fi + if [[ $(params.custom-bundle-version-variable) != "" ]]; then + CUSTOM_BUNDLE_VERSION_VARIABLE=$(params.custom-bundle-version-variable) + fi + if [[ $(params.custom-bundle-version) != "" ]]; then + CUSTOM_BUNDLE_VERSION=$(params.custom-bundle-version) + fi + + # set -exuo pipefail + + # Build installer + . entrypoint.sh + + echo -n "$(params.s3-download-url)" \ + | tee $(results.downloadable-base-url.path) + case "$(params.os)" in + macos|darwin) + echo -n "crc-macos-installer.pkg" | tee $(results.distributable-name.path) + echo -n "crc-macos-installer.pkg.sha256sum" | tee $(results.shasumfile.path) + ;; + windows) + echo -n "crc-windows-installer.zip" | tee $(results.distributable-name.path) + echo -n "crc-windows-installer.zip.sha256sum" | tee $(results.shasumfile.path) + ;; + *) + echo -n "" | tee $(results.distributable-name.path) + echo -n "" | tee $(results.shasumfile.path) + ;; + esac + + resources: + requests: + memory: 150Mi + cpu: 90m + limits: + memory: 270Mi + cpu: 150m + timeout: 90m \ No newline at end of file diff --git a/crc-builder/tkn/tpl/crc-builder.tpl.yaml b/crc-builder/tkn/tpl/crc-builder.tpl.yaml new file mode 100644 index 0000000..1ba6415 --- /dev/null +++ b/crc-builder/tkn/tpl/crc-builder.tpl.yaml @@ -0,0 +1,102 @@ +--- +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: crc-builder + labels: + app.kubernetes.io/version: "0.0.6" + redhat.com/product: openshift-local + dev.lifecycle.io/phase: build + openshift-local.redhat.com/component: binary + annotations: + tekton.dev/pipelines.minVersion: "0.24.x" + tekton.dev/categories: binary + tekton.dev/tags: openshift-local, binary, linux + tekton.dev/displayName: "openshift local linux binary" + tekton.dev/platforms: "linux/amd64" +spec: + description: >- + This task will build openshift local binary for linux distributions + + params: + - name: crc-scm + default: https://github.com/code-ready/crc.git + - name: crc-scm-pr + default: "''" + - name: crc-scm-ref + default: main + - name: custom-bundle-version-variable + description: | + When building an installer based on a custom bundle it is required + to manipulate the Makefile to match the custom version. + Current variables holding bundle version based on bundle type are + * OPENSHIFT_VERSION + * PODMAN_VERSION + default: "''" + - name: custom-bundle-version + default: "''" + - name: s3-url + - name: s3-access-key + - name: s3-secret-key + - name: s3-folder-path + - name: s3-download-url + + results: + - name: downloadable-base-url + description: base url where the installer and the shasumfile can be downloaded + - name: distributable-name + description: distributable file name for the installer + - name: shasumfile + description: shasumfile name + + steps: + - name: build + image: quay.io/rhqp/crc-builder:v0.0.7-linux + imagePullPolicy: Always + script: | + #!/bin/sh + DATALAKE_URL=$(params.s3-url) + DATALAKE_ACCESS_KEY=$(params.s3-access-key) + DATALAKE_SECRET_KEY=$(params.s3-secret-key) + + # Optionals + if [[ $(params.crc-scm) != "" ]]; then + CRC_SCM=$(params.crc-scm) + fi + if [[ $(params.crc-scm-pr) != "" ]]; then + CRC_SCM_PR=$(params.crc-scm-pr) + fi + if [[ $(params.crc-scm-ref) != "" ]]; then + CRC_SCM_REF=$(params.crc-scm-ref) + fi + if [[ $(params.custom-bundle-version-variable) != "" ]]; then + CUSTOM_BUNDLE_VERSION_VARIABLE=$(params.custom-bundle-version-variable) + fi + if [[ $(params.custom-bundle-version) != "" ]]; then + CUSTOM_BUNDLE_VERSION=$(params.custom-bundle-version) + fi + if [[ $(params.s3-folder-path) != "" ]]; then + UPLOAD_PATH=$(params.s3-folder-path) + fi + + # Build installer + DEBUG=true + . entrypoint.sh + + if [[ $? -ne 0 ]]; then + exit 1 + fi + + # From entrypoint we can get UPLOAD_PATH env with the target bucket + echo -n "$(params.s3-download-url)/${UPLOAD_PATH}" | tee $(results.downloadable-base-url.path) + # Linux generated files + echo -n "crc-linux-amd64.tar.xz" | tee $(results.distributable-name.path) + echo -n "crc-linux-amd64.tar.xz.sha256sum" | tee $(results.shasumfile.path) + resources: + requests: + memory: 450Mi + cpu: 250m + limits: + memory: 3800Mi + cpu: 1850m + timeout: 900m \ No newline at end of file diff --git a/snc-runner/release-info b/snc-runner/release-info index adcd6ee..90474e2 100644 --- a/snc-runner/release-info +++ b/snc-runner/release-info @@ -1,2 +1,2 @@ -quay.io/rhqp/snc-runner -2.0.0-dev \ No newline at end of file +quay.io/crcont/ci-snc-runner +1.0.0-dev \ No newline at end of file