blob: 9453a34beeeffee2fcc821872e1b854e3d03d1d8 [file] [log] [blame]
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// relui is a web interface for managing the release process of Go.
package main
import (
"context"
"flag"
"log"
"os"
"github.com/jackc/pgx/v4/pgxpool"
"golang.org/x/build/internal/relui"
)
var (
pgConnect = flag.String("pg-connect", "", "Postgres connection string or URI. If empty, libpq connection defaults are used.")
migrateOnly = flag.Bool("migrate-only", false, "Exit after running migrations. Migrations are run by default.")
downUp = flag.Bool("migrate-down-up", false, "Run all Up migration steps, then the last down migration step, followed by the final up migration. Exits after completion.")
)
func main() {
flag.Parse()
ctx := context.Background()
if err := relui.InitDB(ctx, *pgConnect); err != nil {
log.Fatalf("relui.InitDB() = %v", err)
}
if *migrateOnly {
return
}
if *downUp {
if err := relui.MigrateDB(*pgConnect, true); err != nil {
log.Fatalf("relui.MigrateDB() = %v", err)
}
return
}
db, err := pgxpool.Connect(ctx, *pgConnect)
if err != nil {
log.Fatal(err)
}
defer db.Close()
s := relui.NewServer(db)
if err != nil {
log.Fatalf("relui.NewServer() = %v", err)
}
port := os.Getenv("PORT")
if port == "" {
port = "8080"
}
log.Printf("Listening on :" + port)
log.Fatal(s.Serve(port))
}