-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
53 lines (36 loc) · 1.32 KB
/
Dockerfile
File metadata and controls
53 lines (36 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Build stage
FROM golang:1.26.2-alpine@sha256:c2a1f7b2095d046ae14b286b18413a05bb82c9bca9b25fe7ff5efef0f0826166 AS builder
RUN go version
WORKDIR /app
# Install required packages
RUN apk add --no-cache git ca-certificates
# Install swag CLI for swagger docs generation (pinned to v1.16.4 - commit 0b9e347c196710ea155a147782bf51707a600c2c)
RUN git clone https://github.com/swaggo/swag.git /tmp/swag && \
cd /tmp/swag && \
git checkout 0b9e347c196710ea155a147782bf51707a600c2c && \
go install ./cmd/swag && \
rm -rf /tmp/swag
# Copy go mod files
COPY go.mod go.sum ./
# Download dependencies
RUN go mod download
# Copy source code
COPY . .
# Generate swagger docs and build the application
RUN swag init -g cmd/server/main.go -o docs && go mod tidy && CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main ./cmd/server
# Final stage
FROM alpine:3.20@sha256:a4f4213abb84c497377b8544c81b3564f313746700372ec4fe84653e4fb03805
WORKDIR /app
# Install ca-certificates for HTTPS requests
RUN apk --no-cache add ca-certificates
# Copy binary from builder
COPY --from=builder /app/main .
# Copy swagger docs
COPY --from=builder /app/docs ./docs
# Create uploads directory
RUN mkdir -p /app/uploads
# Environment variables are provided by .env via Docker Compose
# Expose port
EXPOSE 8083
# Run the application
CMD ["./main"]