Files
hello_gitea/Dockerfile
direct-dev.ru 381eefa47b
Some checks failed
Release Build / release (push) Successful in 1m37s
Release Build / create-docker-image (push) Failing after 51s
Release Build / create-release (push) Has been skipped
Add Gin framework and create REST API endpoints
2025-07-27 14:42:45 +06:00

51 lines
1010 B
Docker

# Build stage
FROM --platform=$BUILDPLATFORM golang:1.21-alpine AS builder
# Install git and ca-certificates
RUN apk --no-cache add git ca-certificates
WORKDIR /app
# Copy go mod files
COPY go.mod go.sum ./
# Download dependencies
RUN go mod download
# Copy source code
COPY . .
# Build the application for target platform
ARG TARGETPLATFORM
ARG BUILDPLATFORM
ARG TARGETOS
ARG TARGETARCH
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -a -installsuffix cgo -o hello-api main.go
# Final stage
FROM alpine:latest
# Install jq and ca-certificates
RUN apk --no-cache add ca-certificates jq
# Create non-root user
RUN addgroup -g 1001 -S appgroup && \
adduser -u 1001 -S appuser -G appgroup
WORKDIR /app
# Copy binary from builder stage
COPY --from=builder /app/hello-api .
# Change ownership to non-root user
RUN chown appuser:appgroup hello-api
# Switch to non-root user
USER appuser
# Expose port (if your app uses one)
EXPOSE 8080
# Run the application
CMD ["./hello-api"]