diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/default.nix | 2 | ||||
-rw-r--r-- | tools/govanity/Dockerfile | 30 | ||||
-rw-r--r-- | tools/govanity/README.org | 11 | ||||
-rw-r--r-- | tools/govanity/default.nix | 30 | ||||
-rw-r--r-- | tools/govanity/e2e_test.go | 31 | ||||
-rw-r--r-- | tools/govanity/fly.toml | 34 | ||||
-rw-r--r-- | tools/govanity/go.mod | 5 | ||||
-rw-r--r-- | tools/govanity/go.sum | 3 | ||||
-rw-r--r-- | tools/govanity/main.go | 134 | ||||
-rw-r--r-- | tools/govanity/templates/index.html.tpl | 14 | ||||
-rw-r--r-- | tools/govanity/templates/module.html.tpl | 12 | ||||
-rw-r--r-- | tools/govanity/vanity.yaml | 7 |
12 files changed, 0 insertions, 313 deletions
diff --git a/tools/default.nix b/tools/default.nix index 9f6d273..1044b09 100644 --- a/tools/default.nix +++ b/tools/default.nix @@ -3,8 +3,6 @@ pkgs.lib.makeScope pkgs.newScope (pkgs: { dnsupdate = pkgs.callPackage ./dnsupdate { }; - govanity = pkgs.callPackage ./govanity { }; - gerrit-hook = pkgs.callPackage ./gerrit-hook { }; ipconverter = pkgs.callPackage ./ipconverter { }; diff --git a/tools/govanity/Dockerfile b/tools/govanity/Dockerfile deleted file mode 100644 index 20df29f..0000000 --- a/tools/govanity/Dockerfile +++ /dev/null @@ -1,30 +0,0 @@ -FROM golang:1.16 AS builder - -ENV USER=app -RUN adduser \ - --disabled-password \ - --gecos "" \ - --home "/src" \ - --shell "/sbin/nologin" \ - --uid "10001" \ - "${USER}" - -WORKDIR /src - -ADD go.mod /src -ADD go.sum /src -RUN go mod download - -ADD . /src - -RUN CGO_ENABLED=0 GOOS=linux go build -trimpath -a -installsuffix cgo -ldflags '-extldflags "-static"' -o app . - -FROM scratch -COPY --from=builder /src/app /vanity -COPY --from=builder /src/vanity.yaml /vanity.yaml -COPY --from=builder /etc/passwd /etc/passwd -COPY --from=builder /etc/group /etc/group - -USER app:app - -ENTRYPOINT ["/vanity"] diff --git a/tools/govanity/README.org b/tools/govanity/README.org deleted file mode 100644 index b61021e..0000000 --- a/tools/govanity/README.org +++ /dev/null @@ -1,11 +0,0 @@ -A service to manage vanity URLs for go packages. - -It makes it possible to install tools like this: -#+begin_src sh -GOPRIVATE=1 go install -v golang.fcuny.net/tools/cmd/music-organizer@latest -#+end_src - -* Deployment -To update the application with the most recent code, run =nix run .#tools.govanity.deploy= from the root directory. -* Configuration -Add repositories to the [[file+sys:vanity.yaml][configuration file]]. diff --git a/tools/govanity/default.nix b/tools/govanity/default.nix deleted file mode 100644 index 750b91f..0000000 --- a/tools/govanity/default.nix +++ /dev/null @@ -1,30 +0,0 @@ -{ pkgs, buildGoModule, ... }: - -buildGoModule rec { - name = "govanity"; - src = ./.; - vendorSha256 = "sha256-iu2QE+vvenFWpOOz1NHVQHudiWkvkKqZvD4ZX4Xa1sY="; - nativeBuildInputs = with pkgs; [ go ]; - - deploy = pkgs.pkgs.writeShellScriptBin "run-deploy" '' - set -euo pipefail - export PATH=${pkgs.lib.makeBinPath [ pkgs.go pkgs.flyctl ]}:$PATH - - cd ${src} - - # run the tests, if they fail, we bail - echo "running tests ...." - ${pkgs.go}/bin/go test -v - - echo "deploying ...." - ${pkgs.flyctl}/bin/flyctl deploy - ''; - - meta = with pkgs.lib; { - description = "simple server for golang packages"; - homepage = "https://golang.fcuny.net"; - license = licenses.mit; - platforms = platforms.linux; - maintainers = [ ]; - }; -} diff --git a/tools/govanity/e2e_test.go b/tools/govanity/e2e_test.go deleted file mode 100644 index 157bcc2..0000000 --- a/tools/govanity/e2e_test.go +++ /dev/null @@ -1,31 +0,0 @@ -package main - -import ( - "net" - "net/http" - "testing" -) - -func TestConfigurationURL(t *testing.T) { - // we try a DNS resolution first. If it fails, it means we're - // likely in the sandbox, and we need to skip this test. - _, err := net.LookupHost("fcuny.net") - if err != nil { - t.Skipf("no network connectivity: %v", err) - } - - cfg, err := loadConfig() - if err != nil { - t.Fatal(err) - } - - for _, r := range cfg.Repositories { - res, err := http.Get(r.Repo) - if err != nil { - t.Errorf("failed to request %s: %v", r.Repo, err) - } - if res.StatusCode != http.StatusOK { - t.Errorf("HTTP status for %s is: %d - %s", r.Repo, res.StatusCode, res.Status) - } - } -} diff --git a/tools/govanity/fly.toml b/tools/govanity/fly.toml deleted file mode 100644 index 286cd1e..0000000 --- a/tools/govanity/fly.toml +++ /dev/null @@ -1,34 +0,0 @@ -app = "golang-fcuny-net" - -kill_signal = "SIGINT" -kill_timeout = 5 - -[env] - -[experimental] - allowed_public_ports = [] - auto_rollback = true - -[[services]] - internal_port = 8080 - protocol = "tcp" - script_checks = [] - - [services.concurrency] - hard_limit = 25 - soft_limit = 20 - type = "connections" - - [[services.ports]] - handlers = ["http"] - port = 80 - - [[services.ports]] - handlers = ["tls", "http"] - port = 443 - - [[services.tcp_checks]] - grace_period = "1s" - interval = "15s" - restart_limit = 6 - timeout = "2s" diff --git a/tools/govanity/go.mod b/tools/govanity/go.mod deleted file mode 100644 index d37f146..0000000 --- a/tools/govanity/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module golang.fcuny.net/vanity - -go 1.16 - -require gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b diff --git a/tools/govanity/go.sum b/tools/govanity/go.sum deleted file mode 100644 index 97f8991..0000000 --- a/tools/govanity/go.sum +++ /dev/null @@ -1,3 +0,0 @@ -gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= -gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/tools/govanity/main.go b/tools/govanity/main.go deleted file mode 100644 index d74db9b..0000000 --- a/tools/govanity/main.go +++ /dev/null @@ -1,134 +0,0 @@ -package main - -import ( - "bytes" - "embed" - "flag" - "fmt" - "html/template" - "io/ioutil" - "log" - "net/http" - "strings" - - "gopkg.in/yaml.v3" -) - -//go:embed templates -var tpls embed.FS - -type repository struct { - Name string `yaml:"name"` - Repo string `yaml:"repo"` -} - -type config struct { - BaseUrl string `yaml:"baseUrl"` - VCS string `yaml:"vcs"` - Repositories []repository `yaml:"repositories"` -} - -type moduleTmpl struct { - Name string - Repo string - VCS string - BaseUrl string -} - -func main() { - flag.Parse() - - cfg, err := loadConfig() - if err != nil { - log.Fatal(err) - } - - http.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) { - w.WriteHeader(200) - w.Write([]byte("ok")) - }) - - http.HandleFunc("/", goGet(cfg)) - - log.Printf("starting web server on :8080") - log.Fatal(http.ListenAndServe(":8080", nil)) -} - -func loadConfig() (*config, error) { - configPath := "./vanity.yaml" - - configYaml, err := ioutil.ReadFile(configPath) - if err != nil { - return nil, fmt.Errorf("failed to read configuration file %s: %v", configPath, err) - } - - var cfg config - err = yaml.Unmarshal(configYaml, &cfg) - if err != nil { - return nil, fmt.Errorf("failed to unmarshall configuration: %v", err) - } - - return &cfg, nil -} - -func goGet(cfg *config) http.HandlerFunc { - return func(w http.ResponseWriter, r *http.Request) { - if r.Method != http.MethodGet { - status := http.StatusMethodNotAllowed - http.Error(w, http.StatusText(status), status) - return - } - - if r.FormValue("go-get") == "1" { - pathParts := strings.Split(r.URL.Path, "/") - for _, m := range cfg.Repositories { - if pathParts[1] == m.Name { - goGetModule(w, r, m, cfg) - return - } - } - status := http.StatusNotFound - http.Error(w, http.StatusText(status), status) - return - } - browserURL(w, r, cfg) - } -} - -func goGetModule(w http.ResponseWriter, r *http.Request, m repository, cfg *config) { - tmpl, err := template.ParseFS(tpls, "templates/module.html.tpl") - if err != nil { - log.Fatal(err) - } - mod := moduleTmpl{ - VCS: cfg.VCS, - BaseUrl: cfg.BaseUrl, - Name: m.Name, - Repo: m.Repo, - } - var buf bytes.Buffer - if err := tmpl.Execute(&buf, mod); err != nil { - log.Printf("error: %+v", err) - status := http.StatusInternalServerError - http.Error(w, http.StatusText(status), status) - } else { - w.Header().Set("Cache-Control", "no-store") - w.Write(buf.Bytes()) - } -} - -func browserURL(w http.ResponseWriter, r *http.Request, cfg *config) { - tmpl, err := template.ParseFS(tpls, "templates/index.html.tpl") - if err != nil { - log.Fatal(err) - } - var buf bytes.Buffer - if err := tmpl.Execute(&buf, cfg); err != nil { - log.Printf("error: %+v", err) - status := http.StatusInternalServerError - http.Error(w, http.StatusText(status), status) - } else { - w.Header().Set("Cache-Control", "no-store") - w.Write(buf.Bytes()) - } -} diff --git a/tools/govanity/templates/index.html.tpl b/tools/govanity/templates/index.html.tpl deleted file mode 100644 index fd8fc56..0000000 --- a/tools/govanity/templates/index.html.tpl +++ /dev/null @@ -1,14 +0,0 @@ -<!DOCTYPE html> -<html> - <head> - <title>golang repo</title> - <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> - </head> - <body> - <ul> - {{ range $idx, $m := .Repositories }} - <li>go get <a href="{{ $m.Repo }}">{{ $.BaseUrl }}/{{ $m.Name }}/</a></li> - {{end}} - </ul> - </body> -</html> diff --git a/tools/govanity/templates/module.html.tpl b/tools/govanity/templates/module.html.tpl deleted file mode 100644 index fab3414..0000000 --- a/tools/govanity/templates/module.html.tpl +++ /dev/null @@ -1,12 +0,0 @@ -<!DOCTYPE html> -<html> - <head> - <title>{{.Name}}: golang repo</title> - <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> - <meta name="go-import" content="{{.BaseUrl}}/{{.Name}} {{.VCS}} {{.Repo}}"> - <meta name="go-source" content="{{.BaseUrl}}/{{.Name}} _ {{.Repo}}/src{/dir} {{.Repo}}/src{/dir}/{file}/#L{line}"> - </head> - <body> - go get {{.BaseUrl}}/{{.Name}} - </body> -</html> diff --git a/tools/govanity/vanity.yaml b/tools/govanity/vanity.yaml deleted file mode 100644 index 29ffd1c..0000000 --- a/tools/govanity/vanity.yaml +++ /dev/null @@ -1,7 +0,0 @@ -baseUrl: golang.fcuny.net -vcs: git -repositories: - - name: vanity - repo: https://git.fcuny.net/world/tree/tools/govanity - - name: mpd-stats - repo: https://git.fcuny.net/world/tree/tools/mpd-stats |