Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ft/docker compose added docker compose file #8

Merged
merged 3 commits into from
Apr 9, 2024
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
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 "$@"
Loading