From 6fef81eb522ec69392e3bb889b42dba8a76e1bc7 Mon Sep 17 00:00:00 2001 From: Luca Steeb Date: Tue, 19 Dec 2023 01:36:48 +0700 Subject: [PATCH] chore(contributing): improve onboarding (#3) - shell scripts logging and fail on error - use npx --yes instead of manual global install - run go libs directly instead of installing and running binaries - add missing brew dependencies --- CONTRIBUTING.md | 5 +---- Caddyfile | 8 ++++---- Taskfile.yaml | 2 +- go.mod | 3 +-- go.sum | 2 -- hack/dev/generate-temporal-certs.sh | 4 +++- hack/dev/manage-hosts.sh | 4 +++- hack/dev/proto.sh | 7 ++++++- hack/dev/run-go-with-env.sh | 2 ++ hack/dev/run-npx-with-env.sh | 2 ++ hack/dev/start-api.sh | 4 +++- hack/dev/start-engine.sh | 4 +++- hack/dev/start-frontend.sh | 2 ++ hack/dev/start-temporal-server.sh | 4 +++- hack/oas/generate-client.sh | 2 ++ hack/oas/generate-server.sh | 6 ++++-- internal/services/admin/contracts/workflows.pb.go | 4 ++-- internal/services/admin/contracts/workflows_grpc.pb.go | 2 +- internal/services/dispatcher/contracts/dispatcher.pb.go | 4 ++-- .../services/dispatcher/contracts/dispatcher_grpc.pb.go | 2 +- internal/services/ingestor/contracts/events.pb.go | 4 ++-- internal/services/ingestor/contracts/events_grpc.pb.go | 2 +- 22 files changed, 49 insertions(+), 30 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 531f2be3e..b32110b18 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -10,10 +10,7 @@ - The following additional devtools: - `protoc`: `brew install protobuf` - `sqlc`: `brew install sqlc` - - `deepmap/oapi-codegen`: `go install github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen@latest` - - `swagger-cli`: `npm list -g @apidevtools/swagger-cli || npm install -g @apidevtools/swagger-cli` - - `nodemon`: `npm list -g nodemon || npm install -g nodemon` - - `turbo`: `npm list -g turbo || npm i -g turbo` + - `caddy` and `nss`: `brew install caddy nss` ### Setup diff --git a/Caddyfile b/Caddyfile index 6802b33fc..8ca105518 100644 --- a/Caddyfile +++ b/Caddyfile @@ -1,11 +1,11 @@ app.dev.hatchet-tools.com { tls internal - handle /api/* { - reverse_proxy localhost:8080 - } + handle /api/* { + reverse_proxy localhost:8080 + } handle /* { reverse_proxy localhost:5173 } -} \ No newline at end of file +} diff --git a/Taskfile.yaml b/Taskfile.yaml index 7ba8c13a8..2827b9397 100644 --- a/Taskfile.yaml +++ b/Taskfile.yaml @@ -58,7 +58,7 @@ tasks: - sh ./hack/dev/proto.sh generate-sqlc: cmds: - - npx prisma migrate diff --from-empty --to-schema-datasource prisma/schema.prisma --script > internal/repository/prisma/dbsqlc/schema.sql + - npx --yes prisma migrate diff --from-empty --to-schema-datasource prisma/schema.prisma --script > internal/repository/prisma/dbsqlc/schema.sql - sqlc generate --file internal/repository/prisma/dbsqlc/sqlc.yaml kill-query-engines: cmds: diff --git a/go.mod b/go.mod index a928b4c9f..e66bc8003 100644 --- a/go.mod +++ b/go.mod @@ -87,6 +87,5 @@ require ( google.golang.org/grpc v1.58.2 google.golang.org/protobuf v1.31.0 gopkg.in/ini.v1 v1.67.0 // indirect - gopkg.in/yaml.v2 v2.4.0 - gopkg.in/yaml.v3 v3.0.1 // indirect + gopkg.in/yaml.v3 v3.0.1 ) diff --git a/go.sum b/go.sum index e48071ee2..248d4de70 100644 --- a/go.sum +++ b/go.sum @@ -631,8 +631,6 @@ gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/ini.v1 v1.67.0 h1:Dgnx+6+nfE+IfzjUEISNeydPJh9AXNNsWbGP9KzCsOA= gopkg.in/ini.v1 v1.67.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= -gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/hack/dev/generate-temporal-certs.sh b/hack/dev/generate-temporal-certs.sh index fda904b79..02b4b3e3b 100644 --- a/hack/dev/generate-temporal-certs.sh +++ b/hack/dev/generate-temporal-certs.sh @@ -1,6 +1,8 @@ #!/bin/bash # This scripts generates test keys and certificates for the sample. +set -eux + CERTS_DIR=./certs # Read CERTS_DIR from args if exists @@ -14,7 +16,7 @@ mkdir $CERTS_DIR openssl genrsa -out $CERTS_DIR/ca.key 4096 openssl req -new -x509 -key $CERTS_DIR/ca.key -sha256 -subj "/C=US/ST=WA/O=Test CA, Inc." -days 365 -out $CERTS_DIR/ca.cert -# Generate a private key and a certificate for cluster +# Generate a private key and a certificate for cluster openssl genrsa -out $CERTS_DIR/cluster.key 4096 openssl req -new -key $CERTS_DIR/cluster.key -out $CERTS_DIR/cluster.csr -config $CERTS_DIR/cluster-cert.conf openssl x509 -req -in $CERTS_DIR/cluster.csr -CA $CERTS_DIR/ca.cert -CAkey $CERTS_DIR/ca.key -CAcreateserial -out $CERTS_DIR/cluster.pem -days 365 -sha256 -extfile $CERTS_DIR/cluster-cert.conf -extensions req_ext diff --git a/hack/dev/manage-hosts.sh b/hack/dev/manage-hosts.sh index e484a1189..2719bb0d2 100644 --- a/hack/dev/manage-hosts.sh +++ b/hack/dev/manage-hosts.sh @@ -1,5 +1,7 @@ #!/bin/sh +set -eux + # run: # ./manage-etc-hosts.sh add 10.20.1.2 test.com # ./manage-etc-hosts.sh remove 10.20.1.2 test.com @@ -44,4 +46,4 @@ function add() { fi } -$@ \ No newline at end of file +$@ diff --git a/hack/dev/proto.sh b/hack/dev/proto.sh index 83f5b19f0..d5629c219 100644 --- a/hack/dev/proto.sh +++ b/hack/dev/proto.sh @@ -2,6 +2,11 @@ # # Builds auto-generated protobuf files +go install google.golang.org/protobuf/cmd/protoc-gen-go@v1.28 +go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.2 + +export PATH="$PATH:$(go env GOPATH)/bin" + protoc --proto_path=api-contracts/dispatcher --go_out=./internal/services/dispatcher/contracts --go_opt=paths=source_relative \ --go-grpc_out=./internal/services/dispatcher/contracts --go-grpc_opt=paths=source_relative \ dispatcher.proto @@ -12,4 +17,4 @@ protoc --proto_path=api-contracts/events --go_out=./internal/services/ingestor/c protoc --proto_path=api-contracts/workflows --go_out=./internal/services/admin/contracts --go_opt=paths=source_relative \ --go-grpc_out=./internal/services/admin/contracts --go-grpc_opt=paths=source_relative \ - workflows.proto \ No newline at end of file + workflows.proto diff --git a/hack/dev/run-go-with-env.sh b/hack/dev/run-go-with-env.sh index d95b1df30..0fb93b372 100644 --- a/hack/dev/run-go-with-env.sh +++ b/hack/dev/run-go-with-env.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -eux + set -a . .env set +a diff --git a/hack/dev/run-npx-with-env.sh b/hack/dev/run-npx-with-env.sh index 92d7836c1..e3020f737 100644 --- a/hack/dev/run-npx-with-env.sh +++ b/hack/dev/run-npx-with-env.sh @@ -1,5 +1,7 @@ #!/bin/bash +set -eux + set -a . .env set +a diff --git a/hack/dev/start-api.sh b/hack/dev/start-api.sh index 97038e74c..10c9e0adf 100644 --- a/hack/dev/start-api.sh +++ b/hack/dev/start-api.sh @@ -1,9 +1,11 @@ #!/bin/bash +set -eux + caddy start set -a . .env set +a -nodemon --signal SIGINT --config nodemon.api.json --exec go run ./cmd/hatchet-api +npx --yes nodemon --signal SIGINT --config nodemon.api.json --exec go run ./cmd/hatchet-api diff --git a/hack/dev/start-engine.sh b/hack/dev/start-engine.sh index 087f6af5b..a125fd9fe 100644 --- a/hack/dev/start-engine.sh +++ b/hack/dev/start-engine.sh @@ -1,7 +1,9 @@ #!/bin/bash +set -eux + set -a . .env set +a -nodemon --signal SIGINT --config nodemon.engine.json --exec go run ./cmd/hatchet-engine +npx --yes nodemon --signal SIGINT --config nodemon.engine.json --exec go run ./cmd/hatchet-engine diff --git a/hack/dev/start-frontend.sh b/hack/dev/start-frontend.sh index af102d327..735b42972 100644 --- a/hack/dev/start-frontend.sh +++ b/hack/dev/start-frontend.sh @@ -1,3 +1,5 @@ #!/bin/bash +set -eux + cd ./frontend/app && npm run dev diff --git a/hack/dev/start-temporal-server.sh b/hack/dev/start-temporal-server.sh index ddd4c790c..0b4400020 100644 --- a/hack/dev/start-temporal-server.sh +++ b/hack/dev/start-temporal-server.sh @@ -1,7 +1,9 @@ #!/bin/bash +set -eux + set -a . .env set +a -go run ./cmd/temporal-server \ No newline at end of file +go run ./cmd/temporal-server diff --git a/hack/oas/generate-client.sh b/hack/oas/generate-client.sh index e9a9ed656..483e15afb 100644 --- a/hack/oas/generate-client.sh +++ b/hack/oas/generate-client.sh @@ -1,3 +1,5 @@ #!/bin/bash +set -eux + cd frontend && (npx swagger-typescript-api -p ../bin/oas/openapi.yaml -o ./app/src/lib/api/generated -n hatchet.ts --modular --axios || cd ..) diff --git a/hack/oas/generate-server.sh b/hack/oas/generate-server.sh index a013344c7..18eccb35c 100644 --- a/hack/oas/generate-server.sh +++ b/hack/oas/generate-server.sh @@ -1,4 +1,6 @@ #!/bin/bash -swagger-cli bundle ./api-contracts/openapi/openapi.yaml --outfile bin/oas/openapi.yaml --type yaml -oapi-codegen -config ./api/v1/server/oas/gen/codegen.yaml ./bin/oas/openapi.yaml +set -eux + +npx --yes swagger-cli bundle ./api-contracts/openapi/openapi.yaml --outfile bin/oas/openapi.yaml --type yaml +go run github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen@latest -config ./api/v1/server/oas/gen/codegen.yaml ./bin/oas/openapi.yaml diff --git a/internal/services/admin/contracts/workflows.pb.go b/internal/services/admin/contracts/workflows.pb.go index 5e38cf2cd..a78d53608 100644 --- a/internal/services/admin/contracts/workflows.pb.go +++ b/internal/services/admin/contracts/workflows.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.27.1 -// protoc v3.19.3 +// protoc-gen-go v1.28.1 +// protoc v4.25.1 // source: workflows.proto package contracts diff --git a/internal/services/admin/contracts/workflows_grpc.pb.go b/internal/services/admin/contracts/workflows_grpc.pb.go index feb84b2c6..88c9bb83a 100644 --- a/internal/services/admin/contracts/workflows_grpc.pb.go +++ b/internal/services/admin/contracts/workflows_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.2.0 -// - protoc v3.19.3 +// - protoc v4.25.1 // source: workflows.proto package contracts diff --git a/internal/services/dispatcher/contracts/dispatcher.pb.go b/internal/services/dispatcher/contracts/dispatcher.pb.go index 1167475bc..5b77dd59c 100644 --- a/internal/services/dispatcher/contracts/dispatcher.pb.go +++ b/internal/services/dispatcher/contracts/dispatcher.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.27.1 -// protoc v3.19.3 +// protoc-gen-go v1.28.1 +// protoc v4.25.1 // source: dispatcher.proto package contracts diff --git a/internal/services/dispatcher/contracts/dispatcher_grpc.pb.go b/internal/services/dispatcher/contracts/dispatcher_grpc.pb.go index 78c3d278f..e28aa18a0 100644 --- a/internal/services/dispatcher/contracts/dispatcher_grpc.pb.go +++ b/internal/services/dispatcher/contracts/dispatcher_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.2.0 -// - protoc v3.19.3 +// - protoc v4.25.1 // source: dispatcher.proto package contracts diff --git a/internal/services/ingestor/contracts/events.pb.go b/internal/services/ingestor/contracts/events.pb.go index fe1f557cf..cab9f1c63 100644 --- a/internal/services/ingestor/contracts/events.pb.go +++ b/internal/services/ingestor/contracts/events.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.27.1 -// protoc v3.19.3 +// protoc-gen-go v1.28.1 +// protoc v4.25.1 // source: events.proto package contracts diff --git a/internal/services/ingestor/contracts/events_grpc.pb.go b/internal/services/ingestor/contracts/events_grpc.pb.go index d34ad88e5..db36673c5 100644 --- a/internal/services/ingestor/contracts/events_grpc.pb.go +++ b/internal/services/ingestor/contracts/events_grpc.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: // - protoc-gen-go-grpc v1.2.0 -// - protoc v3.19.3 +// - protoc v4.25.1 // source: events.proto package contracts