# Dockerfile.runner
# Stage 1: Build the Go application
FROM golang:1.24-alpine AS builder
# Install protoc and dependencies
RUN apk add --no-cache bash curl git build-base protobuf
# Install protoc-gen-go and protoc-gen-go-grpc
RUN go install google.golang.org/protobuf/cmd/protoc-gen-go@latest && \
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
# Set the working directory for the entire repository
WORKDIR /devex
# Copy the go.mod and go.sum files specific to the runner application first.
# This allows Docker to cache the 'go mod tidy' step. If only your source code
# changes (but not the dependencies), this layer will be reused, speeding up builds.
COPY apps/runner/go.mod apps/runner/go.sum ./apps/runner/
# Set working directory for Go module to download modules
WORKDIR /devex/apps/runner
# Download modules. This layer will be cached if go.mod/go.sum haven't changed.
RUN go mod tidy
# Now, copy the rest of the application code.
# Changes here won't invalidate the 'go mod tidy' cache layer above.
WORKDIR /devex
COPY . .
# Set PATH so protoc can find plugins
ENV PATH="/go/bin:$PATH"
# Run the proto generation step
RUN make generate-proto
# Set working dir back to the Go module for building
WORKDIR /devex/apps/runner
# Build the Go application
# CGO_ENABLED=0 for static binary, GOOS=linux for Linux target
# -a -installsuffix cgo helps ensure a fully static binary
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main ./cmd/main.go
# --- Final Runner Image (Optional but Recommended for just the Go binary) ---
# This creates a very small image containing only the Go binary.
# You could use this if the runner was a standalone service.
FROM alpine:3.19
WORKDIR /app
COPY --from=builder /devex/apps/runner/main .
RUN chmod +x /app/main