-
Notifications
You must be signed in to change notification settings - Fork 0
/
Taskfile.yaml
166 lines (147 loc) · 5.27 KB
/
Taskfile.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
---
version: 3
vars:
PROJECT_NAME:
sh: echo ${PWD##*/}
PROTO_DIR:
sh: find . -type f -name "*.proto" -exec dirname {} \; | sort | uniq
BRANCH:
sh: if [ $(git rev-parse --abbrev-ref HEAD) != "main" ]; then echo $(git rev-parse --abbrev-ref HEAD); else echo main ; fi
ORGA_NAME: stuttgart-things
MODULE: github.com/{{ .ORGA_NAME }}/{{ .PROJECT_NAME }}
VERSION: 0.0.1-mvp
CHART_DIR: helm
CHART_VERSION:
sh: grep 'version:' ./{{ .CHART_DIR }}/{{ .PROJECT_NAME }}/Chart.yaml | head -n1 | awk '{ print $2 }'
DATE:
sh: date -Ih
GIT_COMMIT:
sh: git log -n 1 --format=%h
PATH_HELMFILE: helm/helmfile.yaml
PATH_HELM_ENV: helm/env
K8S_ENV: dev
dotenv: ['.env', '{{.HOME}}/.env']
tasks:
helm-push:
desc: Push helm chart
cmds:
- dagger call -m {{ .DAGGER_HELM_MODULE }}@{{ .DAGGER_HELM_MODULE_VERSION }} push --src {{ .CHART }} --progress plain --username {{ .USERNAME }} --password=env:GITHUB_TOKEN --registry {{ .PACKAGE_REGISTRY }} --repository {{ .REPOSITORY_NAME }}
vars:
DAGGER_HELM_MODULE: github.com/stuttgart-things/dagger/helm
DAGGER_HELM_MODULE_VERSION: v0.0.3
CHART: helm/clusterbook
PACKAGE_REGISTRY: ghcr.io
USERNAME: stuttgart-things
REPOSITORY_NAME: stuttgart-things/clusterbook
deploy:
desc: Deploy to cluster
deps: [build-ko]
cmds:
- helmfile apply -f {{ .PATH_HELMFILE }} -e {{ .K8S_ENV }}
- helmfile test -f {{ .PATH_HELMFILE }} -e {{ .K8S_ENV }}
run:
desc: Run
deps: [build]
cmds:
- "$GOPATH/bin/{{ .PROJECT_NAME }}"
build-client:
desc: Build client
deps: [proto]
cmds:
- dagger call -m ~/projects/dagger/go ko-build --src ./tests/client --token=env:GITHUB_TOKEN --repo "ghcr.io/{{ .ORGA_NAME }}/{{ .PROJECT_NAME }}-client" --progress plain
run-client:
desc: Run
deps: [build]
cmds:
- "go run tests/client/client.go"
#helm test clusterbook -n clusterbook
build:
desc: Install
deps: [lint, test]
cmds:
- go mod tidy
- go install -ldflags="-X {{ .MODULE }}/internal.version={{ .VERSION }} -X {{ .MODULE }}/internal.date={{ .DATE }} -X {{ .MODULE }}/internal.commit={{ .GIT_COMMIT }}"
build-ko:
desc: Build image w/ KO
deps: [proto, lint, test, commit]
env:
KO_DOCKER_REPO: ghcr.io/{{ .ORGA_NAME }}/{{ .PROJECT_NAME }}
cmds:
- |
BUILD_IMAGE=$(ko build {{ .MODULE }} --image-label org.opencontainers.image.source=https://github.com/stuttgart-things/clusterbook --push)
echo ${BUILD_IMAGE}
dagger call -m github.com/jpadams/daggerverse/[email protected] scan-image --image-ref ${BUILD_IMAGE}
# UPDATE HELM CHART
sed -i "s|^\(\s*image:\s*\).*|\1$(echo ${BUILD_IMAGE} | awk -F':' '{print $1}')|" {{ .CHART_DIR }}/{{ .PROJECT_NAME }}/values.yaml
sed -i "s|^\(\s*tag:\s*\).*|\1$(echo ${BUILD_IMAGE} | awk -F':' '{print $2}')|" {{ .CHART_DIR }}//{{ .PROJECT_NAME }}/values.yaml
# UPDATE HELMFILE
yq eval ".imageTag = \"$(echo ${BUILD_IMAGE} | awk -F':' '{print $2}')\"" -i {{ .PATH_HELM_ENV }}/{{ .K8S_ENV }}.yaml
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 {{ .PROTO_DIR }}/*.proto
lint:
desc: Lint Golang
cmds:
- cmd: golangci-lint run
ignore_error: true
dagger-lint:
desc: Lint Golang w/ dagger
cmds:
- dagger -m github.com/purpleclay/daggerverse/golang@1190a20046659b68001a6e16cd5c12fab960b216 call --src . lint
dagger-build:
desc: Build Golang w/ dagger
cmds:
- dagger call -m github.com/felipecruz91/daggerverse/go build --source . --goVersion 1.23.1 -o build/
# dagger-format:
# desc: Format Golang w/ dagger
# cmds:
# - dagger call -m github.com/purpleclay/daggerverse/golang@1190a20046659b68001a6e16cd5c12fab960b216 --src . format export --path .
test:
desc: Test code
cmds:
- go mod tidy
- cmd: go test ./... -v
commit:
desc: Commit + push code into branch
cmds:
- rm -rf dist/
- git branch --set-upstream-to=origin/{{ .BRANCH }}
- git pull
- |
git add *
if [[ -n $(git status --porcelain) ]]; then
echo "ENTER COMMIT MESSAGE"
read COMMIT_MESSAGE;
echo "COMMITTING CHANGES"
git commit --allow-empty -a -m "$(echo ${COMMIT_MESSAGE})"
else
echo "NO CHANGES"
fi
git push origin -u {{ .BRANCH }}
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}
pr:
desc: Create pull request into main
deps:
# - dagger-format
- dagger-lint
- dagger-build
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