use docker dev env

This commit is contained in:
Ruidy 2024-08-09 15:33:33 +02:00
parent 622adafef6
commit 6eb7e272a4
No known key found for this signature in database
GPG key ID: E00F51288CB857CC
3 changed files with 54 additions and 4 deletions

32
.air.toml Normal file
View file

@ -0,0 +1,32 @@
root = "."
tmp_dir = "tmp"
[build]
bin = "./tmp/main"
cmd = "templ generate && go build -o ./tmp/main ."
delay = 1000
exclude_dir = ["assets", "tmp", "vendor"]
exclude_file = []
exclude_regex = [".*_templ.go"]
exclude_unchanged = false
follow_symlink = false
full_bin = ""
include_dir = []
include_ext = ["go", "tpl", "tmpl", "templ", "html"]
kill_delay = "0s"
log = "build-errors.log"
send_interrupt = false
stop_on_error = true
[color]
app = ""
build = "yellow"
main = "magenta"
runner = "green"
watcher = "cyan"
[log]
time = false
[misc]
clean_on_exit = false

19
Dockerfile.dev Normal file
View file

@ -0,0 +1,19 @@
FROM golang:1.22-alpine
RUN apk update && apk add --no-cache \
build-base
WORKDIR /app
RUN go install github.com/air-verse/air@latest
RUN go install github.com/a-h/templ/cmd/templ@latest
COPY go.mod go.sum ./
RUN go mod download
COPY . .
EXPOSE 8000
CMD [ "air", "-c", ".air.toml" ]

View file

@ -7,16 +7,15 @@ build: format lint
@docker build -t ${NAME}:latest .
run: build
@docker run -p ${PORT}:${PORT} -e DATABASE_URL="host=docker.for.mac.host.internal user=${DB_USER} database=${DB_NAME}" -e PORT=${PORT} ${NAME}
dev: templ
@air cmd/main.go
dev:
@docker build -t ${NAME}:latest -f Dockerfile.dev .
@docker run -p ${PORT}:${PORT} --rm -v `pwd`:/app -v /app/tmp --name ${NAME} -e DATABASE_URL="host=docker.for.mac.host.internal user=${DB_USER} database=${DB_NAME}" -e PORT=${PORT} ${NAME}
test:
@go test ./...
up-deps:
@go get -u ./...
cron:
@go run cmd/cron/main.go
templ:
@templ generate --watch --proxy=http://localhost:${PORT} &
format:
@templ generate internal/views
@templ fmt .