-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
49 lines (37 loc) · 1.41 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
# Use official Go builder image with Alpine Linux as the base
FROM golang:1.21rc3-alpine AS builder
# Set the working directory inside the container
WORKDIR /app
# Copy the source code into the container
COPY . .
# Set GOPROXY to use the specified Go proxy
ENV GOPROXY=https://proxy.golang.org,direct
# Disable GOSUMDB to skip the checksum verification for modules
ENV GOSUMDB=off
# Fetch dependencies using Go Modules
RUN go mod download
RUN go mod vendor
# Build the Go application with static linking
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main main.go
RUN apk add curl
RUN curl -L https://github.com/golang-migrate/migrate/releases/download/v4.14.1/migrate.linux-amd64.tar.gz | tar xvz
RUN chmod a+x start.sh
RUN chmod a+x wait-for.sh
# Use a minimal base image with Alpine Linux to reduce the image size
FROM alpine:3.13
# Set the working directory inside the container
WORKDIR /app
# Copy the binary from the builder stage to the final image
COPY --from=builder /app/main .
COPY --from=builder /app/migrate.linux-amd64 ./migrate
COPY app.env .
COPY start.sh .
COPY wait-for.sh .
COPY db/migration ./db/migration
# Install any necessary dependencies for your application
# For example, if your application requires SSL certificates, you may need to add them here.
# Expose port 8080 for the application
EXPOSE 8080
# Set the command to run the application
CMD ["./main"]
ENTRYPOINT ["/app/start.sh"]