add Dockerfile to build the go app
This commit is contained in:
42
Dockerfile
Normal file
42
Dockerfile
Normal 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"]
|
||||
Reference in New Issue
Block a user