-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
38 lines (31 loc) · 901 Bytes
/
main.go
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
package main
import (
"fmt"
"io/ioutil"
"cloud.google.com/go/datastore"
"golang.org/x/net/context"
)
// YAMLWrapper stores build info. Cannot store cloudbuild.Build directly.
type YAMLWrapper struct {
Value string
}
func main() {
ctx := context.Background()
// Set environment variable DATASTORE_PROJECT_ID.
dsClient, err := datastore.NewClient(ctx, "")
if err != nil {
panic(fmt.Sprintf("Cannot initialize Datastore: %q", err))
}
// Load cloudbuild.yaml and save to Datastore.
k := datastore.NameKey("YAMLWrapper", "ID", nil)
y := new(YAMLWrapper)
dat, err := ioutil.ReadFile("cloudbuild.yaml")
if err != nil {
panic(fmt.Sprintf("Cannot load cloudbuild.yaml: %q", err))
}
y.Value = string(dat)
if _, err := dsClient.Put(ctx, k, y); err != nil {
panic(fmt.Sprintf("Error persisting to Datastore: %q", err))
}
fmt.Printf("Uploaded YAML to Datastore successfully\n")
}