diff --git a/crc-support/oci/Containerfile b/crc-support/oci/Containerfile index df18d2c..67f2751 100644 --- a/crc-support/oci/Containerfile +++ b/crc-support/oci/Containerfile @@ -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 " diff --git a/crc-support/oci/lib/darwin/lib.sh b/crc-support/oci/lib/darwin/lib.sh index e10214f..ca26adf 100755 --- a/crc-support/oci/lib/darwin/lib.sh +++ b/crc-support/oci/lib/darwin/lib.sh @@ -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 / +} + diff --git a/crc-support/oci/lib/linux/lib.sh b/crc-support/oci/lib/linux/lib.sh index 60d5bcf..4055f3d 100755 --- a/crc-support/oci/lib/linux/lib.sh +++ b/crc-support/oci/lib/linux/lib.sh @@ -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/ +} diff --git a/crc-support/oci/lib/unix/run.sh b/crc-support/oci/lib/unix/run.sh index 2c255cf..887ea32 100755 --- a/crc-support/oci/lib/unix/run.sh +++ b/crc-support/oci/lib/unix/run.sh @@ -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" @@ -113,7 +113,7 @@ fi # INSTALLATION if [[ $install == 'true' ]]; then echo "installing crc" - sudo installer -pkg $aName -target / + installCRC $aName fi popd \ 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..64301f8 --- /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 [[ $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 index 91d1003..975e7e1 100644 --- a/crc-support/tkn/tpl/task.tpl.yaml +++ b/crc-support/tkn/tpl/task.tpl.yaml @@ -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 @@ -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 "