Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Build stage
FROM golang:1.26.3-alpine3.23 AS builder
WORKDIR /app
COPY . .
RUN go build -o main main.go
RUN go install -tags 'postgres' github.com/golang-migrate/migrate/v4/cmd/migrate@latest

# Run stage
FROM alpine:3.23
WORKDIR /app
COPY --from=builder /app/main .
COPY --from=builder /go/bin/migrate .
COPY db/migration ./migration
COPY app.env .
COPY start.sh .
RUN chmod +x /app/start.sh
EXPOSE 8080
ENTRYPOINT ["/app/start.sh"]
CMD ["/app/main"]
26 changes: 26 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
services:
postgres:
image: postgres:16-alpine
ports:
- "25432:5432"
environment:
- POSTGRES_USER=root
- POSTGRES_PASSWORD=secret
- POSTGRES_DB=bank_db
healthcheck:
test: ["CMD-SHELL", "pg_isready -U root -d bank_db"]
interval: 5s
timeout: 5s
retries: 5
api:
build:
context: .
dockerfile: Dockerfile
ports:
- "8080:8080"
environment:
- DB_SOURCE=postgresql://root:secret@postgres:5432/bank_db?sslmode=disable
depends_on:
postgres:
condition: service_healthy

9 changes: 9 additions & 0 deletions start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

set -e

echo "Run db migration"
/app/migrate -path /app/migration -database "$DB_SOURCE" --verbose up

echo "Start the app"
exec "$@"
Loading