add Dockerfile to build the go app

This commit is contained in:
2025-01-11 01:00:32 +01:00
parent 77f391f24d
commit bda62c508e
4 changed files with 68 additions and 4 deletions

42
Dockerfile Normal file
View File

@@ -0,0 +1,42 @@
# Stage 1: Build the Go application
FROM golang:1.23 AS builder
ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOARCH=amd64
WORKDIR /app
# Copy the Go modules and dependencies
COPY ./golang/go.mod ./golang/go.sum ./
RUN go mod download
# Copy the source code
COPY ./golang/cmd ./cmd
COPY ./golang/assets ./assets
COPY ./golang/internal ./internal
# Build the application
RUN go build -o main cmd/frontend/*
# Stage 2: Run the application
FROM alpine:latest
ENV DB_HOST="10.99.0.3"
ENV DB_PORT="5432"
ENV DB_NAME="crowsnest"
ENV DB_USER="crow"
ENV DB_PASS=""
# Set the working directory
WORKDIR /app
# Copy the built binary from the builder stage
COPY --from=builder /app/main .
COPY ./golang/assets ./assets
# Expose the desired port (e.g., 8080)
EXPOSE 8080
# Command to run the application
CMD ["/app/main"]