diff --git a/Dockerfile b/Dockerfile index 2bff7de..80a47da 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,14 +3,19 @@ FROM golang:1.22.2-alpine3.19 AS builder WORKDIR /app COPY . . RUN go build -o main main.go +RUN apk add curl +RUN curl -L https://github.com/golang-migrate/migrate/releases/download/v4.16.2/migrate.linux-amd64.tar.gz | tar xvz # run stage From alpine:3.19 WORKDIR /app COPY --from=builder /app/main . - -RUN mkdir config +COPY --from=builder /app/migrate . COPY config/config.json /app/config/ +COPY db/migration ./migration +COPY start.sh . +RUN chmod +x start.sh EXPOSE 8080 -CMD [ "/app/main" ] \ No newline at end of file +CMD ["/app/main"] +ENTRYPOINT ["/app/start.sh"] \ No newline at end of file diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..0d10b35 --- /dev/null +++ b/docker-compose.yaml @@ -0,0 +1,26 @@ +name: simple-bank + +services: + postgres: + image: postgres:16rc1-alpine3.18 + environment: + - POSTGRES_USER=root + - POSTGRES_PASSWORD=1234 + - POSTGRES_DB=simple_bank + healthcheck: + test: ["CMD-SHELL", "pg_isready -d simple_bank -U root"] + interval: 10s + timeout: 5s + retries: 5 + + api: + build: + context: . + dockerfile: Dockerfile + ports: + - "8080:8080" + environment: + - DATABASE_SOURCE=postgresql://root:1234@postgres:5432/simple_bank?sslmode=disable + depends_on: + postgres: + condition: service_healthy \ No newline at end of file diff --git a/start.sh b/start.sh new file mode 100644 index 0000000..dd83d50 --- /dev/null +++ b/start.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +set -e + +echo "run db migration" +/app/migrate -path /app/migration -database "$DATABASE_SOURCE" -verbose up + +echo "start the app" +exec "$@" \ No newline at end of file