From 5a2a3e95ea19f86b66e7017f9d6905133816fa00 Mon Sep 17 00:00:00 2001 From: Muhammed Efe Cetin Date: Mon, 17 Mar 2025 10:23:28 +0300 Subject: [PATCH] infra: add support for docker --- Dockerfile | 25 +++++++++++++++++++++++++ config.yaml | 2 +- docker-compose.yaml | 11 ++++++----- 3 files changed, 32 insertions(+), 6 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..75315c9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +FROM golang:1.24-alpine AS builder + +WORKDIR /src + +# Copy go mod and project files +COPY go.* ./ +RUN go mod download +COPY . . + +# Install necessary dependencies +RUN apk update && apk add --no-cache git ca-certificates openssl && update-ca-certificates + +# Build the binary +RUN CGO_ENABLED=0 go build -ldflags "-s -w" -o ./hastebin ./cmd/main.go + +FROM gcr.io/distroless/static:nonroot +COPY --from=builder /etc/ssl/certs /etc/ssl/certs + +# Copy the binary from the builder stage +COPY --from=builder /src/hastebin /bin/hastebin + +# Set the user and group +USER 0:0 + +CMD ["/bin/hastebin", "--config", "/app/config.yaml"] \ No newline at end of file diff --git a/config.yaml b/config.yaml index 11cecf7..d1c76b1 100644 --- a/config.yaml +++ b/config.yaml @@ -13,7 +13,7 @@ storage: documents: - key: "about" - path: "./about.md" + path: "/app/about.md" rate_limiting: enable: true diff --git a/docker-compose.yaml b/docker-compose.yaml index 155d09f..10201b9 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -3,10 +3,11 @@ services: haste-server: build: . environment: - - STORAGE_TYPE=memcached - - STORAGE_HOST=memcached - - STORAGE_PORT=11211 + - STORAGE_TYPE=file + - STORAGE_FILE_PATH=/app/pastes ports: - "7777:7777" - memcached: - image: memcached:latest + volumes: + - ./config.yaml:/app/config.yaml + - ./about.md:/app/about.md + - "./data:/app/pastes"