Merge pull request #7 from Xe/rip-out-mage

Rip out mage
This commit is contained in:
Cadey Ratio 2018-07-01 13:36:38 -07:00 committed by GitHub
commit b0e0b10823
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
48 changed files with 30 additions and 567 deletions

View File

@ -1,4 +1,16 @@
FROM xena/christine.website:1.1-47-g3228e3b FROM xena/go:1.10 AS build
COPY . /root/go/src/github.com/Xe/site
RUN CGO_ENABLED=0 GOBIN=/root go install github.com/Xe/site/cmd/site
FROM xena/alpine
EXPOSE 5000 EXPOSE 5000
RUN apk add --no-cache bash RUN apk add --no-cache bash
COPY --from=build /root/site /site/site
COPY ./static2 /site/static
COPY ./templates /site/templates
COPY ./blog /site/blog
COPY ./css /site/css
COPY ./run.sh /site/run.sh
HEALTHCHECK CMD curl --fail http://127.0.0.1:5000 || exit 1
CMD /site/run.sh CMD /site/run.sh

36
box.rb
View File

@ -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"

View File

@ -12,7 +12,6 @@ import (
"sync" "sync"
"time" "time"
"github.com/GeertJohan/go.rice"
"github.com/Xe/jsonfeed" "github.com/Xe/jsonfeed"
"github.com/Xe/ln" "github.com/Xe/ln"
"github.com/gorilla/feeds" "github.com/gorilla/feeds"
@ -135,17 +134,12 @@ func Build() (*Site, error) {
sort.Sort(sort.Reverse(s.Posts)) sort.Sort(sort.Reverse(s.Posts))
cb, err := rice.FindBox("css") resumeData, err := ioutil.ReadFile("./static/resume/resume.md")
if err != nil { if err != nil {
return nil, err return nil, err
} }
sb, err := rice.FindBox("static") s.Resume = template.HTML(blackfriday.Run(resumeData))
if err != nil {
return nil, err
}
s.Resume = template.HTML(blackfriday.Run(sb.MustBytes("resume/resume.md")))
for _, item := range s.Posts { for _, item := range s.Posts {
itime, _ := time.Parse("2006-01-02", item.Date) itime, _ := time.Parse("2006-01-02", item.Date)
@ -174,8 +168,8 @@ func Build() (*Site, error) {
s.mux.HandleFunc("/blog.atom", s.createAtom) s.mux.HandleFunc("/blog.atom", s.createAtom)
s.mux.HandleFunc("/blog.json", s.createJsonFeed) s.mux.HandleFunc("/blog.json", s.createJsonFeed)
s.mux.HandleFunc("/blog/", s.showPost) s.mux.HandleFunc("/blog/", s.showPost)
s.mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(sb.HTTPBox()))) s.mux.Handle("/css/", http.FileServer(http.Dir(".")))
s.mux.Handle("/css/", http.StripPrefix("/css/", http.FileServer(cb.HTTPBox()))) s.mux.Handle("/static/", http.FileServer(http.Dir(".")))
return s, nil return s, nil
} }

80
mage.go
View File

@ -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
}

View File

@ -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)
}

File diff suppressed because one or more lines are too long

7
scripts/deploy.sh Executable file
View File

@ -0,0 +1,7 @@
#!/bin/sh
set -e
set -x
docker build .
git push dokku master

6
scripts/setupremote.sh Executable file
View File

@ -0,0 +1,6 @@
#!/bin/sh
set -e
set -x
git remote add dokku dooku@minipaas.xeserv.us:christine

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

Before

Width:  |  Height:  |  Size: 17 KiB

After

Width:  |  Height:  |  Size: 17 KiB

View File

Before

Width:  |  Height:  |  Size: 3.0 KiB

After

Width:  |  Height:  |  Size: 3.0 KiB

View File

Before

Width:  |  Height:  |  Size: 4.1 KiB

After

Width:  |  Height:  |  Size: 4.1 KiB

View File

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 8.5 KiB

View File

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

View File

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

Before

Width:  |  Height:  |  Size: 4.8 KiB

After

Width:  |  Height:  |  Size: 4.8 KiB

View File

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 5.0 KiB

View File

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

Before

Width:  |  Height:  |  Size: 6.5 KiB

After

Width:  |  Height:  |  Size: 6.5 KiB

View File

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

Before

Width:  |  Height:  |  Size: 18 KiB

After

Width:  |  Height:  |  Size: 18 KiB

View File

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 1.7 KiB

View File

Before

Width:  |  Height:  |  Size: 2.7 KiB

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

Before

Width:  |  Height:  |  Size: 8.5 KiB

After

Width:  |  Height:  |  Size: 8.5 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

Before

Width:  |  Height:  |  Size: 40 KiB

After

Width:  |  Height:  |  Size: 40 KiB

View File

Before

Width:  |  Height:  |  Size: 5.9 KiB

After

Width:  |  Height:  |  Size: 5.9 KiB

View File

Before

Width:  |  Height:  |  Size: 144 KiB

After

Width:  |  Height:  |  Size: 144 KiB

View File

Before

Width:  |  Height:  |  Size: 89 KiB

After

Width:  |  Height:  |  Size: 89 KiB

View File

Before

Width:  |  Height:  |  Size: 41 KiB

After

Width:  |  Height:  |  Size: 41 KiB