-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrun_flex_template.go
More file actions
87 lines (75 loc) · 2.58 KB
/
run_flex_template.go
File metadata and controls
87 lines (75 loc) · 2.58 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
package main
import (
"context"
"fmt"
"os"
"dagger.io/dagger"
)
func main() {
projectId := os.Getenv("PROJECT_ID")
location := os.Getenv("LOCATION")
jobName := os.Getenv("JOB_NAME")
metadataTemplateFilePath := os.Getenv("METADATA_TEMPLATE_FILE_PATH")
tempLocation := os.Getenv("TEMP_LOCATION")
stagingLocation := os.Getenv("STAGING_LOCATION")
saEmail := os.Getenv("SA_EMAIL")
inputFile := os.Getenv("INPUT_FILE")
sideInputFile := os.Getenv("SIDE_INPUT_FILE")
teamLeagueDataset := os.Getenv("TEAM_LEAGUE_DATASET")
teamLeagueTable := os.Getenv("TEAM_STATS_TABLE")
jobType := os.Getenv("JOB_TYPE")
failureOutputDataset := os.Getenv("FAILURE_OUTPUT_DATASET")
failureOutputTable := os.Getenv("FAILURE_OUTPUT_TABLE")
failureFeatureName := os.Getenv("FAILURE_FEATURE_NAME")
ctx := context.Background()
client, err := dagger.Connect(ctx, dagger.WithLogOutput(os.Stdout))
if err != nil {
panic(err)
}
defer client.Close()
hostSourceDir := client.Host().Directory(".", dagger.HostDirectoryOpts{})
activateServiceAccount := []string{
"gcloud",
"auth",
"activate-service-account",
saEmail,
"--key-file=./secrets/sa-dataflow.json",
fmt.Sprintf("--project=%s", projectId),
}
source := client.Container().
From("google/cloud-sdk:420.0.0-slim").
WithMountedDirectory("/src", hostSourceDir).
WithWorkdir("/src").
Directory(".")
runFlexTemplate := client.Container().
From("google/cloud-sdk:420.0.0-slim").
WithDirectory(".", source).
WithEnvVariable("CI_SERVICE_NAME", "dagger").
WithEnvVariable("PROJECT_ID", projectId).
WithEnvVariable("LOCATION", location).
WithEnvVariable("JOB_NAME", jobName).
WithEnvVariable("METADATA_TEMPLATE_FILE_PATH", metadataTemplateFilePath).
WithEnvVariable("TEMP_LOCATION", tempLocation).
WithEnvVariable("STAGING_LOCATION", stagingLocation).
WithEnvVariable("SA_EMAIL", saEmail).
WithEnvVariable("INPUT_FILE", inputFile).
WithEnvVariable("SIDE_INPUT_FILE", sideInputFile).
WithEnvVariable("TEAM_LEAGUE_DATASET", teamLeagueDataset).
WithEnvVariable("TEAM_STATS_TABLE", teamLeagueTable).
WithEnvVariable("JOB_TYPE", jobType).
WithEnvVariable("FAILURE_OUTPUT_DATASET", failureOutputDataset).
WithEnvVariable("FAILURE_OUTPUT_TABLE", failureOutputTable).
WithEnvVariable("FAILURE_FEATURE_NAME", failureFeatureName).
WithEnvVariable("GOOGLE_APPLICATION_CREDENTIALS", "./secrets/sa-dataflow.json").
WithExec(activateServiceAccount).
WithExec([]string{
"sh",
"-c",
"./scripts/run_dataflow_job.sh",
})
out, err := runFlexTemplate.Stdout(ctx)
if err != nil {
panic(err)
}
fmt.Printf("Published image to: %s\n", out)
}