-
Notifications
You must be signed in to change notification settings - Fork 1
/
Taskfile.yml
99 lines (76 loc) · 2.57 KB
/
Taskfile.yml
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
# https://taskfile.dev
version: '3'
env:
APPLICATION_NAME: go-c8y-cli-microservice
vars:
BINARY_NAME: go-c8y-cli-microservice
MAIN: ./cmd/main/main.go
RELEASE_DIR: release
VERSION_TAG:
sh: cat ./cumulocity.json | jq -r '.version'
dotenv: ['.env', '{{.ENV}}/.env.', '{{.HOME}}/.env']
tasks:
init:
desc: Init microservice and dot env file (required for local development)
cmds:
- task: init:microservice
- "sleep 2"
- task: init:env
init:microservice:
desc: Init the microservice by creating a placeholder in Cumulocity
cmds:
- c8y microservices create --name {{.APPLICATION_NAME}} --file cumulocity.json
init:env:
desc: Init the dotenv file (.env)
vars:
C8Y_BOOTSTRAP_USER:
sh: c8y microservices getBootstrapUser --id {{.APPLICATION_NAME}} --select name --output csv
C8Y_BOOTSTRAP_PASSWORD:
sh: c8y microservices getBootstrapUser --id {{.APPLICATION_NAME}} --select password --output csv
cmds:
- |
cat << EOF > .env
APPLICATION_NAME={{.APPLICATION_NAME}}
C8Y_HOST={{.C8Y_HOST}}
C8Y_BOOTSTRAP_TENANT={{.C8Y_TENANT}}
C8Y_BOOTSTRAP_USER={{.C8Y_BOOTSTRAP_USER}}
C8Y_BOOTSTRAP_PASSWORD={{.C8Y_BOOTSTRAP_PASSWORD}}
EOF
silent: true
clean:release:
desc: Clean (delete) any release files
cmds:
- go clean
- rm -rf "{{.RELEASE_DIR}}"
- rm -f "{{.BINARY_NAME}}"
start:local:
desc: Start the microserviice locally
env:
SERVER_PORT: 8000
cmds:
- go run {{.MAIN}}
build:binary:
desc: Build go binary
summary: |
Build just the go binary and not the whole docker image.
Useful if you want to run the microservice outside of a dockerized environment
cmds:
- go build -o {{.BINARY_NAME}}_{{OS}}_{{ARCH}} -v {{.MAIN}}
- chmod +x "{{.BINARY_NAME}}_{{OS}}_{{ARCH}}"
build:microservice:
desc: Build the microservice artifact that can be uploaded to Cumulocity
cmds:
- chmod +x ./build/microservice.sh
- bash -e ./build/microservice.sh pack --directory ./ --name {{.BINARY_NAME}} --tag "{{.VERSION_TAG}}"
- mkdir -p {{.RELEASE_DIR}}
- mv -f {{.BINARY_NAME}}.zip {{.RELEASE_DIR}}/{{.BINARY_NAME}}-v{{.VERSION_TAG}}.zip
deploy:microservice:
desc: Deploy microservice to Cumulocity
preconditions:
- sh: test -e {{.RELEASE_DIR}}
cmds:
- c8y microservices create --name {{.BINARY_NAME}} --file {{.RELEASE_DIR}}/{{.BINARY_NAME}}-v{{.VERSION_TAG}}.zip
test:
desc: Run tests
cmds:
- go test ./pkg/app