Skip to content

Commit f90d8fc

Browse files
authored
Added air live-reload on dev (#453)
1 parent f41b679 commit f90d8fc

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ terraform.tfstate
99
terraform.tfstate.backup
1010
**/.tfplan.*
1111
tests/periodic-test/build-template/e2b.toml
12+
.air

packages/api/.air.toml

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
root = "."
2+
tmp_dir = ".air"
3+
4+
[build]
5+
cmd = "CGO_ENABLED=1 go build -race -gcflags=all=\"-N -l\" -o bin/api ."
6+
bin = "bin/api"
7+
full_bin = "ENV=$(cat ../../.last_used_env || echo \"not-set\") && . ../../.env.${ENV} && POSTGRES_CONNECTION_STRING=${POSTGRES_CONNECTION_STRING} SUPABASE_JWT_SECRETS=${SUPABASE_JWT_SECRETS} GOTRACEBACK=crash GODEBUG=madvdontneed=1 TEMPLATE_BUCKET_NAME=${TEMPLATE_BUCKET_NAME} ENVIRONMENT=${ENVIRONMENT} ORCHESTRATOR_PORT=5008 bin/api --port 3000"
8+
include_ext = ["go", "yml", "yaml"]
9+
exclude_dir = ["assets", ".air", "vendor", "bin"]
10+
exclude_regex = ["_test\\.go"]
11+
exclude_unchanged = true
12+
delay = 500
13+
send_interrupt = true # not sure this is actually needed
14+
15+
[log]
16+
time = true
17+
18+
[screen]
19+
clear_on_rebuild = false

packages/api/Makefile

+12
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,18 @@ run:
3535
ORCHESTRATOR_PORT=5008 \
3636
./bin/api --port 3000
3737

38+
# Run the API using air
39+
.PHONY: dev-init
40+
dev-init:
41+
go install github.com/air-verse/air@latest
42+
43+
.PHONY: dev
44+
dev:
45+
@if [ ! -f "${GOPATH}/bin/air" ]; then \
46+
echo "air not found in ${GOPATH}/bin/air, please run 'make dev-init' first"; \
47+
exit 1; \
48+
fi
49+
${GOPATH}/bin/air
3850

3951
# You run the parametrized command like this:
4052
# make metric=heap interval=90 profiler

packages/api/main.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,11 @@ func run() int {
325325
// This is a bit of a hack, but this way we can properly propagate
326326
// the health status to the load balancer.
327327
apiStore.Healthy = false
328-
time.Sleep(15 * time.Second)
328+
329+
// Skip the delay in local environment for instant shutdown
330+
if !env.IsLocal() {
331+
time.Sleep(15 * time.Second)
332+
}
329333

330334
// if the parent context `ctx` is canceled the
331335
// shutdown will return early. This should only happen

0 commit comments

Comments
 (0)