-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmage.go
More file actions
63 lines (54 loc) · 1.43 KB
/
mage.go
File metadata and controls
63 lines (54 loc) · 1.43 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
//go:build mage
// +build mage
package main
import (
"github.com/magefile/mage/sh"
)
const (
name = "gobl.ruby"
runImage = "ruby:2.7"
)
// Runs gem's setup script (install dependencies…)
func Setup() error {
return dockerRunCmd(name+"-install", "", "bin/setup")
}
// Runs gem's rspec tests.
func Spec() error {
return dockerRunCmd(name, "", "bundle", "exec", "rake", "spec")
}
// Shell runs an interactive shell within a docker container.
func Shell() error {
return dockerRunCmd(name+"-shell", "", "bash")
}
// Starts yard server
func YardServer() error {
return dockerRunCmd("gobl-ruby-yard", "8808", "yard", "server", "--reload")
}
// Runs an IRB session with the library required.
func Console() error {
return dockerRunCmd(name, "", "bin/console")
}
func dockerRunCmd(name, publicPort string, cmd ...string) error {
args := []string{
"run",
"--rm",
"--name", name,
"--network", "invopop-local",
"-v", "$PWD:/app",
"-v", "$PWD/.tmp_bundle:/usr/local/bundle",
"-w", "/app",
"-it",
}
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",
"--label", "traefik.http.services."+name+".loadbalancer.server.port="+publicPort,
"--expose", publicPort,
)
}
args = append(args, runImage)
args = append(args, cmd...)
return sh.RunV("docker", args...)
}