|
| 1 | +# More examples of Codefresh YAML can be found at |
| 2 | +# https://codefresh.io/docs/docs/yaml-examples/examples/ |
| 3 | + |
| 4 | +version: "1.0" |
| 5 | +mode: parallel |
| 6 | +# Stages can help you organize your steps in stages |
| 7 | +stages: |
| 8 | + - "clone" |
| 9 | + - "build" |
| 10 | + - "test" |
| 11 | + |
| 12 | +steps: |
| 13 | + clone: |
| 14 | + title: "Cloning repository" |
| 15 | + type: "git-clone" |
| 16 | + repo: "codefresh-contrib/vcluster-prometheus-operator-plugin" |
| 17 | + revision: "${{CF_BRANCH}}" |
| 18 | + git: "codefresh-git-integration-contrib" |
| 19 | + stage: "clone" |
| 20 | + |
| 21 | + export_image_tag: |
| 22 | + title: "Export image tag" |
| 23 | + type: freestyle |
| 24 | + stage: build |
| 25 | + image: alpine |
| 26 | + commands: |
| 27 | + - | |
| 28 | + export isRelease="${{RELEASE}}" |
| 29 | + if [[ "$isRelease" == "true" ]]; then |
| 30 | + export IMAGE_TAG="${{CF_RELEASE_TAG}}" |
| 31 | + else |
| 32 | + export IMAGE_TAG="${{CF_BRANCH_TAG_NORMALIZED_LOWER_CASE}}" |
| 33 | + fi |
| 34 | +
|
| 35 | + cf_export IMAGE_TAG |
| 36 | +
|
| 37 | +
|
| 38 | + build_v1: |
| 39 | + title: "Build v1" |
| 40 | + type: build |
| 41 | + stage: "build" |
| 42 | + working_directory: '${{clone}}/v1' |
| 43 | + build_arguments: |
| 44 | + - BUILDKIT_INLINE_CACHE=1 |
| 45 | + image_name: "${{CF_REPO_NAME}}" |
| 46 | + tag: "v1-${{IMAGE_TAG}}" |
| 47 | + registry: "ghcr-codefresh-contrib" |
| 48 | + platform: 'linux/amd64,linux/arm64' |
| 49 | + buildx: |
| 50 | + builder: |
| 51 | + driver_opts: "image=moby/buildkit:v0.14.1" |
| 52 | + cache_from: |
| 53 | + - ghcr.io/${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}:v1-${{CF_BRANCH_TAG_NORMALIZED_LOWER_CASE}} |
| 54 | + - ghcr.io/${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}:v1-main |
| 55 | + when: |
| 56 | + steps: |
| 57 | + - name: clone |
| 58 | + on: |
| 59 | + - success |
| 60 | + - name: export_image_tag |
| 61 | + on: |
| 62 | + - success |
| 63 | + |
| 64 | + build_v2: |
| 65 | + title: "Build v2" |
| 66 | + type: build |
| 67 | + stage: "build" |
| 68 | + build_arguments: |
| 69 | + - BUILDKIT_INLINE_CACHE=1 |
| 70 | + working_directory: '${{clone}}/v2' |
| 71 | + image_name: "${{CF_REPO_NAME}}" |
| 72 | + tag: "v2-${{IMAGE_TAG}}" |
| 73 | + registry: "ghcr-codefresh-contrib" |
| 74 | + platform: 'linux/amd64,linux/arm64' |
| 75 | + buildx: |
| 76 | + builder: |
| 77 | + driver_opts: "image=moby/buildkit:v0.14.1" |
| 78 | + cache_from: |
| 79 | + - ghcr.io/${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}:v2-${{CF_BRANCH_TAG_NORMALIZED_LOWER_CASE}} |
| 80 | + - ghcr.io/${{CF_REPO_OWNER}}/${{CF_REPO_NAME}}:v2-main |
| 81 | + when: |
| 82 | + steps: |
| 83 | + - name: clone |
| 84 | + on: |
| 85 | + - success |
| 86 | + - name: build_v1 |
| 87 | + on: |
| 88 | + - success |
| 89 | + - name: export_image_tag |
| 90 | + on: |
| 91 | + - success |
| 92 | + |
| 93 | + |
| 94 | + create_clusters: |
| 95 | + title: 'Create k3d clusters' |
| 96 | + stage: test |
| 97 | + type: freestyle |
| 98 | + image: 'ghcr.io/k3d-io/k3d:5.5.2-dind' |
| 99 | + commands: |
| 100 | + - export NETWORK=$(docker network ls | grep bridge | tail -1 | awk '{print $2}') |
| 101 | + - export FULL_CLUSTER_NAME_V1="k3d-test-prom-vcluster-plugin-v1" |
| 102 | + - export FULL_CLUSTER_NAME_V2="k3d-test-prom-vcluster-plugin-v2" |
| 103 | + - export CLUSTER_IMAGE="rancher/k3s:v1.24.4-k3s1" |
| 104 | + - k3d cluster create $FULL_CLUSTER_NAME_V1 --network $NETWORK -i $CLUSTER_IMAGE --no-lb |
| 105 | + - k3d cluster create $FULL_CLUSTER_NAME_V2 --network $NETWORK -i $CLUSTER_IMAGE --no-lb |
| 106 | + - export CLUSTER_IP_V1=$(docker inspect k3d-$FULL_CLUSTER_NAME_V1-server-0 | jq -r '.[0].NetworkSettings.IPAddress') |
| 107 | + - export CLUSTER_IP_V2=$(docker inspect k3d-$FULL_CLUSTER_NAME_V2-server-0 | jq -r '.[0].NetworkSettings.IPAddress') |
| 108 | + - yq e -i '(.clusters[] | select(.name=="k3d-"+env(FULL_CLUSTER_NAME_V1)) | .cluster.server) = "https://"+env(CLUSTER_IP_V1)+":6443"' $KUBECONFIG |
| 109 | + - yq e -i '(.clusters[] | select(.name=="k3d-"+env(FULL_CLUSTER_NAME_V2)) | .cluster.server) = "https://"+env(CLUSTER_IP_V2)+":6443"' $KUBECONFIG |
| 110 | + - export V1_KUBE_CONTEXT=k3d-$FULL_CLUSTER_NAME_V1 |
| 111 | + - export V2_KUBE_CONTEXT=k3d-$FULL_CLUSTER_NAME_V2 |
| 112 | + - cf_export FULL_CLUSTER_NAME_V1 V1_KUBE_CONTEXT FULL_CLUSTER_NAME_V2 V2_KUBE_CONTEXT |
| 113 | + |
| 114 | + init_test_envs: |
| 115 | + stage: test |
| 116 | + title: 'Init test environments' |
| 117 | + image: "dtzar/helm-kubectl:3.15" |
| 118 | + working_directory: '${{clone}}' |
| 119 | + commands: |
| 120 | + - curl -L -o vcluster "https://github.com/loft-sh/vcluster/releases/download/v0.20.0-beta.11/vcluster-linux-amd64" && chmod +x ./vcluster && mv ./vcluster /usr/local/bin/vcluster |
| 121 | + - kubectl config use-context $V1_KUBE_CONTEXT |
| 122 | + - v1/.e2e/scripts/init.sh "${{steps.build_v1.imageId}}" |
| 123 | + - kubectl config use-context $V2_KUBE_CONTEXT |
| 124 | + - v2/.e2e/scripts/init.sh "${{steps.build_v2.imageId}}" |
| 125 | + when: |
| 126 | + steps: |
| 127 | + - name: create_clusters |
| 128 | + on: |
| 129 | + - success |
| 130 | + - name: build_v1 |
| 131 | + on: |
| 132 | + - success |
| 133 | + - name: build_v2 |
| 134 | + on: |
| 135 | + - success |
| 136 | + |
| 137 | + run_chainsaw_tests: |
| 138 | + stage: test |
| 139 | + title: 'Run chainsaw tests' |
| 140 | + image: 'ghcr.io/kyverno/chainsaw:v0.2.5' |
| 141 | + working_directory: '${{clone}}' |
| 142 | + commands: |
| 143 | + - chainsaw test --kube-context $V1_KUBE_CONTEXT --test-file .e2e/chainsaw-tests.yaml --skip-delete |
| 144 | + - chainsaw test --kube-context $V2_KUBE_CONTEXT --test-file .e2e/chainsaw-tests.yaml --skip-delete |
| 145 | + when: |
| 146 | + steps: |
| 147 | + - name: init_test_envs |
| 148 | + on: |
| 149 | + - success |
0 commit comments