Files
schedtxt_api/Dockerfile
T
phoenixandphoenix 2045465111 tsk-6: Added docker support (#14)
Closes #6

Reviewed-on: phoenix/textsender-api#14
Co-authored-by: phoenix <kundeng00@pm.me>
Co-committed-by: phoenix <kundeng00@pm.me>
2025-11-05 18:22:55 +00:00

53 lines
1.1 KiB
Docker

# Multi-stage Dockerfile for Go application
FROM golang:1.25.3 AS builder
WORKDIR /app
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates \
openssh-client git
RUN mkdir -p -m 0700 ~/.ssh && \
ssh-keyscan git.kundeng.us >> ~/.ssh/known_hosts
# Configure Git to use SSH for GitHub
RUN git config --global url."ssh://git@git.kundeng.us".insteadOf "https://git.kundeng.us"
# Set up the Go environment for private modules
ENV GOPRIVATE=git.kundeng.us
# Copy go mod and sum files
COPY go.mod go.sum ./
RUN --mount=type=ssh mkdir src && \
go mod download
# Copy source code
COPY ./cmd ./cmd
COPY ./internal ./internal
COPY ./Makefile .
COPY ./.env .
COPY ./migrations ./migrations
# Build the application
RUN CGO_ENABLED=0 GOOS=linux make build
# Runtime stage
FROM alpine:latest AS production
RUN apk --no-cache add ca-certificates
WORKDIR /root/
# Copy the pre-built binary file from the previous stage
COPY --from=builder /app/textsender-api .
COPY --from=builder /app/.env ./
COPY --from=builder /app/migrations ./migrations
# Expose port
EXPOSE 8080
# Command to run the executable
CMD ["./textsender-api"]