diff --git a/Makefile b/Makefile index d12738c..9e61e3d 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ release: git push --tags build-binary: - go build -trimpath -o web/landing/www/binaries/hishtory-linux #-ldflags "-X main.GitCommit=`git rev-list -1 HEAD`" + go build -trimpath -o web/landing/www/binaries/hishtory-linux -ldflags "-X main.GitCommit=`git rev-list -1 HEAD`" install: build-binary web/landing/www/binaries/hishtory-linux install diff --git a/VERSION b/VERSION index 00750ed..b8626c4 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -3 +4 diff --git a/server/Dockerfile b/server/Dockerfile index 8162ad3..d6eca99 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -3,6 +3,6 @@ COPY go.mod ./ COPY go.sum ./ RUN unset GOPATH; go mod download COPY . ./ -RUN unset GOPATH; go build -o /server server/server.go +RUN unset GOPATH; cat VERSION; go build -o /server -ldflags "-X main.ReleaseVersion=v0.`cat VERSION`" server/server.go CMD [ "/server" ] diff --git a/server/server.go b/server/server.go index efbd564..0195b46 100644 --- a/server/server.go +++ b/server/server.go @@ -17,10 +17,13 @@ import ( ) const ( - POSTGRES_DB = "postgresql://postgres:O74Ji4735C@postgres-postgresql.default.svc.cluster.local:5432/hishtory?sslmode=disable" + PostgresDb = "postgresql://postgres:O74Ji4735C@postgres-postgresql.default.svc.cluster.local:5432/hishtory?sslmode=disable" ) -var GLOBAL_DB *gorm.DB +var ( + GLOBAL_DB *gorm.DB + ReleaseVersion string = "UNKNOWN" +) func apiESubmitHandler(w http.ResponseWriter, r *http.Request) { data, err := ioutil.ReadAll(r.Body) @@ -120,7 +123,7 @@ func OpenDB() (*gorm.DB, error) { return db, nil } - db, err := gorm.Open(postgres.Open(POSTGRES_DB), &gorm.Config{}) + db, err := gorm.Open(postgres.Open(PostgresDb), &gorm.Config{}) if err != nil { return nil, fmt.Errorf("failed to connect to the DB: %v", err) } @@ -130,6 +133,9 @@ func OpenDB() (*gorm.DB, error) { } func init() { + if ReleaseVersion == "UNKNOWN" { + panic("server.go was built without a ReleaseVersion!") + } InitDB() } @@ -149,6 +155,14 @@ func InitDB() { } } +func bindaryDownloadHandler(w http.ResponseWriter, r *http.Request) { + http.Redirect(w, r, fmt.Sprintf("https://github.com/ddworken/hishtory/releases/download/%s/hishtory-linux-amd64", ReleaseVersion), http.StatusFound) +} + +func attestationDownloadHandler(w http.ResponseWriter, r *http.Request) { + http.Redirect(w, r, fmt.Sprintf("https://github.com/ddworken/hishtory/releases/download/%s/hishtory-linux-amd64.intoto.jsonl", ReleaseVersion), http.StatusFound) +} + func main() { fmt.Println("Listening on localhost:8080") http.HandleFunc("/api/v1/esubmit", apiESubmitHandler) @@ -156,5 +170,7 @@ func main() { http.HandleFunc("/api/v1/ebootstrap", apiEBootstrapHandler) http.HandleFunc("/api/v1/eregister", apiERegisterHandler) http.HandleFunc("/api/v1/banner", apiBannerHandler) + http.HandleFunc("/download/hishtory-linux-amd64", bindaryDownloadHandler) + http.HandleFunc("/download/hishtory-linux-amd64.intoto.jsonl", attestationDownloadHandler) log.Fatal(http.ListenAndServe(":8080", nil)) }