Skip to content

Commit cbb5112

Browse files
committed
cmd/relui,internal/relui: create and run workflows
Create and run workflows, storing state in a postgres database. Generate database queries using sqlc, which allows the author to have complete control over the query structure. The basic structure of creating and running a workflow works, but there is still much work to do in terms of selecting which workflow to create, recording logs, maintaining a list of currently running workflows, and recording workflow-level results. Task persistence needs to be updated, as the current implementation cannot be resumed due to losing the type during marshalling. For golang/go#47401 Change-Id: I9ccddf117d023f70568de655c482820a1152d9cb Reviewed-on: https://go-review.googlesource.com/c/build/+/350449 Trust: Alexander Rakoczy <[email protected]> Run-TryBot: Alexander Rakoczy <[email protected]> TryBot-Result: Go Bot <[email protected]> Reviewed-by: Heschi Kreinick <[email protected]>
1 parent 7692cd0 commit cbb5112

17 files changed

+852
-92
lines changed

cmd/relui/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ DEV_CFG := ${HOME}/.local/share/relui
1818

1919
.PHONY: dev
2020
dev: postgres-dev docker
21-
docker run --rm --name=relui-dev -v $(POSTGRES_RUN_DEV) -p 8080:8080 $(DOCKER_TAG)
21+
docker run --rm --name=relui-dev -v $(POSTGRES_RUN_DEV) -e PGUSER=$(POSTGRES_USER) -e PGDATABASE=relui-dev -p 8080:8080 $(DOCKER_TAG)
2222

2323
.PHONY: postgres-dev
2424
postgres-dev: $(DEV_CFG)/pgpass
@@ -38,7 +38,7 @@ schema.sql: $(MIGRATION_FILES) $(GO_FILES)
3838

3939
.PHONY: test
4040
test: postgres-dev docker-test
41-
docker run --rm --name=relui-test -v $(POSTGRES_RUN_DEV) -e RELUI_TEST_DATABASE="host=/var/run/postgresql user=postgres database=relui-test" golang/relui-test:$(VERSION)
41+
docker run --rm --name=relui-test -v $(POSTGRES_RUN_DEV) -e PGUSER=$(POSTGRES_USER) -e PGDATABASE=relui-test golang/relui-test:$(VERSION)
4242

4343
.PHONY: docker
4444
docker:

cmd/relui/README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,44 @@
99
```
1010

1111
relui is a web interface for managing the release process of Go.
12+
13+
## Development
14+
15+
Run the command with the appropriate
16+
[libpq-style environment variables](https://www.postgresql.org/docs/current/libpq-envars.html)
17+
set.
18+
19+
```bash
20+
PGHOST=localhost PGDATABASE=relui-dev PGUSER=postgres go run ./
21+
```
22+
23+
Alternatively, using docker:
24+
25+
```bash
26+
make dev
27+
```
28+
29+
### Updating Queries
30+
31+
Create or edit SQL files in `internal/relui/queries`.
32+
After editing the query, run `sqlc generate` in this directory. The
33+
`internal/relui/db` package contains the generated code.
34+
35+
See [sqlc documentation](https://docs.sqlc.dev/en/stable/) for further
36+
details.
37+
38+
## Testing
39+
40+
Run go test with the appropriate
41+
[libpq-style environment variables](https://www.postgresql.org/docs/current/libpq-envars.html)
42+
set. If the database connection fails, database integration tests will
43+
be skipped. If PGDATABSE is unset, relui-test is used by default.
44+
45+
```bash
46+
PGHOST=localhost PGUSER=postgres go test -v ./... ../../internal/relui/...
47+
```
48+
49+
Alternatively, using docker:
50+
```bash
51+
make test
52+
```

cmd/relui/main.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ import (
1414
"log"
1515
"os"
1616

17+
"github.com/jackc/pgx/v4/pgxpool"
1718
"golang.org/x/build/internal/relui"
1819
)
1920

2021
var (
21-
pgConnect = flag.String("pg-connect", "host=/var/run/postgresql user=postgres database=relui-dev", "Postgres connection string or URI")
22+
pgConnect = flag.String("pg-connect", "", "Postgres connection string or URI. If empty, libpq connection defaults are used.")
2223
onlyMigrate = flag.Bool("only-migrate", false, "Exit after running migrations. Migrations are run by default.")
2324
)
2425

@@ -31,12 +32,12 @@ func main() {
3132
if *onlyMigrate {
3233
return
3334
}
34-
d := new(relui.PgStore)
35-
if err := d.Connect(ctx, *pgConnect); err != nil {
35+
db, err := pgxpool.Connect(ctx, *pgConnect)
36+
if err != nil {
3637
log.Fatal(err)
3738
}
38-
defer d.Close()
39-
s, err := relui.NewServer(ctx, d)
39+
defer db.Close()
40+
s := relui.NewServer(db)
4041
if err != nil {
4142
log.Fatalf("relui.NewServer() = %v", err)
4243
}

cmd/relui/sqlc.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: "1"
2+
packages:
3+
- name: "db"
4+
path: "../../internal/relui/db"
5+
queries: "../../internal/relui/queries"
6+
schema: "schema.sql"
7+
engine: "postgresql"
8+
sql_package: "pgx/v4"
9+
overrides:
10+
- go_type: "database/sql.NullString"
11+
db_type: "jsonb"
12+
nullable: true

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ require (
2424
github.com/googleapis/gax-go/v2 v2.0.5
2525
github.com/googleapis/google-cloud-go-testing v0.0.0-20200911160855-bcd43fbb19e8
2626
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7
27+
github.com/jackc/pgconn v1.10.0
2728
github.com/jackc/pgx/v4 v4.13.0
2829
github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1
2930
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07

internal/relui/db/db.go

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/relui/db/models.go

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)