aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Mo Tarbin <mhed.t91@gmail.com>2024-09-06 01:02:25 -0400
committerLibravatar Mo Tarbin <mhed.t91@gmail.com>2024-09-06 01:13:29 -0400
commit591adc6514c0fe0e8c4cff1a68fdc4b20d615f26 (patch)
tree620e5ab0f5d1de2206b82372b3972a90e0e44a4c
parent62969880ad14d2c8678d22c3a5d663d0cb02fb46 (diff)
downloaddonetick-591adc6514c0fe0e8c4cff1a68fdc4b20d615f26.tar.gz
donetick-591adc6514c0fe0e8c4cff1a68fdc4b20d615f26.tar.bz2
donetick-591adc6514c0fe0e8c4cff1a68fdc4b20d615f26.zip
Update Dockerfile to optimize build process and improve image size
-rw-r--r--Dockerfile24
1 files changed, 20 insertions, 4 deletions
diff --git a/Dockerfile b/Dockerfile
index 3508e96..ef46a01 100644
--- a/Dockerfile
+++ b/Dockerfile
@@ -1,13 +1,29 @@
-FROM golang:1.22
+# Stage 1: Build the application
+FROM golang:1.22 AS builder
WORKDIR /usr/src/app
-
COPY go.mod go.sum ./
RUN go mod download && go mod verify
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"
-EXPOSE 2021
+
+# Expose the application port
+EXPOSE 2021
+
+# Command to run the application
CMD ["/donetick"] \ No newline at end of file