site/mage.go

81 lines
1.7 KiB
Go
Raw Normal View History

2017-12-13 18:30:41 +00:00
// +build mage
package main
import (
"context"
2017-12-13 19:24:20 +00:00
"fmt"
"os"
2017-12-13 18:30:41 +00:00
"github.com/magefile/mage/mg"
)
2017-12-13 19:42:17 +00:00
func do(cmd string, args ...string) {
shouldWork(context.Background(), nil, wd, cmd, args...)
}
2017-12-13 18:30:41 +00:00
// Setup installs the tools that other parts of the build process depend on.
func Setup(ctx context.Context) {
2017-12-13 19:42:17 +00:00
// go tools
do("go", "get", "-u", "-v", "github.com/GeertJohan/go.rice/rice")
do("git", "remote", "add", "dokku", "dokku@minipaas.xeserv.us")
2017-12-13 18:30:41 +00:00
}
// Generate runs all of the code generation.
func Generate(ctx context.Context) {
shouldWork(ctx, nil, wd, "rice", "embed-go")
}
2017-12-13 19:42:17 +00:00
// Docker creates the docker image xena/christine.website using box(1).
func Docker() {
2017-12-13 18:30:41 +00:00
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
2017-12-13 19:42:17 +00:00
mg.Deps(Generate)
2017-12-13 18:30:41 +00:00
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 {
2017-12-13 19:42:17 +00:00
mg.Deps(Docker)
2017-12-13 18:30:41 +00:00
2017-12-13 19:24:20 +00:00
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}
2017-12-13 19:42:17 +00:00
EXPOSE 5000
RUN apk add --no-cache bash
CMD /site/run.sh`
2017-12-13 19:24:20 +00:00
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
}
2017-12-13 19:42:17 +00:00
fmt.Fprintln(fout, data)
2017-12-13 19:24:20 +00:00
fout.Close()
do("git", "add", "Dockerfile")
2017-12-13 19:43:21 +00:00
do("git", "commit", "-m", "Dockerfile: update for deployment of version "+tag)
2017-12-13 19:24:20 +00:00
do("git", "push", "dokku", "master")
2017-12-13 19:55:27 +00:00
do("git", "push")
2017-12-13 18:30:41 +00:00
return nil
}