Skip to content

Commit d1c9e99

Browse files
refactor Dockerfile for multi-stage build; update compose.yaml for production settings and network configuration
1 parent f3ce04c commit d1c9e99

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

Dockerfile

+11-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
FROM golang:1.23.4-alpine3.21
2-
RUN mkdir /app
3-
ADD . /app
1+
# Build stage
2+
FROM golang:1.23.4-alpine3.21 AS builder
43
WORKDIR /app
4+
COPY . .
5+
RUN go mod download
56
RUN go build -o main .
6-
CMD ["/app/main"]
7+
8+
# Production stage
9+
FROM alpine:latest AS production
10+
WORKDIR /app
11+
COPY --from=builder /app/main .
12+
EXPOSE 8080
13+
CMD ["./main"]

compose.yaml

+14-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
services:
2-
app:
3-
image: go-crud-api
2+
api:
3+
image: go-crud-api:latest
4+
build:
5+
context: .
6+
dockerfile: Dockerfile
7+
target: production
48
ports:
59
- "8000:8000"
10+
environment:
11+
- GO_ENV=production
12+
networks:
13+
- go-network
14+
15+
networks:
16+
go-network:
17+
driver: bridge

main

-7.58 MB
Binary file not shown.

0 commit comments

Comments
 (0)