Skip to content

Commit

Permalink
Fixing e2e
Browse files Browse the repository at this point in the history
Signed-off-by: Vincent Demeester <[email protected]>
  • Loading branch information
vdemeester committed Jul 10, 2024
1 parent 7866b50 commit 7a3a766
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 25 deletions.
49 changes: 26 additions & 23 deletions .github/workflows/latest.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
permissions:
contents: read

on:
pull_request:
branches: [main]
push:
branches: [main]
branches: ["**"]
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
Expand All @@ -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 ./...
Expand All @@ -37,24 +41,17 @@ 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/[email protected]
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
- 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/[email protected]
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
Expand All @@ -63,18 +60,23 @@ 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
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
Expand All @@ -90,14 +92,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
Expand All @@ -107,7 +110,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:
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand Down
85 changes: 85 additions & 0 deletions hack/kind-install.sh
Original file line number Diff line number Diff line change
@@ -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 <<EOF >>${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 <<EOF | kubectl apply -f -
apiVersion: v1
kind: ConfigMap
metadata:
name: local-registry-hosting
namespace: kube-public
data:
localRegistryHosting.v1: |
host: "localhost:${REG_PORT}"
help: "https://kind.sigs.k8s.io/docs/user/local-registry/"
EOF

}

main() {
start_registry
install_kind
}

main
26 changes: 26 additions & 0 deletions hack/kind.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
apiServerAddress: 127.0.0.1
apiServerPort: 8443
nodes:
- role: control-plane
kubeadmConfigPatches:
- |
kind: InitConfiguration
nodeRegistration:
kubeletExtraArgs:
node-labels: "ingress-ready=true"
extraMounts:
- containerPath: /var/lib/kubelet/config.json
hostPath: "%DOCKERCFG%"
# extraPortMappings:
# - containerPort: 80
# hostPort: 80
# protocol: TCP
# - containerPort: 443
# hostPort: 443
# protocol: TCP
# - containerPort: 32567
# hostPort: 3000
# protocol: TCP
7 changes: 6 additions & 1 deletion tekton/cache-upload.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ spec:
Whether to use insecure mode for fetching the cache
type: string
default: "false"
- name: fetched
description: |
Wether cache was fetched or not previously
type: string
default: "false"
- name: force-cache-upload
description: |
Whether to force the cache upload even if it was fetched previously
Expand All @@ -48,7 +53,7 @@ spec:
- name: PARAM_INSECURE
value: $(params.insecure)
- name: RESULT_CACHE_FETCHED
value: $(steps.cache-fetch.results.fetched)
value: $(params.fetched)
- name: PARAM_FORCE_CACHE_UPLOAD
value: $(params.force-cache-upload)
# FIXME: use a released version once something is released :)
Expand Down
1 change: 1 addition & 0 deletions tests/task-cache-fetch-go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ spec:
default: "main"
- name: cachePatterns
type: array
default: []
- name: cacheURIBase
steps:
- name: git-clone
Expand Down
1 change: 1 addition & 0 deletions tests/task-cache-upload-go.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ spec:
default: "main"
- name: cachePatterns
type: array
default: []
- name: cacheURIBase
steps:
- name: git-clone
Expand Down

0 comments on commit 7a3a766

Please sign in to comment.