mage: add deployment functions
This commit is contained in:
parent
311e876f23
commit
141a3320ff
|
@ -1 +1,2 @@
|
|||
*.asar
|
||||
cw.tar
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
// +build mage
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/magefile/mage/mg"
|
||||
)
|
||||
|
||||
// Setup installs the tools that other parts of the build process depend on.
|
||||
func Setup(ctx context.Context) {
|
||||
shouldWork(ctx, nil, wd, "go", "get", "-u", "-v", "github.com/GeertJohan/go.rice/rice")
|
||||
}
|
||||
|
||||
// Generate runs all of the code generation.
|
||||
func Generate(ctx context.Context) {
|
||||
shouldWork(ctx, nil, wd, "rice", "embed-go")
|
||||
}
|
||||
|
||||
// Build creates the docker image xena/christine.website using box(1).
|
||||
func Build() {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
defer cancel()
|
||||
|
||||
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(Build)
|
||||
|
||||
do := func(cmd string, args ...string) {
|
||||
shouldWork(ctx, nil, wd, cmd, args...)
|
||||
}
|
||||
|
||||
do("docker", "save", "-o", "cw.tar", "xena/christine.website")
|
||||
do("scp", "cw.tar", "root@apps.xeserv.us:cw.tar")
|
||||
|
||||
return nil
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
// +build mage
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/jtolds/qod"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
var wd string
|
||||
|
||||
func init() {
|
||||
lwd, err := os.Getwd()
|
||||
qod.ANE(err)
|
||||
|
||||
wd = lwd
|
||||
}
|
||||
|
||||
// must end in a slash
|
||||
const pkgBase = "github.com/Xe/site/"
|
||||
|
||||
func output(cmd string, args ...string) (string, error) {
|
||||
c := exec.Command(cmd, args...)
|
||||
c.Env = os.Environ()
|
||||
c.Stderr = os.Stderr
|
||||
b, err := c.Output()
|
||||
if err != nil {
|
||||
return "", errors.Wrapf(err, `failed to run %v %q`, cmd, args)
|
||||
}
|
||||
return string(b), nil
|
||||
}
|
||||
|
||||
func gitTag() (string, error) {
|
||||
s, err := output("git", "describe", "--tags")
|
||||
if err != nil {
|
||||
ee, ok := errors.Cause(err).(*exec.ExitError)
|
||||
if ok && ee.Exited() {
|
||||
// probably no git tag
|
||||
return "dev", nil
|
||||
}
|
||||
return "", err
|
||||
}
|
||||
|
||||
return strings.TrimSuffix(s, "\n"), nil
|
||||
}
|
||||
|
||||
func shouldWork(ctx context.Context, env []string, dir string, cmdName string, args ...string) {
|
||||
loc, err := exec.LookPath(cmdName)
|
||||
qod.ANE(err)
|
||||
|
||||
cmd := exec.CommandContext(ctx, loc, args...)
|
||||
cmd.Dir = dir
|
||||
cmd.Env = append(env, os.Environ()...)
|
||||
|
||||
cmd.Stdout = os.Stdout
|
||||
cmd.Stderr = os.Stderr
|
||||
|
||||
log.Printf("starting process, env: %v, pwd: %s, cmd: %s, args: %v", env, dir, loc, args)
|
||||
err = cmd.Run()
|
||||
qod.ANE(err)
|
||||
}
|
||||
|
||||
func goBuild(ctx context.Context, env []string, dir string, pkgname string) {
|
||||
shouldWork(ctx, env, dir, "go", "build", "-v", pkgBase+pkgname)
|
||||
}
|
||||
|
||||
func goInstall(ctx context.Context, env []string, pkgname string) {
|
||||
shouldWork(ctx, nil, wd, "go", "install", pkgBase+pkgname)
|
||||
}
|
||||
|
||||
func goBuildPlugin(ctx context.Context, dir, pkgname, fname string) {
|
||||
if runtime.GOOS != "linux" {
|
||||
qod.Printlnf("plugins don't work on non-linux machines yet :(")
|
||||
return
|
||||
}
|
||||
|
||||
shouldWork(ctx, nil, dir, "go", "build", "-v", "-buildmode=plugin", "-o="+fname, pkgBase+pkgname)
|
||||
qod.Printlnf("built %s for %s", fname, runtime.GOOS)
|
||||
}
|
88
rice-box.go
88
rice-box.go
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue