aboutsummaryrefslogtreecommitdiff
path: root/mage.go
blob: 1c406b283b5ac88151c76da7c49acc356986422f (plain)
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
// +build mage

package main

import (
	"context"
	"fmt"
	"os"

	"github.com/magefile/mage/mg"
)

func do(cmd string, args ...string) {
	shouldWork(context.Background(), nil, wd, cmd, args...)
}

// Setup installs the tools that other parts of the build process depend on.
func Setup(ctx context.Context) {
	// go tools
	do("go", "get", "-u", "-v", "github.com/GeertJohan/go.rice/rice")

	do("git", "remote", "add", "dokku", "dokku@minipaas.xeserv.us")
}

// Generate runs all of the code generation.
func Generate(ctx context.Context) {
	shouldWork(ctx, nil, wd, "rice", "embed-go")
}

// Docker creates the docker image xena/christine.website using box(1).
func Docker() {
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	mg.Deps(Generate)

	shouldWork(ctx, nil, wd, "box", "box.rb")
}

// Deploy does the work needed to deploy this image to the dokku server.
func Deploy(ctx context.Context) error {
	mg.Deps(Docker)

	tag, err := gitTag()
	if err != nil {
		return err
	}

	do("docker", "tag", "xena/christine.website", "xena/christine.website:"+tag)
	do("docker", "push", "xena/christine.website:"+tag)

	const dockerfileTemplate = `FROM xena/christine.website:${VERSION}
EXPOSE 5000
RUN apk add --no-cache bash
CMD /site/run.sh`
	data := os.Expand(dockerfileTemplate, func(inp string) string {
		switch inp {
		case "VERSION":
			return tag
		default:
			return "<unknown arg " + inp + ">"
		}
	})

	os.Remove("Dockerfile")
	fout, err := os.Create("Dockerfile")
	if err != nil {
		return err
	}

	fmt.Fprintln(fout, data)
	fout.Close()

	do("git", "add", "Dockerfile")
	do("git", "commit", "-m", "Dockerfile: update for deployment of version "+tag)
	do("git", "push", "dokku", "master")

	return nil
}