Prepare for deployment
This commit is contained in:
+40
@@ -0,0 +1,40 @@
|
||||
# Build stage
|
||||
FROM golang:1.22-alpine AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
# Copy and download dependencies
|
||||
COPY go.mod go.sum ./
|
||||
RUN go mod download
|
||||
|
||||
# Copy the source code
|
||||
COPY . .
|
||||
|
||||
# Install required packages for cgo
|
||||
RUN apk add --no-cache gcc musl-dev
|
||||
|
||||
# Build with cgo enabled
|
||||
ENV CGO_ENABLED=1
|
||||
|
||||
# Build the Go application
|
||||
RUN go build -o app .
|
||||
|
||||
# Runtime stage
|
||||
FROM alpine:latest
|
||||
|
||||
WORKDIR /root/
|
||||
|
||||
# Install SQLite CLI for runtime
|
||||
RUN apk add --no-cache sqlite
|
||||
|
||||
# Copy the binary from the builder stage
|
||||
COPY --from=builder /app/app .
|
||||
COPY --from=builder /app/static/index.html.tmpl ./static/index.html.tmpl
|
||||
COPY --from=builder /app/static/result.html.tmpl ./static/result.html.tmpl
|
||||
|
||||
# Expose the port the app runs on
|
||||
EXPOSE 8080
|
||||
|
||||
# Run the application
|
||||
CMD ["./app"]
|
||||
|
||||
Reference in New Issue
Block a user