diff --git a/.github/workflows/latest.yaml b/.github/workflows/latest.yaml index 6bc85dfa0..ea3decf1d 100644 --- a/.github/workflows/latest.yaml +++ b/.github/workflows/latest.yaml @@ -1,8 +1,11 @@ +permissions: + contents: read + on: pull_request: branches: [main] push: - branches: [main] + branches: ["**"] schedule: - cron: "0 0 * * *" workflow_dispatch: @@ -18,12 +21,13 @@ name: build-test-publish jobs: go: runs-on: ubuntu-latest + # if: github.repository_owner == 'openshift-pipelines' # do not run this elsewhere steps: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Set up Go uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1 with: - go-version: "1.21" + go-version: "1.22" - run: go env - name: go build run: go build -v ./... @@ -37,6 +41,9 @@ jobs: e2e: name: e2e tests runs-on: ubuntu-latest + env: + KUBECONFIG: /home/runner/.kube/config.kind + # if: github.repository_owner == 'openshift-pipelines' # do not run this elsewhere needs: [go] steps: - uses: ko-build/setup-ko@v0.7 @@ -44,17 +51,13 @@ jobs: - uses: azure/setup-helm@v4 # instantiate a KinD (Kubernetes in Docker) cluster, installs `kubectl` and configures the # `kubeconfig` to reach the local cluster - - uses: helm/kind-action@v1.10.0 - with: - cluster_name: kind - wait: 120s + # - uses: helm/kind-action@v1.10.0 + # with: + # cluster_name: kind + # wait: 120s - uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1 with: - go-version: "1.21.x" - - uses: openshift-pipelines/setup-tektoncd@v1 - with: - pipeline_version: v0.56.1 - feature_flags: '{"enable-step-actions": "true"}' + go-version: "1.22" - name: Setup tmate session uses: mxschmitt/action-tmate@v3 @@ -63,18 +66,26 @@ jobs: limit-access-to-actor: true detached: true + - name: Install kind + run: | + set -euxfo pipefail + ./hack/kind-install.sh + + - uses: tektoncd/actions/setup-tektoncd@main + with: + pipeline_version: v0.61.1 + feature_flags: '{"enable-step-actions": "true"}' + setup_registry: false - name: tests - env: - OSP_PAC_GITHUB_TOKEN: ${{ secrets.OSP_PAC_GITHUB_TOKEN }} - OSP_PAC_USERNAME: os-pac + # env: + # OSP_PAC_GITHUB_TOKEN: ${{ secrets.OSP_PAC_GITHUB_TOKEN }} + # OSP_PAC_USERNAME: os-pac run: | set -euxfo pipefail + REGISTRY=registry.registry.svc.cluster.local:32222 - KO_DOCKER_REPO=ghcr.io/openshift-pipelines/tekton-caches + KO_DOCKER_REPO=localhost:5000/tekton-caches IMAGE_REF="${KO_DOCKER_REPO}/cache:$(git rev-parse HEAD | tr -d '\n')" - echo "${OSP_PAC_GITHUB_TOKEN}" | ko login ghcr.io --username ${OSP_PAC_USERNAME} --password-stdin - kubectl -n registry get deployment - kubectl -n registry port-forward deployment/registry 5000:5000 & make e2e @@ -90,14 +101,15 @@ jobs: -w name=gomodcache,emptyDir= --showlog tkn task start cache-upload-go -p gitURL=https://github.com/vdemeester/go-helloworld-app -p gitRevision=main -p cachePatterns="**.go,**go.sum" -p cacheURIBase=oci://${REGISTRY}/cache/go -w name=source,emptyDir= -w name=gocache,emptyDir= -w name=gomodcache,emptyDir= --showlog tkn task start cache-fetch-go -p gitURL=https://github.com/vdemeester/go-helloworld-app -p gitRevision=main -p cachePatterns="**.go,**go.sum" -p cacheURIBase=oci://${REGISTRY}/cache/go -w name=source,emptyDir= -w name=gocache,emptyDir= -w name=gomodcache,emptyDir= --showlog - tkn task start cache-upload-go -p gitURL=https://github.com/vdemeester/go-helloworld-app -p gitRevision=main -p cacheURIBase=oci://${REGISTRY}/cache/go -w name=source,emptyDir= -w name=gocache,emptyDir= -w name=gomodcache,emptyDir= --showlog - tkn task start cache-fetch-go -p gitURL=https://github.com/vdemeester/go-helloworld-app -p gitRevision=main -p cacheURIBase=oci://${REGISTRY}/cache/go -w name=source,emptyDir= -w name=gocache,emptyDir= -w name=gomodcache,emptyDir= --showlog + tkn task start cache-upload-go -p gitURL=https://github.com/vdemeester/go-helloworld-app -p gitRevision=main -p cachePatterns="" -p cacheURIBase=oci://${REGISTRY}/cache/go -w name=source,emptyDir= -w name=gocache,emptyDir= -w name=gomodcache,emptyDir= --showlog + tkn task start cache-fetch-go -p gitURL=https://github.com/vdemeester/go-helloworld-app -p gitRevision=main -p cachePatterns="" -p cacheURIBase=oci://${REGISTRY}/cache/go -w name=source,emptyDir= -w name=gocache,emptyDir= -w name=gomodcache,emptyDir= --showlog tkn taskrun list kubectl get taskrun -o yaml publish: name: publish latest runs-on: ubuntu-latest + if: github.repository_owner == 'openshift-pipelines' # do not run this elsewhere needs: [go] # https://docs.github.com/en/actions/reference/authentication-in-a-workflow @@ -107,7 +119,7 @@ jobs: - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1 with: - go-version: "1.21" + go-version: "1.22" - id: meta uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # 5.5.1 with: diff --git a/go.mod b/go.mod index 55d342219..7a332e803 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/openshift-pipelines/tekton-caches -go 1.21 +go 1.22 require ( github.com/codeclysm/extract/v3 v3.1.1 diff --git a/hack/kind-install.sh b/hack/kind-install.sh new file mode 100755 index 000000000..ce30432fd --- /dev/null +++ b/hack/kind-install.sh @@ -0,0 +1,85 @@ +#!/usr/bin/env bash +# This setups kind for running e2e tests on it. +# +# This targets both local setup (with docker or podman) and github workflows. + +set -euf +cd $(dirname $(readlink -f ${0})) + +export KIND_CLUSTER_NAME=${KIND_CLUSTER_NAME:-kind} +export KUBECONFIG=${HOME}/.kube/config.${KIND_CLUSTER_NAME} +export DOMAIN_NAME=caches-127-0-0-1.nip.io +export DOCKER=${DOCKER:-docker} + +TMPD=$(mktemp -d /tmp/.GITXXXX) +REG_PORT='5000' +REG_NAME='kind-registry' +# SUDO=sudo +# [[ $(uname -s) == "Darwin" ]] && { +# SUDO= +# } +SUDO= + +if ! builtin type -p kind &>/dev/null; then + echo "Install kind. https://kind.sigs.k8s.io/docs/user/quick-start/#installation" + exit 1 +fi +kind=$(type -p kind) + +# cleanup on exit (useful for running locally) +cleanup() { rm -rf ${TMPD}; } +trap cleanup EXIT + +function start_registry() { + running="$(${DOCKER} inspect -f '{{.State.Running}}' ${REG_NAME} 2>/dev/null || echo false)" + + if [[ ${running} != "true" ]]; then + ${DOCKER} rm -f kind-registry || true + ${DOCKER} run \ + -d --restart=always -p "127.0.0.1:${REG_PORT}:5000" \ + -e REGISTRY_HTTP_SECRET=secret \ + --name "${REG_NAME}" \ + registry:2 + fi +} + + +function install_kind() { + if [[ ${DOCKER} == "podman" ]]; then + export KIND_EXPERIMENTAL_PROVIDER=podman + fi + ${SUDO} $kind delete cluster --name ${KIND_CLUSTER_NAME} || true + sed "s,%DOCKERCFG%,${HOME}/.docker/config.json," kind.yaml >${TMPD}/kconfig.yaml + + cat <>${TMPD}/kconfig.yaml +containerdConfigPatches: +- |- + [plugins."io.containerd.grpc.v1.cri".registry.mirrors."localhost:${REG_PORT}"] + endpoint = ["http://${REG_NAME}:5000"] +EOF + + ${SUDO} ${kind} create cluster --name ${KIND_CLUSTER_NAME} --config ${TMPD}/kconfig.yaml + mkdir -p $(dirname ${KUBECONFIG}) + ${SUDO} ${kind} --name ${KIND_CLUSTER_NAME} get kubeconfig >${KUBECONFIG} + + ${DOCKER} network connect "kind" "${REG_NAME}" 2>/dev/null || true + cat <