Update Dockerfile to optimize build process and improve image size
This commit is contained in:
parent
62969880ad
commit
591adc6514
1 changed files with 20 additions and 4 deletions
20
Dockerfile
20
Dockerfile
|
@ -1,13 +1,29 @@
|
||||||
FROM golang:1.22
|
# Stage 1: Build the application
|
||||||
|
FROM golang:1.22 AS builder
|
||||||
|
|
||||||
WORKDIR /usr/src/app
|
WORKDIR /usr/src/app
|
||||||
|
|
||||||
|
|
||||||
COPY go.mod go.sum ./
|
COPY go.mod go.sum ./
|
||||||
RUN go mod download && go mod verify
|
RUN go mod download && go mod verify
|
||||||
|
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN CGO_ENABLED=1 GOOS=linux go build -ldflags="-s -w" -buildvcs=false -o /donetick
|
RUN CGO_ENABLED=1 GOOS=linux go build -ldflags="-s -w" -buildvcs=false -o /donetick
|
||||||
|
|
||||||
|
# Stage 2: Create a smaller runtime image
|
||||||
|
FROM alpine:latest
|
||||||
|
|
||||||
|
# Install necessary CA certificates
|
||||||
|
RUN apk --no-cache add ca-certificates
|
||||||
|
|
||||||
|
# Copy the binary and config folder from the builder stage
|
||||||
|
COPY --from=builder /donetick /donetick
|
||||||
|
COPY --from=builder /usr/src/app/config /config
|
||||||
|
|
||||||
|
# Set environment variables
|
||||||
ENV DT_ENV="selfhosted"
|
ENV DT_ENV="selfhosted"
|
||||||
|
|
||||||
|
# Expose the application port
|
||||||
EXPOSE 2021
|
EXPOSE 2021
|
||||||
|
|
||||||
|
# Command to run the application
|
||||||
CMD ["/donetick"]
|
CMD ["/donetick"]
|
Loading…
Add table
Reference in a new issue