diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..5bf4c39 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,56 @@ +# Use an official Golang image as a builder +FROM golang:1.20 as builder + +# Set environment variables +ENV GO111MODULE=on \ + CGO_ENABLED=0 \ + GOOS=linux \ + GOARCH=amd64 + +# Set the working directory inside the container +WORKDIR /app + +# Copy go.mod and go.sum first to leverage Docker cache +COPY go.mod ./ + +# Download dependencies +RUN go mod download + +# Copy the rest of the application code +COPY . . + +# Build the Go application +RUN go build -o whois-daemon main.go + +# Use a minimal base image to run the application +FROM alpine:3.18 + +# Install CA certificates for HTTPS +RUN apk add --no-cache ca-certificates + +# Create a non-root user to run the app +RUN addgroup -S appgroup && adduser -S appuser -G appgroup + +# Set the working directory for the runtime container +WORKDIR /app + +# Copy the built application from the builder stage +COPY --from=builder /app/whois-daemon /app/ + +# Copy the data directory +COPY data /app/data + +# Set appropriate permissions for the app directory +RUN chown -R appuser:appgroup /app + +# Switch to the non-root user +USER appuser + +# Expose the port the daemon runs on, replace with the actual port number +EXPOSE 43 + +# Define the entrypoint +ENTRYPOINT ["/app/whois-daemon"] + +# Optional: Define the command +CMD ["--help"] diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..f6e078c --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module main.go + +go 1.22.6