# Build stage for YouTube search service FROM golang:1.21-alpine AS builder # Install git and other build dependencies RUN apk add --no-cache git # Set working directory WORKDIR /app # Copy go mod files COPY search.go ./ # Build the search service RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o youtube-search search.go # Final stage FROM alpine:latest # Install ca-certificates for HTTPS requests RUN apk --no-cache add ca-certificates wget # Create non-root user RUN addgroup -g 1001 -S appgroup && \ adduser -u 1001 -S appuser -G appgroup WORKDIR /app # Copy the binary from builder stage COPY --from=builder /app/youtube-search . # Change ownership to non-root user RUN chown appuser:appgroup youtube-search # Switch to non-root user USER appuser # Expose port EXPOSE 8090 # Health check HEALTHCHECK --interval=30s --timeout=10s --start-period=20s --retries=3 \ CMD wget --no-verbose --tries=1 --spider http://localhost:8090/youtube?q=test || exit 1 # Run the binary CMD ["./youtube-search"]