2024-01-10 00:10:39 +01:00
|
|
|
# Start from a Go base image
|
2024-01-10 01:11:25 +01:00
|
|
|
FROM golang:alpine3.19 AS builder
|
2024-01-10 00:10:39 +01:00
|
|
|
|
|
|
|
# Set the working directory
|
|
|
|
WORKDIR /app
|
|
|
|
|
|
|
|
# Copy the source code into the container
|
2024-01-12 20:12:34 +01:00
|
|
|
COPY go.mod .
|
|
|
|
COPY go.sum .
|
|
|
|
|
|
|
|
# Download required modules
|
2024-01-10 01:11:25 +01:00
|
|
|
RUN go mod download
|
2024-01-10 00:10:39 +01:00
|
|
|
|
2024-01-12 20:12:34 +01:00
|
|
|
# Copy the main application file
|
|
|
|
COPY main.go .
|
|
|
|
|
2024-01-10 00:10:39 +01:00
|
|
|
# Build the application
|
2024-01-12 20:12:34 +01:00
|
|
|
RUN CGO_ENABLED=0 GOOS=linux go build -o gitea-register-account-bot .
|
2024-01-10 00:10:39 +01:00
|
|
|
|
|
|
|
# Use a small base image
|
2024-01-10 01:11:25 +01:00
|
|
|
FROM alpine:edge
|
2024-01-10 00:10:39 +01:00
|
|
|
|
2024-01-12 20:12:34 +01:00
|
|
|
# Create and set the application directory
|
2024-01-10 01:11:25 +01:00
|
|
|
WORKDIR /app/
|
2024-01-10 00:10:39 +01:00
|
|
|
|
2024-01-12 20:12:34 +01:00
|
|
|
# Add a non-root user to run the application
|
|
|
|
RUN addgroup -S nonroot \
|
|
|
|
&& adduser -S nonroot -G nonroot
|
|
|
|
|
2024-01-10 00:10:39 +01:00
|
|
|
# Copy the binary from the builder stage
|
2024-01-12 20:12:34 +01:00
|
|
|
COPY --from=builder /app/gitea-register-account-bot /app/
|
|
|
|
|
|
|
|
# Change file ownership to the nonroot user
|
|
|
|
RUN chown -R nonroot:nonroot /app
|
|
|
|
|
|
|
|
# Change to nonroot user
|
|
|
|
USER nonroot
|
2024-01-10 00:10:39 +01:00
|
|
|
|
|
|
|
# Command to run the executable
|
2024-01-12 20:12:34 +01:00
|
|
|
CMD ["./gitea-register-account-bot"]
|