-
Notifications
You must be signed in to change notification settings - Fork 17
210 lines (205 loc) · 8.14 KB
/
main.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
name: CI
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches: [master]
paths-ignore: ["**.md"]
pull_request:
branches: [master]
paths-ignore: ["**.md"]
jobs:
validate:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Validate
run: |
if [ "${{ github.event_name }}" == "pull_request" ]
then
make validate-versions
else
echo "push to master, skipping validation"
fi
docker-build:
needs: validate
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Determine Tag
run: |
[ "${{ github.event_name }}" == "pull_request" ] && export VERSION=$(cat VERSION)-dev || export VERSION=$(cat VERSION)
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "REPO=kraan" >> $GITHUB_ENV
echo "using $VERSION as the release version"
- name: Setup Go environment
uses: actions/setup-go@v2
with:
# The Go version to download (if necessary) and use. Supports semver spec and ranges.
go-version: 1.19.3
- name: Setup dependencies
run: |
[ -z "${GOPATH}" ] && export GOPATH=$HOME/go
PATH="${GOPATH}/bin:${PATH}"
./bin/setup.sh --skip-kind
# - uses: satackey/action-docker-layer-caching@v0
# # Ignore the failure of a step and avoid terminating the job.
# continue-on-error: true
- name: Prerelease - Lint, Test, Build
if: github.event_name == 'pull_request'
run: |
make clean
make dev-build
- name: Prerelease - Store docker image as artifact
if: github.event_name == 'pull_request'
uses: actions/upload-artifact@v2
with:
name: image
path: build/*.tar
if-no-files-found: error
- name: Login to GitHub Packages Docker Registry
if: github.event_name == 'push'
uses: docker/login-action@v1
with:
username: ${{ secrets.DOCKER_USER }}
password: ${{ secrets.DOCKER_TOKEN }}
- name: Prepare
id: prep
if: github.event_name == 'push'
run: |
VERSION=$(cat VERSION)
TAGS=kraan/kraan-controller:${VERSION}
echo ::set-output name=tags::${TAGS}
- name: Set up QEMU
if: github.event_name == 'push'
uses: docker/setup-qemu-action@master
with:
platforms: all
- name: Set up Docker Buildx
id: buildx
if: github.event_name == 'push'
uses: docker/setup-buildx-action@master
- name: Build arm image
if: github.event_name == 'push'
uses: docker/build-push-action@v4
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile
platforms: linux/arm64
tags: ${{ steps.prep.outputs.tags }}-arm
outputs: type=docker,oci-mediatypes=false
- name: push arm
id: push-arm
if: github.event_name == 'push'
run: |
docker push ${{ steps.prep.outputs.tags }}-arm
- name: Build amd image
if: github.event_name == 'push'
uses: docker/build-push-action@v4
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
file: ./Dockerfile
platforms: linux/amd64
tags: ${{ steps.prep.outputs.tags }}-amd
outputs: type=docker,oci-mediatypes=false
- name: push amd
id: push-amd
if: github.event_name == 'push'
run: |
docker push ${{ steps.prep.outputs.tags }}-amd
integration-test:
needs: docker-build
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: Create kind cluster
run: |
[ -z "${GOPATH}" ] && export GOPATH=$HOME/go
PATH="${GOPATH}/bin:${PATH}"
kind create cluster --image kindest/node:v1.26.6
echo "sleep 60s to wait node ready"
sleep 60s
kubectl get node
- name: Prerelease - pull image from artifact
if: github.event_name == 'pull_request'
uses: actions/download-artifact@v2
with:
name: image
- name: Prerelease - load image
if: github.event_name == 'pull_request'
run: |
export VERSION=$(cat VERSION)-dev
docker load -i *.tar
kind load docker-image kraan/kraan-controller-prerelease:$VERSION
- name: Integration Test
env:
GITREPO: ${{ github.event.pull_request.head.repo.full_name }}
run: |
[ "${{ github.event_name }}" == "pull_request" ] && export DOCKER_IMG='kraan-controller-prerelease' || export DOCKER_IMG='kraan-controller'
[ "${{ github.event_name }}" == "pull_request" ] && export VERSION=$(cat VERSION)-dev || export VERSION=$(cat VERSION)-amd
[ "${{ github.event_name }}" != "pull_request" ] && export GITREPO='fidelity/kraan'
export CHART_VERSION=$VERSION
export REPO=kraan
kubectl cluster-info
kubectl version
echo "installing kraan..."
helm install kraan --set kraan.kraanController.image.name=$DOCKER_IMG --set kraan.kraanController.image.tag=${VERSION} --set kraan.kraanController.resources=null --set gotk.sourceController.resources=null --set gotk.helmController.resources=null --wait --timeout=2m --create-namespace --namespace gotk-system chart || (kubectl describe deploy -n gotk-system && kubectl describe po -n gotk-system && false)
echo "setting up test..."
kubectl apply -f ./testdata/namespaces.yaml
kubectl apply -f ./testdata/addons/addons-source.yaml
kubectl patch gitrepository addons-config -n gotk-system -p "{\"spec\": {\"ref\": {\"branch\": \"$GITHUB_HEAD_REF\"},\"url\": \"$GITHUB_SERVER_URL/$GITREPO.git\"}}" --type=merge
kubectl apply -f ./testdata/addons/addons-repo.yaml
kubectl apply -f ./testdata/addons/addons.yaml
echo "waiting 5m for test to pass..."
kubectl wait al --for=condition=Deployed --all --timeout=5m || (kubectl get po -A && kubectl describe al -A && false)
- name: Orphan Integration Test
env:
GITREPO: ${{ github.event.pull_request.head.repo.full_name }}
run: |
[ "${{ github.event_name }}" != "pull_request" ] && export GITREPO='fidelity/kraan'
echo "setting up test..."
kubectl apply -f ./testdata/addons-orphan/addons-source.yaml
kubectl patch gitrepository addons-config -n gotk-system -p "{\"spec\": {\"ref\": {\"branch\": \"$GITHUB_HEAD_REF\"},\"url\": \"$GITHUB_SERVER_URL/$GITREPO.git\"}}" --type=merge
kubectl apply -f ./testdata/addons-orphan/addons-repo.yaml
kubectl apply -f ./testdata/addons-orphan/addons.yaml
echo "waiting 5m for test to pass..."
kubectl wait al --for=condition=Deployed --all --timeout=5m || (kubectl get po -A && false)
helm-publish:
if: github.event_name == 'push'
needs: integration-test
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Setup dependencies
run: |
[ -z "${GOPATH}" ] && export GOPATH=$HOME/go
PATH="${GOPATH}/bin:${PATH}"
./bin/setup.sh
- name: Publish Helm Chart
run: |
export VERSION=$(cat VERSION)
unset CHART_VERSION
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions"
git checkout go.mod go.sum
make release
tag-repo:
if: github.event_name == 'push'
needs: helm-publish
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: tag repository
run: |
export VERSION=$(cat VERSION)
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --global user.name "github-actions"
git tag -a $VERSION -m "tag version $VERSION"
git push origin --tags