aboutsummaryrefslogtreecommitdiff
path: root/cmd/within.website/build.go
blob: c27104d0ab29283a621abecd473c3916e7c3ce3a (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
//+build ignore

// Builds and deploys the application to minipaas.
package main

import (
	"context"
	"flag"
	"log"
	"net/http"
	"os"

	"github.com/shurcooL/vfsgen"
	"within.website/x/internal"
	"within.website/x/internal/kahless"
	"within.website/x/internal/minipaas"
	"within.website/x/internal/yeet"
)

var (
	genVFS = flag.Bool("gen-vfs", true, "if true, generate VFS")
	deploy = flag.Bool("deploy", true, "if true, deploy to minipaas via kahless")
)

func main() {
	internal.HandleStartup()
	ctx, cancel := context.WithCancel(context.Background())
	defer cancel()

	if *genVFS {
		err := vfsgen.Generate(http.Dir("./static"), vfsgen.Options{
			PackageName:  "main",
			BuildTags:    "!dev",
			VariableName: "assets",
		})
		if err != nil {
			log.Fatalln(err)
		}
	}

	if *deploy {
		env := append(os.Environ(), []string{"CGO_ENABLED=0", "GOOS=linux"}...)
		yeet.ShouldWork(ctx, env, yeet.WD, "go", "build", "-o=web")
		yeet.ShouldWork(ctx, env, yeet.WD, "appsluggr", "-web=web")
		fin, err := os.Open("slug.tar.gz")
		if err != nil {
			log.Fatal(err)
		}
		defer fin.Close()

		fname := "within.website-" + yeet.DateTag + ".tar.gz"
		pubURL, err := kahless.CopyFile(fname, fin)
		if err != nil {
			log.Fatal(err)
		}

		err = minipaas.Exec("tar:from within.website " + pubURL)
		if err != nil {
			log.Fatal(err)
		}
	}
}