-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTaskfile.yaml
More file actions
190 lines (170 loc) · 6.55 KB
/
Taskfile.yaml
File metadata and controls
190 lines (170 loc) · 6.55 KB
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
---
version: 3
vars:
PROJECT_NAME:
sh: echo ${PWD##*/}
MODULE: github.com/{{ .REPOSITORY_NAME }}/{{ .PROJECT_NAME }}
#REGISTRY: eu.gcr.io
#REPOSITORY_NAME: stuttgart-things
REGISTRY: scr.cd43.sthings-pve.labul.sva.de
REPOSITORY_NAME: stagetime-server
VCLUSTER_NAME: my-vcluster
VCLUSTER_NAMESPACE: vcluster-my-vcluster
VCLUSTER_STORAGE_CLASS: openebs-hostpath
VCLUSTER_HELMFILE_ENV: vcluster
LOCAL_BIN_SERVER_PORT: 50051
LOCAL_CONTAINER_SERVER_PORT: 8011
DEV_INGRESS_URL: stagetime.teasle.sthings.tiab.ssc.sva.de:443
DATE:
sh: date +"%y.%m%d.%H%M"
GIT_COMMIT:
sh: git log -n 1 --format=%h
UPDATED_TAG:
sh: old_tag=$(git describe --tags --abbrev=0 | cut -d "." -f3 | cut -d "-" -f1); new_tag=$((old_tag+1)); echo $new_tag
UPDATED_TAG_VERSION:
sh: t1=$(git describe --tags --abbrev=0 | cut -f1 -d'.'); t2=$(git describe --tags --abbrev=0 | cut -f2 -d'.'); echo $t1.$t2.{{ .UPDATED_TAG }}
BRANCH:
sh: if [ $(git rev-parse --abbrev-ref HEAD) != "main" ]; then echo $(git rev-parse --abbrev-ref HEAD) ; fi
tasks:
branch:
desc: Create branch from main
cmds:
- git checkout main
- git branch
- git pull
- |
echo "Enter to be created (remote) branch:"
read BRANCH_NAME;
git checkout -b ${BRANCH_NAME}
git push origin ${BRANCH_NAME}
- git branch
- git branch --set-upstream-to=origin/main ${BRANCH_NAME}
commit:
desc: Commit + push code into branch
cmds:
- git pull
- |
echo "ENTER COMMIT MESSAGE"
read COMMIT_MESSAGE;
git add *
git commit -am "$(echo ${COMMIT_MESSAGE})"
git push origin -u {{ .BRANCH }}
pr:
desc: Create pull request into main
cmds:
- task: commit
- gh pr create -t "{{ .BRANCH }}" -b "{{ .BRANCH }} branch into main"
- sleep 20s
- gh pr checks $(gh pr list | grep "^[^#;]" | awk '{print $1}') --watch
- gh pr merge $(gh pr list | grep "^[^#;]" | awk '{print $1}') --auto --rebase --delete-branch
- git checkout main && git pull
lint:
desc: Lint code
cmds:
- cmd: golangci-lint run
ignore_error: true
build-server:
desc: Build server
deps: [lint, proto]
cmds:
- go mod tidy
- CGO_ENABLED=0
- GOOS=linux
- go install -ldflags="-X {{ .MODULE }}/internal.version=v{{ .UPDATED_TAG_VERSION }} -X {{ .MODULE }}/internal.date={{ .DATE }} -X {{ .MODULE }}/internal.commit={{ .GIT_COMMIT }}"
git-push:
desc: Commit & push the module
cmds:
- go mod tidy
- git pull
- git config advice.addIgnoredFile false
- git add *
- git commit -am 'updated {{ .PROJECT_NAME }} {{ .DATE }} for tag version {{ .UPDATED_TAG_VERSION }}{{ .BRANCH }}'
- git push
build:
desc: Build the app
deps: [lint, proto]
cmds:
- go mod tidy
- CGO_ENABLED=0
- GOOS=linux
- go install -ldflags="-X {{ .MODULE }}/internal.date={{ .DATE }} -X {{ .MODULE }}/internal.version={{ .UPDATED_TAG_VERSION }} -X {{ .MODULE }}/internal.commit={{ .GIT_COMMIT }}"
- "{{ .PROJECT_NAME }}"
proto:
desc: Generate Go code from proto
cmds:
- protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative revisionrun/*.proto
build-image:
desc: Build container image
deps: [build-server]
cmds:
- sudo nerdctl build -t {{ .REGISTRY }}/{{ .REPOSITORY_NAME }}/{{ lower (.PROJECT_NAME) }}:{{ .DATE }}-{{ .UPDATED_TAG_VERSION }} --build-arg VERSION={{ .UPDATED_TAG_VERSION }} --build-arg BUILD_DATE={{ .DATE }} --build-arg COMMIT={{ .GIT_COMMIT }} .
- sudo nerdctl push {{ .REGISTRY }}/{{ .REPOSITORY_NAME }}/{{ lower (.PROJECT_NAME) }}:{{ .DATE }}-{{ .UPDATED_TAG_VERSION }}
run-server:
desc: Run server locally
deps: [build-server]
cmds:
- "{{ .PROJECT_NAME }}"
env:
SERVER_PORT: "{{ .LOCAL_SERVER_PORT }}"
run-client:
desc: Run client locally
deps: [build-server]
cmds:
- go run client/client.go
env:
SERVER_PORT: "{{ .LOCAL_CONTAINER_SERVER_PORT }}"
GRPC_GO_LOG_VERBOSITY_LEVEL: 99
GRPC_GO_LOG_SEVERITY_LEVEL: info
STAGE_TIME_URL: "{{ .DEV_INGRESS_URL }}"
run-container:
desc: Run container image
deps: [build-image]
cmds:
- nerdctl run -e SERVER_PORT={{ .LOCAL_CONTAINER_SERVER_PORT }} -p {{ .LOCAL_CONTAINER_SERVER_PORT }}:{{ .LOCAL_CONTAINER_SERVER_PORT }} {{ .REGISTRY }}/{{ .PROJECT_NAME }}/{{ .PROJECT_NAME }}:{{ .DATE }}
tag:
desc: Commit, push & tag the module on remote
deps: [lint, proto]
cmds:
- rm -rf dist
- task: git-push
- go mod tidy
- git pull --tags
- git tag -a {{ .UPDATED_TAG_VERSION }}{{ .BRANCH }} -m 'updated for stuttgart-things {{ .DATE }} for tag version {{ .UPDATED_TAG_VERSION }}{{ .BRANCH }}'
- git push origin --tags
package:
desc: Update Chart.yaml and package archive
cmds:
- cd ./helm/{{ lower (.PROJECT_NAME) }} && helm dep update
- git add ./helm/*/*
- yq e -i '.version = "{{ .UPDATED_TAG_VERSION }}"' ./helm/*/Chart.yaml
- "sed -i 's/appVersion: .*/appVersion: {{ .UPDATED_TAG_VERSION }}/g' ./helm/*/Chart.yaml"
- yq e -i '.deployment.containers.stagetimeserver.tag = "{{ .DATE }}-{{ .UPDATED_TAG_VERSION }}"' ./helm/*/values.yaml
- yq e -i '.deployment.containers.stagetimeserver.image = "{{ .REGISTRY }}/{{ .REPOSITORY_NAME }}/{{ lower (.PROJECT_NAME) }}"' ./helm/*/values.yaml
- yq e -i '.releases[1].version = "{{ .UPDATED_TAG_VERSION }}"' ./helmfile.yaml
- helm package ./helm/*/
push:
desc: Push to registry
deps: [tag, build-image, package]
cmds:
- helm push {{ lower (.PROJECT_NAME) }}-{{ .UPDATED_TAG_VERSION }}.tgz oci://{{ .REGISTRY }}/{{ .REPOSITORY_NAME }}
- rm -rf {{ lower (.PROJECT_NAME) }}-{{ .UPDATED_TAG_VERSION }}.tgz
- task: git-push
release:
desc: Relase binaries
deps: [tag]
cmds:
- rm -rf ./dist
- goreleaser healthcheck
- goreleaser check
- goreleaser release --skip-publish --snapshot --clean
- goreleaser release --clean
- rm -rf ./dist
vcluster:
desc: Test deploy on vcluster
deps: [push]
cmds:
- vcluster disconnect || true
- vcluster create {{ .VCLUSTER_NAME }} --expose --set storage.className={{ .VCLUSTER_STORAGE_CLASS }} --update-current -n {{ .VCLUSTER_NAMESPACE }}
- vcluster connect {{ .VCLUSTER_NAME }} -n {{ .VCLUSTER_NAMESPACE }}
- helmfile sync --environment {{ .VCLUSTER_HELMFILE_ENV }}
- helmfile test --environment {{ .VCLUSTER_HELMFILE_ENV }}