Skip to content

Commit

Permalink
Merge pull request #8 from TheFeij/ft/docker-compose
Browse files Browse the repository at this point in the history
Ft/docker compose added docker compose file
  • Loading branch information
TheFeij authored Apr 9, 2024
2 parents 6f0bd04 + 19a1d03 commit c26cbf1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
11 changes: 8 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
CMD ["/app/main"]
ENTRYPOINT ["/app/start.sh"]
26 changes: 26 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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
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 "$DATABASE_SOURCE" -verbose up

echo "start the app"
exec "$@"

0 comments on commit c26cbf1

Please sign in to comment.