feat: add air for watch project changes

This commit is contained in:
amir-ys 2026-04-28 00:38:31 +03:30
parent 23fedc02c3
commit 0269822fc0
4 changed files with 48 additions and 7 deletions

34
.air/.air.productapp.toml Normal file
View File

@ -0,0 +1,34 @@
root = "."
tmp_dir = "cmd/productapp/temp"
[build]
bin = "/entrypoint.sh"
args_bin = []
cmd = "go build -mod=mod -buildvcs=false -o ./cmd/productapp/temp/main ./cmd/productapp/"
delay = 1000
exclude_dir = ["vendor", "cmd/productapp/temp"]
exclude_file = []
exclude_regex = []
exclude_unchanged = false
follow_symlink = false
include_dir = []
include_ext = ["go"]
kill_delay = "0s"
log = "build-errors.log"
send_interrupt = false
stop_on_error = true
poll = true
poll_interval = 1000
[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"
[log]
time = false
[misc]
clean_on_exit = false

View File

@ -81,7 +81,7 @@ confirm:
# ==================================================================================== # ====================================================================================
# Productapp Service Commands # Productapp Service Commands
# ==================================================================================== # ====================================================================================
.PHONY: productapp-up productapp-up-logs .PHONY: productapp-up productapp-up-logs productapp-rebuild productapp-watch
PRODUCTAPP_ENV = deploy/productapp/development/.env PRODUCTAPP_ENV = deploy/productapp/development/.env
PRODUCTAPP_COMPOSE = deploy/productapp/development/docker-compose.yml PRODUCTAPP_COMPOSE = deploy/productapp/development/docker-compose.yml
@ -91,6 +91,11 @@ productapp-up:
docker compose --env-file $(PRODUCTAPP_ENV) -f $(PRODUCTAPP_COMPOSE) up --build -d docker compose --env-file $(PRODUCTAPP_ENV) -f $(PRODUCTAPP_COMPOSE) up --build -d
@echo "productapp stack is up." @echo "productapp stack is up."
productapp-down:
@echo "Building and starting productapp full stack..."
docker compose --env-file $(PRODUCTAPP_ENV) -f $(PRODUCTAPP_COMPOSE) down
@echo "productapp stack is up."
productapp-up-logs: productapp-up-logs:
@echo "Building and starting productapp full stack..." @echo "Building and starting productapp full stack..."
docker compose --env-file $(PRODUCTAPP_ENV) -f $(PRODUCTAPP_COMPOSE) up --build docker compose --env-file $(PRODUCTAPP_ENV) -f $(PRODUCTAPP_COMPOSE) up --build

View File

@ -5,14 +5,15 @@ FROM ${GO_IMAGE_NAME}:${GO_IMAGE_VERSION}
ENV GOPROXY=https://package-mirror.liara.ir/repository/go/ ENV GOPROXY=https://package-mirror.liara.ir/repository/go/
ENV GOSUMDB=off ENV GOSUMDB=off
WORKDIR /home/app WORKDIR /home/app
COPY go.mod go.sum ./ COPY go.mod go.sum ./
RUN go mod download RUN go mod download
COPY . . RUN go install github.com/air-verse/air@latest
RUN go build -mod=mod -o /bin/productapp cmd/productapp/main.go
CMD ["/bin/productapp", "serve"] RUN printf '#!/bin/sh\n./cmd/productapp/temp/main migrate --up\nexec ./cmd/productapp/temp/main serve\n' > /entrypoint.sh && chmod +x /entrypoint.sh
COPY . .
CMD ["air", "-c", "/home/app/.air/.air.productapp.toml"]

View File

@ -9,7 +9,8 @@ services:
container_name: productapp-app container_name: productapp-app
ports: ports:
- "8080:8080" - "8080:8080"
command: /bin/sh -c "/bin/productapp migrate --up && /bin/productapp serve" volumes:
- ../../..:/home/app
environment: environment:
DB_HOST: productapp-mysql DB_HOST: productapp-mysql
DB_USERNAME: root DB_USERNAME: root