-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmage.go
More file actions
60 lines (53 loc) · 1.27 KB
/
mage.go
File metadata and controls
60 lines (53 loc) · 1.27 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
//go:build mage
package main
import (
"io/ioutil"
"path"
"github.com/magefile/mage/sh"
)
const (
name = "provider"
runImage = "us-docker.pkg.dev/invopop/repos/golang:1.24.3-alpine"
)
// Protocol takes the protobuf source and converts them into go code.
func Protocol() error {
p := "./gateway"
args := []string{
"protoc",
"--go_out=" + p,
"--proto_path=" + p,
}
files, _ := ioutil.ReadDir(p)
for _, file := range files {
if path.Ext(file.Name()) == ".proto" {
args = append(args, path.Join(p, file.Name()))
}
}
return dockerRunCmd(name+"-proto", "", args...)
}
func dockerRunCmd(name, publicPort string, cmd ...string) error {
args := []string{
"run",
"--rm",
"--name", name,
"--network", "invopop-local",
"-v", "$PWD:/src",
"-w", "/src",
"-it", // interactive
}
if publicPort != "" {
args = append(args,
"--label", "traefik.enable=true",
"--label", "traefik.http.routers."+name+".rule=Host(`"+name+".invopop.dev`)",
"--label", "traefik.http.routers."+name+".tls=true",
"--expose", publicPort,
)
}
args = append(args, runImage)
args = append(args, cmd...)
return sh.RunV("docker", args...)
}
// Shell runs an interactive shell within a docker container.
func Shell() error {
return dockerRunCmd(name+"-shell", "", "ash")
}