Skip to content

Commit e5cc9bc

Browse files
committed
Remove generated files from directory
1 parent 2731e7a commit e5cc9bc

11 files changed

Lines changed: 46 additions & 7250 deletions

File tree

broker/Dockerfile

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ COPY ncip/ ./ncip
2121
COPY zoom/ ./zoom
2222
COPY testutil/ ./testutil
2323

24+
# Directory generated sources are not stored in the repository.
25+
RUN --mount=type=cache,sharing=shared,target=/go/pkg/mod \
26+
cd /app/directory && \
27+
GOWORK=off go mod download && \
28+
GOWORK=off go generate .
29+
2430
# copy broker manifests before sources to leverage docker cache for mod downloads
2531
COPY broker/go.mod broker/go.sum ./broker/
2632

@@ -31,9 +37,6 @@ WORKDIR /app/broker
3137
RUN --mount=type=cache,sharing=shared,target=/go/pkg/mod \
3238
go mod download
3339

34-
# sources are generated before docker build
35-
# make sure make generate is run
36-
3740
# copy broker sources (changes here won't invalidate deps cache)
3841
# see .dockerignore for what is getting copied
3942
COPY broker/ ./

broker/Dockerfile.dockerignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,9 @@ broker/**/*_test.go
2626

2727
# Include pull slip templates
2828
!broker/pullslip/service/pull_slip_template.html
29+
30+
# Directory sources are generated inside the build.
31+
directory/api/directory.gen.go
32+
directory/db/db.go
33+
directory/db/models.go
34+
directory/db/query.sql.go

directory/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
directory
22
coverage.out
33
.vscode
4+
/api/directory.gen.go
5+
/db/db.go
6+
/db/models.go
7+
/db/query.sql.go

directory/Dockerfile

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@ COPY directory/go.mod directory/go.sum ./directory/
1010
# Set destination for COPY
1111
WORKDIR /app/directory
1212

13-
# sources are generated before docker build
14-
# make sure make generate is run
15-
1613
# see .dockerignore for what is getting copied
1714
COPY directory/ ./
1815

1916
# download go deps, caches GOMODPATH
2017
RUN --mount=type=cache,sharing=shared,target=/go/pkg/mod \
2118
GOWORK=off go mod download
2219

20+
# Generate API and database code from the tracked specifications.
21+
RUN --mount=type=cache,sharing=shared,target=/go/pkg/mod \
22+
GOWORK=off go generate .
23+
2324
# Build, caches GOCACHE
2425
RUN --mount=type=cache,sharing=shared,target=/root/.cache/go-build \
2526
CGO_ENABLED=0 \

directory/Dockerfile.dockerignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Generated sources are created inside the build.
2+
directory/api/directory.gen.go
3+
directory/db/db.go
4+
directory/db/models.go
5+
directory/db/query.sql.go

directory/Makefile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ OAPI_CODEGEN ?= $(GO) tool oapi-codegen
1010

1111
.PHONY: all docker generate generate-sqlc generate-api check checkinclgen run fmt fmt-check lint vulncheck clean deps-update tools-update
1212

13-
all: generate $(BINARY)
13+
all: $(BINARY)
1414

1515
docker:
1616
cd .. && $(DOCKER) build -f ./directory/Dockerfile .
@@ -23,18 +23,18 @@ generate-sqlc:
2323
generate-api:
2424
$(OAPI_CODEGEN) --config=oapi-codegen.yaml api.yaml
2525

26-
$(BINARY): $(GOFILES)
26+
$(BINARY): generate $(GOFILES)
2727
$(GO) build -v -o $(BINARY) ./$(MAIN_PACKAGE)
2828

29-
checkinclgen:
29+
checkinclgen: generate
3030
$(GO) test -v -cover -coverpkg=./... -coverprofile=$(COVERAGE) ./...
3131

32-
check:
32+
check: generate
3333
$(GO) test -v -coverpkg=./... -coverprofile=$(COVERAGE).tmp ./...
3434
grep -v "\.gen\.go" $(COVERAGE).tmp | grep -v "/db/" | grep -v "/test/" > $(COVERAGE)
3535
$(GO) tool cover -func $(COVERAGE)
3636

37-
run: $(BINARY)
37+
run: generate
3838
$(GO) run -buildvcs=true ./$(MAIN_PACKAGE)
3939

4040
fmt:
@@ -59,4 +59,6 @@ tools-update:
5959
$(GO) mod tidy
6060

6161
clean:
62-
rm -f $(BINARY) $(COVERAGE) $(COVERAGE).tmp
62+
rm -f $(BINARY) $(COVERAGE) $(COVERAGE).tmp \
63+
api/directory.gen.go \
64+
db/db.go db/models.go db/query.sql.go

directory/README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,23 +7,25 @@ PGPASSWORD=<somepass> psql -p 54322 -U postgres -h <local host/ip> -c 'create da
77
PGPASSWORD=<somepass> psql -p 54322 -U postgres -h <local host/ip> -d directory -a -f schema.sql
88
```
99

10-
Installing sqlc and oapi-codegen (probably good to contrive a way to add these as deps although the [tools.go](https://www.jvt.me/posts/2024/09/30/go-tools-module/) approach is a bit unwieldy it does seem like they have a proposal open with the core team to smooth this out a bit):
11-
```
12-
go install github.com/sqlc-dev/sqlc/cmd/sqlc@latest
13-
go install github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen@latest
14-
```
10+
The SQLC and OpenAPI generator versions are pinned as Go tools in `go.mod`.
11+
Generate the database and API sources with:
1512

16-
Generating structs/interfaces for db and api:
1713
```
18-
sqlc generate
19-
oapi-codegen --config=oapi-codegen.yaml api.yaml
14+
make generate
2015
```
2116

22-
Compiling:
17+
Generated Go sources are build artifacts and are not stored in the repository.
18+
The standard build, test, lint, and run targets generate them automatically:
19+
2320
```
24-
go build
21+
make all
22+
make check
23+
make lint
24+
make run
2525
```
2626

27+
Run `make generate` before invoking `go build` or `go test` directly.
28+
2729
# Some examples of repos using sqlc / some sort of api gen
2830

2931
## Contrived
@@ -37,4 +39,4 @@ go build
3739
- https://github.com/helpwave/services/tree/main/services/tasks-svc
3840

3941
# Environment variables
40-
- SYMBOL_AUTHORITY: The authority that is paired with the incoming institution/tenant to form a full symbol
42+
- SYMBOL_AUTHORITY: The authority that is paired with the incoming institution/tenant to form a full symbol

0 commit comments

Comments
 (0)