rip out mage
This commit is contained in:
parent
7d8c210f14
commit
599712fab9
13
Dockerfile
13
Dockerfile
|
@ -1,4 +1,15 @@
|
|||
FROM xena/christine.website:1.1-47-g3228e3b
|
||||
FROM xena/go:1.10 AS build
|
||||
COPY . /root/go/src/github.com/Xe/site
|
||||
RUN GOBIN=/root go build github.com/Xe/site
|
||||
|
||||
FROM xena/alpine
|
||||
EXPOSE 5000
|
||||
RUN apk add --no-cache bash
|
||||
COPY --from=build /root/site /site/site
|
||||
COPY ./templates /site/templates
|
||||
COPY ./blog /site/blog
|
||||
COPY ./run.sh /site.sh
|
||||
COPY ./static /site/static
|
||||
|
||||
HEALTHCHECK CMD curl --fail http://127.0.0.1:5000 || exit 1
|
||||
CMD /site/run.sh
|
||||
|
|
36
box.rb
36
box.rb
|
@ -1,36 +0,0 @@
|
|||
from "xena/go:1.10"
|
||||
|
||||
### Copy files
|
||||
run "mkdir -p /site"
|
||||
|
||||
def put(file)
|
||||
copy "./#{file}", "/site/#{file}"
|
||||
end
|
||||
|
||||
files = [
|
||||
"gops.go",
|
||||
"hash.go",
|
||||
"html.go",
|
||||
"main.go",
|
||||
"rss.go",
|
||||
"run.sh",
|
||||
"templates",
|
||||
"blog",
|
||||
"rice-box.go"
|
||||
]
|
||||
|
||||
files.each { |x| put x }
|
||||
|
||||
copy "vendor/", "/root/go/src/"
|
||||
|
||||
### Build
|
||||
run "cd /site && go build -v"
|
||||
|
||||
### Cleanup
|
||||
run %q[ rm -rf /root/go /site/backend /root/sdk /site/*.go ]
|
||||
run %q[ rm -rf /usr/local/bin/go* ]
|
||||
|
||||
cmd "/site/run.sh"
|
||||
|
||||
flatten
|
||||
tag "xena/christine.website"
|
80
mage.go
80
mage.go
|
@ -1,80 +0,0 @@
|
|||
// +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")
|
||||
do("git", "push")
|
||||
|
||||
return nil
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
// +build mage
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"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)
|
||||
}
|
365
rice-box.go
365
rice-box.go
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,7 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
set -x
|
||||
|
||||
docker build .
|
||||
git push dokku master
|
|
@ -0,0 +1,6 @@
|
|||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
set -x
|
||||
|
||||
git remote add dokku dooku@minipaas.xeserv.us:christine
|
Loading…
Reference in New Issue