Dockerized uwu

Signed-off-by: caramelpony <caramel@candyhorses.network>
This commit is contained in:
caramelpony
2024-12-29 15:41:56 -07:00
parent 1878aa76c6
commit 8c8109ff73
2 changed files with 59 additions and 0 deletions

56
Dockerfile Normal file
View File

@@ -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 <port> with the actual port number
EXPOSE 43
# Define the entrypoint
ENTRYPOINT ["/app/whois-daemon"]
# Optional: Define the command
CMD ["--help"]

3
go.mod Normal file
View File

@@ -0,0 +1,3 @@
module main.go
go 1.22.6