-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmage.go
55 lines (47 loc) · 1.12 KB
/
mage.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// +build mage
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/magefile/mage/sh"
)
const (
name = "mapplibs"
port = "3000"
nodeVersion = "12"
)
// Install makes sure we have all the modules we need are installed.
func Install() error {
return frontDockerCmd("npm", "install")
}
// Build creates a static version of the site.
func Build() error {
return frontDockerCmd("npm", "run", "build")
}
// Run starts listening for connections in the docker environment
func Run() error {
// If we're running, we obviously do not need the build path!
if _, err := os.Stat("./build"); err == nil {
err = sh.Run("rm", "-r", "./build")
if err != nil {
return err
}
}
return frontDockerCmd("npm", "run", "start")
}
func frontDockerCmd(cmd ...string) error {
p, _ := filepath.Abs("./")
args := []string{"run", "--rm",
"--name", name,
"--label", "traefik.enable=true",
"--expose", port,
"--network", "lana-local",
"-v", fmt.Sprintf("%v:/front:cached", p),
"-w", "/front",
"-it", // Interactve!
"node:" + nodeVersion,
}
args = append(args, cmd...)
return sh.Run("docker", args...)
}