Skip to content

Commit

Permalink
add Dockerfiles and docker-compose to run full system in docker
Browse files Browse the repository at this point in the history
  • Loading branch information
MowlCoder committed Nov 4, 2023
1 parent 503a3c9 commit 3cdad10
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cmd/accrual/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM golang:1.20-alpine as builder

WORKDIR /app
COPY . /app

RUN go clean --modcache
RUN go mod download
RUN CGO_ENABLED=0 GOOS=linux go build -o accrual ./cmd/accrual/main.go

FROM golang:alpine

COPY --from=builder /app/accrual .

EXPOSE 8081

CMD ["./accrual"]
16 changes: 16 additions & 0 deletions cmd/gophermart/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM golang:1.20-alpine as builder

WORKDIR /app
COPY . /app

RUN go clean --modcache
RUN go mod download
RUN CGO_ENABLED=0 GOOS=linux go build -o gophermart ./cmd/gophermart/main.go

FROM golang:alpine

COPY --from=builder /app/gophermart .

EXPOSE 8080

CMD ["./gophermart"]
38 changes: 38 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: '3.9'
services:
db:
image: postgres:latest
container_name: "database"
environment:
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=postgres
ports:
- "35432:5432"

accrual:
build:
dockerfile: cmd/accrual/Dockerfile
context: .
container_name: "accrual"
environment:
DATABASE_URI: postgres://postgres:postgres@db:5432/postgres
RUN_ADDRESS: :8081
ports:
- "8081:8081"
depends_on:
- db

gophermart:
build:
dockerfile: cmd/gophermart/Dockerfile
context: .
container_name: "gophermart"
environment:
DATABASE_URI: postgres://postgres:postgres@db:5432/postgres
RUN_ADDRESS: :8080
ACCRUAL_SYSTEM_ADDRESS: http://accrual:8081
ports:
- "8080:8080"
depends_on:
- db

0 comments on commit 3cdad10

Please sign in to comment.