diff --git a/.github/workflows/crc-support-builder.yaml b/.github/workflows/crc-support-builder.yaml new file mode 100644 index 0000000..0c08e5e --- /dev/null +++ b/.github/workflows/crc-support-builder.yaml @@ -0,0 +1,89 @@ +name: crc-support-builder + +on: + push: + tags: [ 'crc-support-v*' ] + pull_request: + branches: [ main ] + paths: ['Makefile', 'crc-support/**', '.github\/workflows\/crc-support*' ] + +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: + CRC_SUPPORT: ghcr.io/crc-org/ci-crc-support + CRC_SUPPORT_V: pr-${{ github.event.number }} + run: | + make crc-support-oci-build + make crc-support-oci-save + echo "image=${CRC_SUPPORT}:${CRC_SUPPORT_V}" >> "$GITHUB_ENV" + + - name: Build image for Release + if: ${{ github.event_name == 'push' }} + run: | + make crc-support-oci-build + make crc-support-oci-save + echo "image=$(sed -n 1p crc-support/release-info):v$(sed -n 2p crc-support/release-info)" >> "$GITHUB_ENV" + + - name: Create image metadata + run: | + echo ${{ env.image }} > crc-support-image + echo ${{ github.event_name }} > crc-support-build-event + + - name: Upload crc-support + uses: actions/upload-artifact@v4 + with: + name: crc-support + path: crc-support* + + tkn-check: + runs-on: ubuntu-24.04 + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Template tkn for PR + if: ${{ github.event_name == 'pull_request' }} + env: + CRC_SUPPORT: ghcr.io/crc-org/ci-crc-support + CRC_SUPPORT_V: pr-${{ github.event.number }} + run: | + make crc-support-tkn-create + + - name: Check tkn specs + run: | + if [[ ! -f crc-support/tkn/task.yaml ]]; then + exit 1 + fi + # Check if version is in sync + + - name: Create k8s Kind Cluster + uses: helm/kind-action@v1 + + # https://docs.openshift.com/pipelines/1.15/about/op-release-notes.html + - name: Deploy min supported tekton version + run: kubectl apply -f https://storage.googleapis.com/tekton-releases/pipeline/previous/v0.44.5/release.yaml + + - name: Deploy tasks + run: | + kubectl apply -f crc-support/tkn/task.yaml + + - name: Upload crc-support-tkn + uses: actions/upload-artifact@v4 + with: + name: crc-support-tkn + path: crc-support/tkn/crc-support* + + + + + + + \ No newline at end of file diff --git a/.github/workflows/crc-support-pusher.yml b/.github/workflows/crc-support-pusher.yml new file mode 100644 index 0000000..82aaf57 --- /dev/null +++ b/.github/workflows/crc-support-pusher.yml @@ -0,0 +1,74 @@ +name: crc-support-pusher + +on: + workflow_run: + workflows: [ 'crc-support-builder' ] + types: + - completed + +jobs: + push: + name: push + if: ${{ github.event.workflow_run.conclusion == 'success' }} + runs-on: ubuntu-24.04 + permissions: + contents: read + packages: write + steps: + - name: Download crc-support assets + uses: actions/download-artifact@v4 + with: + name: crc-support + run-id: ${{ github.event.workflow_run.id }} + github-token: ${{ github.token }} + + - name: Get crc-support build informaiton + run: | + echo "source_event=$(cat crc-support-build-event)" >> "$GITHUB_ENV" + echo "image=$(cat crc-support-image)" >> "$GITHUB_ENV" + + - name: Log in to ghcr.io + 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 quay.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 crc-support + run: | + # Load + podman load -i crc-support-linux.tar + podman load -i crc-support-windows.tar + podman load -i crc-support-darwin.tar + # Push + podman push ${{ env.image }}-linux + podman push ${{ env.image }}-windows + podman push ${{ env.image }}-darwin + + - name: Download crc-support-tkn assets + uses: actions/download-artifact@v4 + with: + name: crc-support-tkn + run-id: ${{ github.event.workflow_run.id }} + github-token: ${{ github.token }} + + - name: Push crc-support-tkn + env: + TKN_VERSION: '0.37.0' + run: | + curl -LO "https://github.com/tektoncd/cli/releases/download/v${TKN_VERSION}/tkn_${TKN_VERSION}_Linux_x86_64.tar.gz" + tar xvzf "tkn_${TKN_VERSION}_Linux_x86_64.tar.gz" tkn + ./tkn bundle push ${{ env.image }}-tkn \ + -f crc-support-installer.yaml \ + -f crc-support.yaml + + \ No newline at end of file diff --git a/Makefile b/Makefile index 89c58a2..ea17f39 100644 --- a/Makefile +++ b/Makefile @@ -107,4 +107,46 @@ endif -f crc-builder/tkn/crc-builder-installer.yaml \ -f crc-builder/tkn/crc-builder.yaml \ -f crc-builder/tkn/crc-builder-arm64.yaml - \ No newline at end of file + +#### crc-support #### + +.PHONY: crc-support-oci-build crc-support-oci-save crc-support-oci-load crc-support-oci-push crc-support-tkn-create crc-support-tkn-push + +# Registries and versions +CRC_SUPPORT ?= $(shell sed -n 1p crc-support/release-info) +CRC_SUPPORT_V ?= v$(shell sed -n 2p crc-support/release-info) +CRC_SUPPORT_SAVE ?= crc-support + +crc-support-oci-build: CONTEXT=crc-support/oci +crc-support-oci-build: MANIFEST=$(CRC_SUPPORT):$(CRC_SUPPORT_V) +crc-support-oci-build: + ${CONTAINER_MANAGER} build -t $(MANIFEST)-linux -f $(CONTEXT)/Containerfile --build-arg=OS=linux $(CONTEXT) + ${CONTAINER_MANAGER} build -t $(MANIFEST)-windows -f $(CONTEXT)/Containerfile --build-arg=OS=windows $(CONTEXT) + ${CONTAINER_MANAGER} build -t $(MANIFEST)-darwin -f $(CONTEXT)/Containerfile --build-arg=OS=darwin $(CONTEXT) + +crc-support-oci-save: MANIFEST=$(CRC_SUPPORT):$(CRC_SUPPORT_V) +crc-support-oci-save: + ${CONTAINER_MANAGER} save -o $(CRC_SUPPORT_SAVE)-linux.tar $(MANIFEST)-linux + ${CONTAINER_MANAGER} save -o $(CRC_SUPPORT_SAVE)-windows.tar $(MANIFEST)-windows + ${CONTAINER_MANAGER} save -o $(CRC_SUPPORT_SAVE)-darwin.tar $(MANIFEST)-darwin + +crc-support-oci-load: + ${CONTAINER_MANAGER} load -i $(CRC_SUPPORT_SAVE)-linux.tar + ${CONTAINER_MANAGER} load -i $(CRC_SUPPORT_SAVE)-windows.tar + ${CONTAINER_MANAGER} load -i $(CRC_SUPPORT_SAVE)-darwin.tar + +crc-support-oci-push: MANIFEST=$(CRC_SUPPORT):$(CRC_SUPPORT_V) +crc-support-oci-push: + ${CONTAINER_MANAGER} push $(MANIFEST)-linux + ${CONTAINER_MANAGER} push $(MANIFEST)-windows + ${CONTAINER_MANAGER} push $(MANIFEST)-darwin + +crc-support-tkn-create: + $(call tkn_template,$(CRC_SUPPORT),$(CRC_SUPPORT_V),crc-support,task) + +crc-support-tkn-push: install-out-of-tree-tools +ifndef IMAGE + IMAGE = $(CRC_SUPPORT):$(CRC_SUPPORT_V) +endif + $(TOOLS_BINDIR)/tkn bundle push $(IMAGE)-tkn \ + -f crc-support/tkn/task.yaml \ No newline at end of file diff --git a/crc-support/README.md b/crc-support/README.md new file mode 100644 index 0000000..ff6c953 --- /dev/null +++ b/crc-support/README.md @@ -0,0 +1,7 @@ +# Overview + +crc-support component allows to manage remote operations to setup a environment for testing Openshift Local, it contains the scripts based on each target platform, and it basically manages: + +* Cleanup environments to ensure fresh installations +* Download bundles +* Download and install Openshift Local \ No newline at end of file diff --git a/crc-support/oci/Containerfile b/crc-support/oci/Containerfile new file mode 100644 index 0000000..67f2751 --- /dev/null +++ b/crc-support/oci/Containerfile @@ -0,0 +1,11 @@ +# main +FROM quay.io/rhqp/deliverest@sha256:6b42078f7a869d3b5c64dbac9bf84fe8080d15f6fde0d794713ad4a509eeacc5 + +LABEL org.opencontainers.image.authors="CRCQE " + +ARG OS + +ENV ASSETS_FOLDER=/opt/crc-support \ + OS=${OS} + +COPY /lib/${OS}/* ${ASSETS_FOLDER}/ diff --git a/crc-support/oci/lib/darwin/lib.sh b/crc-support/oci/lib/darwin/lib.sh new file mode 100755 index 0000000..ca26adf --- /dev/null +++ b/crc-support/oci/lib/darwin/lib.sh @@ -0,0 +1,36 @@ +#!/bin/sh + +# Remove any content from any previous crc installation +force_fresh_environment () { + crc cleanup 2>/dev/null + sudo kill -9 $(pgrep crc-tray | head -1) 2>/dev/null + sudo rm -rf /Applications/Red\ Hat\ OpenShift\ Local.app/ + sudo rm /usr/local/bin/crc + rm -rf ~/.crc/ +} + +# $1 file name for the asset to be checked +# $2 file name holding the shasum value +# Return 1 if true 0 false +required_download () { + if [[ ! -f ${1} ]]; then + return 1 + fi + cat ${2} | grep ${1} | shasum -a 256 -c - + return ${?} +} + +# $1 file name for the asset to be checked +# $2 file name holding the shasum value +# Return 1 if true 0 false +check_download() { + cat ${2} | grep ${1} | shasum -a 256 -c - + return ${?} +} + +# $1 file name for crc installer +installCRC() { + sudo installer -pkg ${1} -target / +} + + diff --git a/crc-support/oci/lib/darwin/run.sh b/crc-support/oci/lib/darwin/run.sh new file mode 120000 index 0000000..a353a4c --- /dev/null +++ b/crc-support/oci/lib/darwin/run.sh @@ -0,0 +1 @@ +./../unix/run.sh \ No newline at end of file diff --git a/crc-support/oci/lib/linux/lib.sh b/crc-support/oci/lib/linux/lib.sh new file mode 100755 index 0000000..4055f3d --- /dev/null +++ b/crc-support/oci/lib/linux/lib.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +# Remove any content from any previous crc installation +force_fresh_environment () { + crc cleanup + sudo rm -rf /usr/local/bin/crc + rm -rf ~/.crc/ +} + +# $1 file name for the asset to be checked +# $2 file name holding the shasum value +# Return 1 if true 0 false +required_download () { + if [[ ! -f ${1} ]]; then + return 1 + fi + cat ${2} | grep ${1} | sha256sum -c - + return ${?} + +} + +# $1 file name for the asset to be checked +# $2 file name holding the shasum value +# Return 1 if not valid, 0 if valid +check_download() { + cat ${2} | grep ${1} | sha256sum -c - + return ${?} +} + +# $1 file name for crc installer +installCRC() { + sudo tar xvf "${1}" --strip-components 1 -C /usr/local/bin/ +} diff --git a/crc-support/oci/lib/linux/run.sh b/crc-support/oci/lib/linux/run.sh new file mode 120000 index 0000000..a353a4c --- /dev/null +++ b/crc-support/oci/lib/linux/run.sh @@ -0,0 +1 @@ +./../unix/run.sh \ No newline at end of file diff --git a/crc-support/oci/lib/unix/run.sh b/crc-support/oci/lib/unix/run.sh new file mode 100755 index 0000000..887ea32 --- /dev/null +++ b/crc-support/oci/lib/unix/run.sh @@ -0,0 +1,119 @@ +#!/bin/sh + +SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) +source "${SCRIPT_DIR}/lib.sh" + +# Parameters +aBaseURL='' +aName='' +aSHAName='sha256sum.txt' +targetPath='' +freshEnv='true' +download='true' +install='false' +debug='false' + + +while [[ $# -gt 0 ]]; do + key="$1" + case $key in + -aBaseURL) + aBaseURL="$2" + shift + shift + ;; + -aName) + aName="$2" + shift + shift + ;; + -aSHAName) + aSHAName="$2" + shift + shift + ;; + -targetPath) + targetPath="$2" + shift + shift + ;; + -freshEnv) + freshEnv="$2" + shift + shift + ;; + -download) + download="$2" + shift + shift + ;; + -install) + install="$2" + shift + shift + ;; + -debug) + debug="$2" + shift + shift + ;; + *) # unknown option + shift + ;; + esac +done + +# $1 downloadle url +download () { + local binary_url="${1}" + local download_result=1 + while [[ ${download_result} -ne 0 ]] + do + curl --insecure -LO -C - ${binary_url} + download_result=$? + done +} + +############## +#### MAIN #### +############## +if [ "$debug" = "true" ]; then + set -xuo +fi + +# Ensure fresh environment +if [[ $freshEnv == 'true' ]]; then + echo "removing previous crc" + force_fresh_environment +fi + +# DOWNLOAD +if [[ $download == "true" ]]; then + echo "downlading $aName" + mkdir -p $targetPath + pushd $targetPath + # Download sha256sum + curl --insecure -LO "$aBaseURL/$aSHAName" + # Check if require download + required_download $aName $aSHAName + if [[ ${?} -ne 0 ]]; then + # Required to download + rm -f $aName + dURL="$aBaseURL/$aName" + download $dURL + check_download $aName $aSHAName + if [[ ${?} -ne 0 ]]; then + popd + echo "Error with downloading $aName" + exit 1 + fi + fi +fi + +# INSTALLATION +if [[ $install == 'true' ]]; then + echo "installing crc" + installCRC $aName +fi + +popd \ No newline at end of file diff --git a/crc-support/oci/lib/windows/run.ps1 b/crc-support/oci/lib/windows/run.ps1 new file mode 100644 index 0000000..65b5186 --- /dev/null +++ b/crc-support/oci/lib/windows/run.ps1 @@ -0,0 +1,150 @@ +aBaseURL='' +aName='' +aSHAName='sha256sum.txt' +targetPath='' +freshEnv='true' +download='true' +install='false' + + +param( + [Parameter(HelpMessage='download base url')] + $aBaseURL, + [Parameter(HelpMessage='asset name to be downloaded')] + $aName, + [Parameter(HelpMessage='shasumFile file name Default value: sha256sum.txt')] + $aSHAName="sha256sum.txt", + [Parameter(Mandatory,HelpMessage='target folder for download')] + $targetPath, + [Parameter(HelpMessage='force fresh, remove any previous existing instance for crc. Default False')] + $forceFresh='false', + [Parameter(HelpMessage='download if False not download. Default True')] + $download='true', + [Parameter(HelpMessage='install after downloading if False not install. Default False')] + $install='false' +) + +function Force-Fresh-Environment { + if (Get-Command crc -errorAction SilentlyContinue) + { + crc cleanup + + # Wait to be cleared before uninstalling + Pause-Until-Other-Installations-Finish + pushd $latestPath + Start-Process C:\Windows\System32\msiexec.exe -ArgumentList "/qb /x crc-windows-${arch}.msi /norestart" -wait + popd + } + Start-Process powershell -Verb runAs -ArgumentList "Remove-Item -Recurse -Force $HOME\.crc" + # Remove user from Hyper-V Administrator group + Start-Process powershell -Verb runAs -ArgumentList "Remove-LocalGroupMember -SID S-1-5-32-578 -Member $(whoami)" +} + +function Require-Download { + if (!(Test-Path $downloadItemName)) { + return $true + } + $hashValue=Get-FileHash $downloadItemName | Select-Object -ExpandProperty Hash + $hashMatch=Select-String $shasumFile -Pattern $hashValue -Quiet + return !$hashMatch +} + +function Download ($binaryURL) { + $isFinished=$false + while(!$isFinished) + { + curl.exe --insecure -LO -C - $binaryURL + $isFinished=$? + } +} + +function Check-Download() { + $hashValue=Get-FileHash $downloadItemName | Select-Object -ExpandProperty Hash + $hashMatch=Select-String $shasumFile -Pattern $hashValue -Quiet + return $hashMatch +} + +function Pause-Until-Other-Installations-Finish() { + do { + try{ + $failed = $false + $Mutex = [System.Threading.Mutex]::OpenExisting("Global\_MSIExecute"); + $Mutex.Dispose(); + Start-Sleep -Seconds 1 + } catch { + $failed = $true + } + } while ($failed -eq $false) +} + +############## +#### MAIN #### +############## + + +$latestPath="$HOME\OpenshiftLocal\crc\latest" + +# Transform params to bool +$install = If ($install -eq 'true') {$true} Else {$false} +$download = If ($download -eq 'true') {$true} Else {$false} +$forceFresh = If ($forceFresh -eq 'true') {$true} Else {$false} + +# FORCE FRESH +if ($forceFresh) { + Force-Fresh-Environment +} + +New-Item -Path $targetPath -ItemType Directory -Force +pushd $targetPath + +# DOWNLOAD +if ($download) { + # Download sha256sum + curl.exe --insecure -LO "$aBaseURL/$aSHAName" + # Check if require download + if (Require-Download $targetPath) { + if (Test-Path $aName) { + Remove-Item $aName + } + $distributableURL="$aBaseURL/$aName" + Download $distributableURL + $check=Check-Download + if (!$check) { + popd + Write-Host "Error with downloaded binary" + Exit + } + } +} + + +# INSTALLATION +if ($install) { + + Write-Host "preparing crc installation" + # Extract + Expand-Archive -LiteralPath $aName -DestinationPath $targetPath -Force + + # Ensure current as latest, next time we want to force fresh this msi will be + # used to uninstall + if (Test-Path $latestPath) { # Remove-Item fails if file does not exist + Remove-Item -Path $latestPath -Force -Recurse + } + New-Item -Path $latestPath -ItemType Directory -Force + Copy-Item -Path "$targetPath\*" -Destination $latestPath -Recurse + + # Waiting for other installers to finish + Write-Host "waiting for other installations to finish" + Pause-Until-Other-Installations-Finish + # Install + Write-Host "installing crc" + Start-Process C:\Windows\System32\msiexec.exe -ArgumentList "/qb /i crc-windows-amd64.msi /norestart" -wait + # Restart-Computer -Force + # Run restart from powershell with privileges + Write-Host "restarting host" + Start-Process powershell -verb runas -ArgumentList "Restart-Computer -Force" -wait + # Workaround on non required reboot contolled env + #$Env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") +} + +popd diff --git a/crc-support/release-info b/crc-support/release-info new file mode 100644 index 0000000..ab1b373 --- /dev/null +++ b/crc-support/release-info @@ -0,0 +1,2 @@ +quay.io/crc-org/ci-crc-support +1.0.0-dev \ No newline at end of file diff --git a/crc-support/tkn/task.yaml b/crc-support/tkn/task.yaml new file mode 100644 index 0000000..c0311e8 --- /dev/null +++ b/crc-support/tkn/task.yaml @@ -0,0 +1,141 @@ +--- +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: crc-support + labels: + app.kubernetes.io/version: "v1.0.0-dev" + redhat.com/product: openshift-local + dev.lifecycle.io/phase: testing + annotations: + tekton.dev/pipelines.minVersion: "0.44.x" + tekton.dev/categories: "openshift-local" + tekton.dev/tags: "openshift-local, testing" + tekton.dev/platforms: "linux/amd64" +spec: + description: >- + This task will prepare a target host with valid openshift local related assets + + It will download and install an specific Openshift Local version or can be used to download a specific bundle + + workspaces: + - name: host-info + description: | + ocp secret holding the hsot info credentials. Secret should be accessible to this task. + --- + apiVersion: v1 + kind: Secret + metadata: + name: XXXX + labels: + app.kubernetes.io/component: XXXX + type: Opaque + data: + host: XXXX + user: XXXX + password: XXXX + key: XXXX + platform: XXXX + os-version: XXXX + arch: XXXX + os: XXXX + mountPath: /opt/host/ + + params: + # OS parameter + - name: os + description: type of platform per target host (windows, darwin or linux). Default linux + default: linux + # Assets parameter + - name: asset-base-url + description: base url for the asset to be downloaded + - name: asset-name + description: name for the asset to be downloaded + - name: asset-shasum-name + description: file name for shasum to check asset + default: sha256sum.txt + - name: crc-version + description: Optional parameter to give info about crc version managed as version is not present within the asset name. + # Main stands for version being built from main of the head + default: main + # Control parameters + - name: download + description: controls if preparer will download the element + default: 'true' + - name: install + description: controls if preparer will install. (In case of distriutable) + default: 'true' + - name: force-fresh + description: controls if preparer will remove any previous existing crc version + default: 'true' + - name: debug + description: increase verbosity + default: 'false' + + results: + - name: target-path + description: Path on target host where the item has been dowloaded + + steps: + - name: preparer + image: quay.io/crc-org/ci-crc-support:v1.0.0-dev-$(params.os) + imagePullPolicy: Always + script: | + #!/bin/bash + + if [ "$(params.debug)" = "true" ]; then + set -xuo + fi + + # Prepare ENVs + SECONDS=0 + DEBUG=$(params.debug) + TARGET_HOST=$(cat /opt/host/host) + TARGET_HOST_USERNAME=$(cat /opt/host/user) + cp /opt/host/key id_rsa + chmod 600 id_rsa + TARGET_HOST_KEY_PATH=id_rsa + TARGET_FOLDER=crc-support-$RANDOM$RANDOM + TARGET_CLEANUP='true' + + # Create cmd per OS + runner="run.sh" + if [[ $(params.os) == "windows" ]]; then + runner="run.ps1" + fi + # Path for assets on remote target + tPath='/Users/${TARGET_HOST_USERNAME}/OpenshiftLocal' + if [[ $(params.os) == 'linux' ]]; then + tPath="/home/${TARGET_HOST_USERNAME}/OpenshiftLocal" + fi + if [[ $(params.asset-name) == *'.crcbundle' ]]; then + # It is bundle + nameArr=(${name//_/ }) + tPath+='/bundle/${nameArr[2]}' + else + tPath+='/crc/$(params.crc-version)' + fi + + cmd="${TARGET_FOLDER}/${runner} -targetPath $tPath " + cmd+="-aBaseURL $(params.asset-base-url) " + cmd+="-aName $(params.asset-name) " + cmd+="-aSHAName $(params.asset-shasum-name) " + cmd+="-freshEnv $(params.force-fresh) " + cmd+="-download $(params.download) " + cmd+="-install $(params.install) " + cmd+="-debug $(params.debug) " + + # Exec + . entrypoint.sh "${cmd}" + + # Results + echo -n "$tPath" | tee $(results.target-path.path) + + resources: + requests: + memory: "100Mi" + cpu: "50m" + limits: + memory: "140Mi" + cpu: "100m" + \ No newline at end of file diff --git a/crc-support/tkn/tpl/task.tpl.yaml b/crc-support/tkn/tpl/task.tpl.yaml new file mode 100644 index 0000000..ae3a74a --- /dev/null +++ b/crc-support/tkn/tpl/task.tpl.yaml @@ -0,0 +1,141 @@ +--- +apiVersion: tekton.dev/v1beta1 +kind: Task +metadata: + name: crc-support + labels: + app.kubernetes.io/version: "cversion" + redhat.com/product: openshift-local + dev.lifecycle.io/phase: testing + annotations: + tekton.dev/pipelines.minVersion: "0.44.x" + tekton.dev/categories: "openshift-local" + tekton.dev/tags: "openshift-local, testing" + tekton.dev/platforms: "linux/amd64" +spec: + description: >- + This task will prepare a target host with valid openshift local related assets + + It will download and install an specific Openshift Local version or can be used to download a specific bundle + + workspaces: + - name: host-info + description: | + ocp secret holding the hsot info credentials. Secret should be accessible to this task. + --- + apiVersion: v1 + kind: Secret + metadata: + name: XXXX + labels: + app.kubernetes.io/component: XXXX + type: Opaque + data: + host: XXXX + user: XXXX + password: XXXX + key: XXXX + platform: XXXX + os-version: XXXX + arch: XXXX + os: XXXX + mountPath: /opt/host/ + + params: + # OS parameter + - name: os + description: type of platform per target host (windows, darwin or linux). Default linux + default: linux + # Assets parameter + - name: asset-base-url + description: base url for the asset to be downloaded + - name: asset-name + description: name for the asset to be downloaded + - name: asset-shasum-name + description: file name for shasum to check asset + default: sha256sum.txt + - name: crc-version + description: Optional parameter to give info about crc version managed as version is not present within the asset name. + # Main stands for version being built from main of the head + default: main + # Control parameters + - name: download + description: controls if preparer will download the element + default: 'true' + - name: install + description: controls if preparer will install. (In case of distriutable) + default: 'true' + - name: force-fresh + description: controls if preparer will remove any previous existing crc version + default: 'true' + - name: debug + description: increase verbosity + default: 'false' + + results: + - name: target-path + description: Path on target host where the item has been dowloaded + + steps: + - name: preparer + image: cimage:cversion-$(params.os) + imagePullPolicy: Always + script: | + #!/bin/bash + + if [ "$(params.debug)" = "true" ]; then + set -xuo + fi + + # Prepare ENVs + SECONDS=0 + DEBUG=$(params.debug) + TARGET_HOST=$(cat /opt/host/host) + TARGET_HOST_USERNAME=$(cat /opt/host/user) + cp /opt/host/key id_rsa + chmod 600 id_rsa + TARGET_HOST_KEY_PATH=id_rsa + TARGET_FOLDER=crc-support-$RANDOM$RANDOM + TARGET_CLEANUP='true' + + # Create cmd per OS + runner="run.sh" + if [[ $(params.os) == "windows" ]]; then + runner="run.ps1" + fi + # Path for assets on remote target + tPath='/Users/${TARGET_HOST_USERNAME}/OpenshiftLocal' + if [[ $(params.os) == 'linux' ]]; then + tPath="/home/${TARGET_HOST_USERNAME}/OpenshiftLocal" + fi + if [[ $(params.asset-name) == *'.crcbundle' ]]; then + # It is bundle + nameArr=(${name//_/ }) + tPath+='/bundle/${nameArr[2]}' + else + tPath+='/crc/$(params.crc-version)' + fi + + cmd="${TARGET_FOLDER}/${runner} -targetPath $tPath " + cmd+="-aBaseURL $(params.asset-base-url) " + cmd+="-aName $(params.asset-name) " + cmd+="-aSHAName $(params.asset-shasum-name) " + cmd+="-freshEnv $(params.force-fresh) " + cmd+="-download $(params.download) " + cmd+="-install $(params.install) " + cmd+="-debug $(params.debug) " + + # Exec + . entrypoint.sh "${cmd}" + + # Results + echo -n "$tPath" | tee $(results.target-path.path) + + resources: + requests: + memory: "100Mi" + cpu: "50m" + limits: + memory: "140Mi" + cpu: "100m" + \ No newline at end of file