-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTaskfile.yml
122 lines (113 loc) · 4.08 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# A Taskfile
# See https://taskfile.dev/
# See https://nanovms.gitbook.io/ops/google_cloud for ops commands
# This taskfile will enable local building of the application, building of an
# ops image, and cloud deployment management.
# Things needed
# - taskf runner - see above
# - mkcert - https://github.com/FiloSottile/mkcert
# - nkey generator
# - go get github.com/nats-io/nkeys/nk
# - https://github.com/nats-io/nkeys/blob/master/nk/README.md
version: '3'
vars:
basepath:
sh: pwd
configpath: '{{.basepath}}/build/config/config.json'
applinux: nanoapplinux
nativeapp: nanoappnative
imagename: nanovms-test-image
cloud: gcp
localport: 8000
cloudport: 8000
# If running with pre-set environment variables do not run the dotenv
dotenv: ['./build/config/env/.ENV']
tasks:
build:
desc: build native and linux apps for running in novavms
dir: ./app
vars:
secretspath: ./creds/secrets
nksecretspath: ./msg/secrets
cmds:
# See https://github.com/FiloSottile/mkcert
# Make certificate for grpc tls
- mkcert -key-file {{.secretspath}}/serverkey.pem -cert-file {{.secretspath}}/servercert.pem grpc.com
- nk -gen user > {{.nksecretspath}}/nkuser.seed
- nk -inkey {{.nksecretspath}}/nkeyuser.seed -pubout > {{.nksecretspath}}/nkeyuser.pub
# Use of embed to flag context - used for port use
- echo "cloud" > .context
- GOOS=linux go build .
- mv app {{.basepath}}/build/{{.applinux}}
# Use of embed to flag context - used for port use
- echo "local" > .context
- go build .
- mv app {{.basepath}}/build/{{.nativeapp}}
run-native:
desc: run locally using native biuld
dir: ./build
cmds:
- task: build
- ./{{.nativeapp}}
run-locally:
desc: run locally using ops
dir: ./build
cmds:
- task: build
- ops run -p "{{.localport}},4222" ./{{.applinux}}
list-images:
desc: list images
cmds:
- ops image list
# - ops image list -t {{.cloud}} -c {{.configpath}}
create-image:
# This fails to delete the source image
desc: create image locally
dir: ./build
cmds:
- task: build
- ops image create {{.applinux}} -c {{.configpath}} -i {{.imagename}} -t {{.cloud}}
delete-image:
desc: delete the image
cmds:
# Note: requires GOOGLE_APPLICATION_CREDENTIALS, GOOGLE_CLOUD_PROJECT, and
# GOOGLE_CLOUD_ZONE environment variables
- ops image delete {{.imagename}}.img
- ops image delete {{.imagename}}
create-instance:
# Does not check to see if the cloud image is there and will fail if not
# There are problems here with Google complaining of a pre-existing image
desc: create an instance in cloud
cmds:
# - task: create-image
- ops instance create {{.imagename}} -t {{.cloud}} -c {{.configpath}}
- echo "You can access the instance at the IP listed on port {{.cloudport}}"
delete-instance:
desc: delete a remote instance {{.imagename}}
cmds:
- ops instance delete {{.imagename}}
list-instances:
desc: list instances in cloud
cmds:
- ops instance list -t {{.cloud}} -c {{.configpath}}
firewall-allow-http:
desc: allow http port access
cmds:
- gcloud compute firewall-rules create http_allow --allow tcp:80,tcp:443,tcp:8000
# - gcloud compute instances add-tags nanovms-test-image-1627604881 --tags http-server,https-server
test-instance:
desc: Test deployed cloud instance
cmds:
- task: create-instance
- curl http://127.0.0.1:{{.localport}}/transactions
# Things to do
# - Delete instance
# - Delete GCP image
# - https://cloud.google.com/sdk/gcloud/reference/compute/images/delete
# - Use image to make template
# - https://cloud.google.com/compute/docs/instance-templates/create-instance-templates
# - Use template to make managed instance group (MIG)
# - https://cloud.google.com/compute/docs/instance-groups/creating-groups-of-managed-instances
# - Modify MIG
# - https://cloud.google.com/compute/docs/instance-groups/updating-migs
# - Learn how to replace template used by MIG