-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDockerfile
89 lines (63 loc) · 2.29 KB
/
Dockerfile
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# Build stage: Compile the Go application
FROM golang:1.23-bullseye AS builder
# Set the working directory inside the container
WORKDIR /app
# Copy Go modules to the container and download dependencies
COPY go.mod go.sum ./
RUN go mod download
# Install Swag CLI
RUN go install github.com/swaggo/swag/cmd/swag@latest
# Copy the rest of the application code into the container
COPY . ./
RUN swag init
# Build the Go binary
RUN go build -o main .
# Production stage: Create a lightweight runtime image for production
FROM debian:bullseye-slim AS production
# Install and update CA certificates
RUN apt-get update && \
apt-get install -y ca-certificates && \
update-ca-certificates && \
rm -rf /var/lib/apt/lists/*
# Install necessary libraries (e.g., libc6) to run the Go binary
RUN apt-get update && \
apt-get install -y libc6
# Set the working directory for the application in the container
WORKDIR /app
# Copy the compiled Go binary from the builder stage
COPY --from=builder /app/main .
# Copy the Swagger documentation from the builder stage
COPY --from=builder /app/docs /app/docs
# Set the environment variable for production
ENV ENVIRONMENT=production
# Expose port 8080 for the application
EXPOSE 8080
# Make the Go binary executable
RUN chmod +x /app/main
# Set the entry point to the Go binary for production
ENTRYPOINT ["/app/main"]
# Development stage: Create a lightweight runtime image for development
FROM debian:bullseye-slim AS development
# Install and update CA certificates
RUN apt-get update && \
apt-get install -y ca-certificates && \
update-ca-certificates
# Install necessary libraries (e.g., libc6) to run the Go binary
RUN apt-get update && \
apt-get install -y libc6
# Set the working directory for the application in the container
WORKDIR /app
# Copy the environment configuration file for development
COPY .env .env
# Copy the compiled Go binary from the builder stage
COPY --from=builder /app/main .
# Copy the Swagger documentation from the builder stage
COPY --from=builder /app/docs /app/docs
# Set the environment variable for development
ENV ENVIRONMENT=development
# Expose port 8080 for the application
EXPOSE 8080
# Make the Go binary executable
RUN chmod +x /app/main
# Set the entry point to the Go binary for development
ENTRYPOINT ["/app/main"]