gitea-webhook-listener/Dockerfile

35 lines
1001 B
Docker
Raw Permalink Normal View History

2024-05-05 22:54:06 +02:00
# Start from the official Golang base image version 1.22
FROM golang:1.22-alpine as builder
# Set the Current Working Directory inside the container
WORKDIR /app
# Copy go mod and sum files
COPY go.mod go.sum ./
# Download all dependencies. Dependencies will be cached if the go.mod and go.sum files are not changed
RUN go mod download
# Copy the source code into the container
COPY . .
# Build the Go app
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o webhook-listener .
# Start a new stage from scratch using a slim version of Alpine for a smaller image size
FROM alpine:latest
WORKDIR /root/
# Copy the Pre-built binary file from the previous stage
COPY --from=builder /app/webhook-listener .
# Environment variable for the port, set a default value if not provided
ENV PORT=62082
# Expose the port specified by the PORT environment variable
EXPOSE $PORT
# Command to run the executable, modified to use the environment variable for the port
CMD ["./webhook-listener"]