Skip to content

Commit c0fbd97

Browse files
committed
chore: added air support for hot reloading
Updated docker configs and added an air config for faster development. Air is a watches all the go files and rebuilds whenever there is any change in the code to reflect in the API immediately
1 parent 4f40f8e commit c0fbd97

File tree

5 files changed

+80
-27
lines changed

5 files changed

+80
-27
lines changed

.air.toml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Config file for [Air](https://github.com/cosmtrek/air) in TOML format
2+
3+
# Working directory
4+
# . or absolute path, please note that the directories following must be under root
5+
root = "."
6+
tmp_dir = "/tmp"
7+
8+
[build]
9+
# Just plain old shell command. You could use `make` as well.
10+
cmd = "go build -o ./tmp/app/permify ./cmd/permify"
11+
# Binary file yields from `cmd`.
12+
bin = "/tmp/app"
13+
14+
# Customize binary.
15+
# This is how you start to run your application. Since my application will works like CLI, so to run it, like to make a CLI call.
16+
full_bin = "./tmp/app/permify serve --database-engine postgres --database-uri postgres://postgres:secret@database:5432/permify --database-max-open-connections 20"
17+
# This log file places in your tmp_dir.
18+
log = "air_errors.log"
19+
# Watch these filename extensions.
20+
include_ext = ["go", "yaml",".env"]
21+
# Ignore these filename extensions or directories.
22+
exclude_dir = ["tmp", "docs"]
23+
# It's not necessary to trigger build each time file changes if it's too frequent.
24+
delay = 500 # ms
25+
26+
[log]
27+
# Show log time
28+
time = true
29+
[color]
30+
31+
[misc]
32+
# Delete tmp directory on exit
33+
clean_on_exit = true

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,5 @@
2121
# Dependency directories (remove the comment below to include it)
2222
vendor/dist/
2323
/dist
24-
/config
24+
/config
25+
/tmp

Dockerfile.local

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
FROM golang:1.21-alpine
2+
3+
RUN apk --no-cache add curl
4+
# Install the air binary so we get live code-reloading when we save files
5+
RUN curl -sSfL https://raw.githubusercontent.com/cosmtrek/air/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
6+
7+
# Run the air command in the directory where our code will live
8+
WORKDIR /app
9+
10+
ENTRYPOINT [ "air" ]

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ help: ## Display this help screen
88
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n"} /^[a-zA-Z_-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 } /^##@/ { printf "\n\033[1m%s\033[0m\n", substr($$0, 5) } ' $(MAKEFILE_LIST)
99

1010
compose-up: ### Run docker-compose
11-
docker-compose up --build -d postgres && docker-compose logs -f
11+
docker-compose up --build
1212
.PHONY: compose-up
1313

1414
compose-up-integration-test: ### Run docker-compose with integration test

docker-compose.yaml

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,40 @@
11
version: "3.9"
22
services:
3-
permify:
4-
image: "ghcr.io/permify/permify:latest"
5-
command: "serve --database-engine postgres --database-uri postgres://postgres:secret@database:5432/permify --database-max-open-connections 20"
6-
restart: "always"
7-
ports:
8-
- "3476:3476"
9-
- "3478:3478"
10-
depends_on:
11-
- "database"
3+
permify:
4+
build:
5+
context: .
6+
dockerfile: Dockerfile.local
7+
restart: "always"
8+
ports:
9+
- "3476:3476"
10+
- "3478:3478"
11+
volumes:
12+
- .:/app
13+
depends_on:
14+
- "database"
15+
healthcheck:
16+
test: ["CMD", "curl", "-f", "http://localhost:3476/healthz"]
17+
interval: 10s
18+
retries: 10
19+
start_period: 60s
1220

13-
database:
14-
image: "postgres"
15-
ports:
16-
- "5432:5432"
17-
environment:
18-
- "POSTGRES_PASSWORD=secret"
19-
- "POSTGRES_DB=permify"
21+
database:
22+
image: "postgres"
23+
ports:
24+
- "5432:5432"
25+
environment:
26+
- "POSTGRES_PASSWORD=secret"
27+
- "POSTGRES_DB=permify"
2028

21-
integration:
22-
build:
23-
context: .
24-
dockerfile: integration-test/Dockerfile
25-
container_name: integration
26-
image: integration
27-
depends_on:
28-
- permify
29+
integration:
30+
build:
31+
context: .
32+
dockerfile: integration-test/Dockerfile
33+
container_name: integration
34+
image: integration
35+
depends_on:
36+
permify:
37+
condition: service_healthy
2938

3039
volumes:
31-
pg-data:
40+
pg-data:

0 commit comments

Comments
 (0)