Alpine Dockerfile

PHOTO EMBED

Sun Jan 21 2024 06:46:31 GMT+0000 (Coordinated Universal Time)

Saved by @IfedayoAwe

# Use a lightweight base image with Go
FROM golang:1.21-alpine as builder

# Set the working directory inside the container
WORKDIR /app

# Assuming the project root is two levels up
# Copy go mod and sum files
COPY ../../go.mod ../../go.sum ./

# Download all dependencies
RUN go mod download

# Copy the source from the project root to the working directory inside the container
COPY ../.. .

# Copy the .env file
COPY ../../.env ./

# Build the Go app
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o gradely-main .

# Start a new stage for the final image
FROM alpine:latest

WORKDIR /root/

# Copy the pre-built binary file from the previous stage
COPY --from=builder /app/gradely-main .

# Copy the .env file from the builder stage
COPY --from=builder /app/.env .

# Command to run the executable
CMD ["./gradely-main"]
content_copyCOPY