52 lines
1.2 KiB
Docker
52 lines
1.2 KiB
Docker
FROM golang:1.19-alpine AS builder
|
|
|
|
# Install git and required dependencies
|
|
RUN apk update && apk add --no-cache git
|
|
|
|
# Set working directory
|
|
WORKDIR /app
|
|
|
|
# Copy go mod and sum files
|
|
COPY go.mod go.sum* ./
|
|
|
|
# Download dependencies
|
|
RUN go mod download
|
|
|
|
# Copy source code
|
|
COPY . .
|
|
|
|
# Build the application with optimizations
|
|
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -ldflags="-s -w" -o monaco-backend .
|
|
|
|
# Get cloudflared from official image
|
|
FROM cloudflare/cloudflared:latest AS cloudflared
|
|
|
|
# Use a smaller image for the final container
|
|
FROM alpine:latest
|
|
|
|
# Install Docker client
|
|
RUN apk update && apk add --no-cache docker-cli
|
|
|
|
# Create directories for cloudflared
|
|
RUN mkdir -p /etc/cloudflared
|
|
|
|
# Copy cloudflared from official image
|
|
COPY --from=cloudflared /usr/local/bin/cloudflared /usr/local/bin/cloudflared
|
|
|
|
# Copy the certificate file and config
|
|
COPY cert.pem /etc/cloudflared/cert.pem
|
|
COPY config.json /etc/cloudflared/config.json
|
|
|
|
# Copy the binary from builder
|
|
COPY --from=builder /app/monaco-backend /monaco-backend
|
|
|
|
# Copy the startup script
|
|
COPY start.sh /start.sh
|
|
RUN chmod +x /start.sh
|
|
|
|
# Expose port for local access
|
|
EXPOSE 8080
|
|
|
|
# Run the startup script
|
|
ENTRYPOINT ["/start.sh"]
|