Skip to content

Commit

Permalink
DO NOT MERGE BEFORE REMOVE THIS COMMIT. TESTING PURPOSES
Browse files Browse the repository at this point in the history
Signed-off-by: Adrian Riobo <[email protected]>
  • Loading branch information
adrianriobo committed Nov 5, 2024
1 parent 8b9d808 commit 988dbe1
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 19 deletions.
4 changes: 2 additions & 2 deletions crc-support/oci/Containerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# v0.0.7
FROM quay.io/rhqp/deliverest@sha256:67ed1a47f1580141854c5baa742a50fc21920cf77d9d07eb798d7743508e52eb
# main
FROM quay.io/rhqp/deliverest@sha256:6b42078f7a869d3b5c64dbac9bf84fe8080d15f6fde0d794713ad4a509eeacc5

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

Expand Down
18 changes: 13 additions & 5 deletions crc-support/oci/lib/darwin/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,28 @@ force_fresh_environment () {
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 $aName ]]; then
if [[ ! -f ${1} ]]; then
return 1
fi
cat $aSHAName | grep $aName | shasum -a 256 -c -
cat ${2} | grep ${1} | shasum -a 256 -c -
return ${?}
}

# $1 downloadle url
# Return 1 if not valid, 0 if valid
# $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 $aSHAName | grep $aName | shasum -a 256 -c -
cat ${2} | grep ${1} | shasum -a 256 -c -
return ${?}
}

# $1 file name for crc installer
installCRC() {
sudo installer -pkg ${1} -target /
}


16 changes: 12 additions & 4 deletions crc-support/oci/lib/linux/lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,27 @@ force_fresh_environment () {
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 ${DOWNLOADED_ITEM_NAME} ]]; then
if [[ ! -f ${1} ]]; then
return 1
fi
cat ${SHASUM_FILE} | grep ${DOWNLOADED_ITEM_NAME} | sha256sum -c -
cat ${2} | grep ${1} | sha256sum -c -
return ${?}

}

# $1 downloadle url
# $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 ${SHASUM_FILE} | grep ${DOWNLOADED_ITEM_NAME} | sha256sum -c -
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/
}
8 changes: 4 additions & 4 deletions crc-support/oci/lib/unix/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -95,13 +95,13 @@ if [[ $download == "true" ]]; then
# Download sha256sum
curl --insecure -LO "$aBaseURL/$aSHAName"
# Check if require download
required_download $targetPath
required_download $aName $aSHAName
if [[ ${?} -ne 0 ]]; then
# Required to download
rm -f $aName
local dURL="$aBaseURL/$aName"
dURL="$aBaseURL/$aName"
download $dURL
check_download $dURL
check_download $aName $aSHAName
if [[ ${?} -ne 0 ]]; then
popd
echo "Error with downloading $aName"
Expand All @@ -113,7 +113,7 @@ fi
# INSTALLATION
if [[ $install == 'true' ]]; then
echo "installing crc"
sudo installer -pkg $aName -target /
installCRC $aName
fi

popd
141 changes: 141 additions & 0 deletions crc-support/tkn/task.yaml
Original file line number Diff line number Diff line change
@@ -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 [[ $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"

8 changes: 4 additions & 4 deletions crc-support/tkn/tpl/task.tpl.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ spec:
cp /opt/host/key id_rsa
chmod 600 id_rsa
TARGET_HOST_KEY_PATH=id_rsa
TARGET_FOLDER=crc-support
TARGET_FOLDER=crc-support-$RANDOM$RANDOM
TARGET_CLEANUP='true'
# Create cmd per OS
Expand All @@ -104,16 +104,16 @@ spec:
runner="run.ps1"
fi
# Path for assets on remote target
tPath='/Users/$(params.username)/OpenshiftLocal'
tPath='/Users/${TARGET_HOST_USERNAME}/OpenshiftLocal'
if [[ $(params.os) == 'linux' ]]; then
tPath="/home/$(params.username)/OpenshiftLocal"
tPath="/home/${TARGET_HOST_USERNAME}/OpenshiftLocal"
fi
if [[ $name == *'.crcbundle' ]]; then
# It is bundle
nameArr=(${name//_/ })
tPath+='/bundle/${nameArr[2]}'
else
tPath+='/crc/$(params.crc-version)
tPath+='/crc/$(params.crc-version)'
fi
cmd="${TARGET_FOLDER}/${runner} -targetPath $tPath "
Expand Down

0 comments on commit 988dbe1

Please sign in to comment.