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