diff options
| author | Christine Dodrill <me@christine.website> | 2019-04-01 10:05:03 -0700 |
|---|---|---|
| committer | Christine Dodrill <me@christine.website> | 2019-04-01 10:05:28 -0700 |
| commit | f06f021f402270951f849dde7bee3f3340b8a1d5 (patch) | |
| tree | baee337aab524f162b349d254d21c2d8f2716d44 /cmd/within.website | |
| parent | ba91a17859267201b1d1f0e71da465b1464d940f (diff) | |
| download | x-f06f021f402270951f849dde7bee3f3340b8a1d5.tar.xz x-f06f021f402270951f849dde7bee3f3340b8a1d5.zip | |
reorg
Diffstat (limited to 'cmd/within.website')
| -rw-r--r-- | cmd/within.website/.gitignore | 2 | ||||
| -rw-r--r-- | cmd/within.website/build.go | 39 | ||||
| -rw-r--r-- | cmd/within.website/main.go | 70 |
3 files changed, 111 insertions, 0 deletions
diff --git a/cmd/within.website/.gitignore b/cmd/within.website/.gitignore new file mode 100644 index 0000000..4697cff --- /dev/null +++ b/cmd/within.website/.gitignore @@ -0,0 +1,2 @@ +web +slug.tar.gz
\ No newline at end of file diff --git a/cmd/within.website/build.go b/cmd/within.website/build.go new file mode 100644 index 0000000..d72d9f5 --- /dev/null +++ b/cmd/within.website/build.go @@ -0,0 +1,39 @@ +//+build ignore + +// Builds and deploys the application to minipaas. +package main + +import ( + "context" + "log" + "os" + + "github.com/Xe/x/internal/greedo" + "github.com/Xe/x/internal/minipaas" + "github.com/Xe/x/internal/yeet" +) + +func main() { + ctx, cancel := context.WithCancel(context.Background()) + defer cancel() + + 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 := greedo.CopyFile(fname, fin) + if err != nil { + log.Fatal(err) + } + + err = minipaas.Exec("tar:from within.website " + pubURL) + if err != nil { + log.Fatal(err) + } +} diff --git a/cmd/within.website/main.go b/cmd/within.website/main.go new file mode 100644 index 0000000..ba4f090 --- /dev/null +++ b/cmd/within.website/main.go @@ -0,0 +1,70 @@ +package main + +import ( + "context" + "flag" + "net/http" + + "github.com/Xe/x/internal" + "github.com/mmikulicic/stringlist" + "go.jonnrb.io/vanity" + "within.website/ln" + "within.website/ln/opname" +) + +var ( + domain = flag.String("domain", "within.website", "domain this is run on") + githubUsername = flag.String("github-user", "Xe", "GitHub username for GitHub repos") + gogsDomain = flag.String("gogs-url", "https://git.xeserv.us", "Gogs domain to use") + gogsUsername = flag.String("gogs-username", "xena", "Gogs username for above Gogs instance") + port = flag.String("port", "2134", "HTTP port to listen on") + + githubRepos = stringlist.Flag("github-repo", "list of GitHub repositories to use") + gogsRepos = stringlist.Flag("gogs-repo", "list of Gogs repositories to use") +) + +var githubReposDefault = []string{ + "ln", + "x", + "xultybau", + "johaus", + "confyg", + "derpigo", +} + +var gogsReposDefault = []string{ + "gorqlite", +} + +func main() { + internal.HandleStartup() + ctx := opname.With(context.Background(), "main") + ctx = ln.WithF(ctx, ln.F{ + "domain": *domain, + }) + + if len(*githubRepos) == 0 { + *githubRepos = githubReposDefault + } + + if len(*gogsRepos) == 0 { + *gogsRepos = gogsReposDefault + } + + for _, repo := range *githubRepos { + http.Handle("/"+repo, vanity.GitHubHandler(*domain+"/"+repo, *githubUsername, repo, "https")) + http.Handle("/"+repo+"/", vanity.GitHubHandler(*domain+"/"+repo, *githubUsername, repo, "https")) + + ln.Log(ctx, ln.F{"github_repo": repo, "github_user": *githubUsername}, ln.Info("adding github repo")) + } + + for _, repo := range *gogsRepos { + http.Handle("/"+repo, vanity.GogsHandler(*domain+"/"+repo, *gogsDomain, *gogsUsername, repo, "https")) + http.Handle("/"+repo+"/", vanity.GogsHandler(*domain+"/"+repo, *gogsDomain, *gogsUsername, repo, "https")) + + ln.Log(ctx, ln.F{"gogs_domain": *gogsDomain, "gogs_username": *gogsUsername, "gogs_repo": repo}, ln.Info("adding gogs repo")) + } + + ln.Log(ctx, ln.F{"port": *port}, ln.Info("Listening on HTTP")) + http.ListenAndServe(":"+*port, nil) +} |
