Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add snc runner ci defiinition #1

Merged
merged 1 commit into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions .github/workflows/build-oci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
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


29 changes: 29 additions & 0 deletions .github/workflows/tkn-bundle.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: tkn-bundle

on:
push:
branches: [ main ]
tags:
- '*'
pull_request:
branches: [ main ]

jobs:
tkn-check:
name: tkn-check
runs-on: ubuntu-24.04
steps:
- name: Checkout code
uses: actions/checkout@v4

- 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 snc-runner/tkn/task.yaml


29 changes: 29 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
CONTAINER_MANAGER ?= podman

# Helpers
TOOLS_DIR := tools
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)

.PHONY: oci-build oci-push tkn-create tkn-push

## 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

oci-build:
$(call oci_builder,$(SNC_RUNNER),$(SNC_RUNNER_V),snc-runner)

oci-push:
$(call oci_pusher,$(SNC_RUNNER),$(SNC_RUNNER_V))

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)
9 changes: 9 additions & 0 deletions snc-runner/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Overview

TBD

# Execute

## Container

## Tekton
9 changes: 9 additions & 0 deletions snc-runner/oci/Containerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM quay.io/rhqp/deliverest:v0.0.6

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

# Mandatory envs extending from deliverest
ENV ASSETS_FOLDER=/opt/snc \
OS=linux

COPY run.sh ${ASSETS_FOLDER}/
156 changes: 156 additions & 0 deletions snc-runner/oci/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
#!/bin/bash
#
# Usage run.sh -ocp-ps-path /Users/.../ps -ocp-version 4.1X.X [-ocp-extended-cert enabled] \
# -s3-url https://amazon.es/ -s3-ak XXXX -s3-sk XXXX -s3-path nightly/ocp/4.1X.X \
# [-scm https://github.com/code-ready/snc.git] [-ref master] [-pr] [-ocp-mirror]

# Define error handler function
function handle_error() {
FILENAME_PATTERN="log-bundle-*.tar.gz"
OUTPUT_FILENAME="log-bundle.tar.gz"

set -exuo pipefail

pushd crc-tmp-install-data
log_filename=$(find . -name ${FILENAME_PATTERN} -printf "%f\n" | grep . || true)

# Enforce ntp sync
sudo timedatectl set-ntp on
# wait for sync
while [[ $(timedatectl status | grep 'System clock synchronized' | grep -Eo '(yes|no)') = no ]]; do
sleep 2
done

if [ "${log_filename}" != "" ]; then
mc cp ${log_filename} datalake/${s3Path}
fi

# Optionally exit the script gracefully
exit 1
}

# Parameters
# Default values
scm="https://github.com/code-ready/snc.git"
ref="master"
export SNC_USE_PATCHED_RELEASE_IMAGE="enabled"
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-scm)
scm="$2"
shift
shift
;;
-ref)
ref="$2"
shift
shift
;;
-pr)
pr="$2"
shift
shift
;;
-ocp-ps-path)
export OPENSHIFT_PULL_SECRET_PATH="$2"
shift
shift
;;
-ocp-version)
export OPENSHIFT_VERSION="$2"
shift
shift
;;
-ocp-mirror)
MIRROR="$2"
shift
shift
;;
-ocp-extended-cert)
export SNC_USE_PATCHED_RELEASE_IMAGE="$2"
shift
shift
;;
-s3-url)
s3Url="$2"
shift
shift
;;
-s3-ak)
s3AccessKey="$2"
shift
shift
;;
-s3-sk)
s3SecretKey="$2"
shift
shift
;;
-s3-path)
s3Path="$2"
shift
shift
;;
*) # unknown option
shift
;;
esac
done

set -exuo pipefail

export LC_ALL=C.UTF-8
export LANG=C.UTF-8

# Validations
if [[ -z ${OPENSHIFT_PULL_SECRET_PATH+x} ]] || [[ -z ${OPENSHIFT_VERSION+x} ]]; then
echo "OPENSHIFT_PULL_SECRET_PATH and OPENSHIFT_VERSION should be provided"
exit 1
fi

# Set datalake for uploading results / error logs
if ! which mc >/dev/null; then
if [[ $(uname -m) == "x86_64" ]]; then
mcurl="https://dl.min.io/client/mc/release/linux-amd64/mc"
else
mcurl="https://dl.min.io/client/mc/release/linux-arm64/mc"
fi
sudo curl ${mcurl} -o /usr/local/bin/mc
sudo chmod +x /usr/local/bin/mc
fi
mc alias set datalake ${s3Url} \
${s3AccessKey} \
${s3SecretKey} \
--api S3v4
mc mb -p datalake/${s3Path}

# Get SNC code
git clone ${scm}
pushd snc
if [[ ! -z ${pr+x} ]]; then
git fetch origin pull/${pr}/head:pr-${pr}
git checkout pr-${pr}
else
git checkout ${ref}
fi

# Run SNC
trap handle_error ERR
./snc.sh

# Create disks
SNC_GENERATE_LINUX_BUNDLE=1 ./createdisk.sh crc-tmp-install-data
mkdir -p ${OPENSHIFT_VERSION}
mv *.crcbundle ${OPENSHIFT_VERSION}/
pushd ${OPENSHIFT_VERSION}
# Standarize arch names
arch=$(uname -m)
if [[ ${arch} == "aarch64" ]]; then
arch="arm64"
fi
sha256sum * > bundles.${arch}.sha256
popd

# Upload disks
mc cp -r ${OPENSHIFT_VERSION}/* datalake/${s3Path}
2 changes: 2 additions & 0 deletions snc-runner/release-info
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
quay.io/rhqp/snc-runner
2.0.0-dev
Loading