-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
40 lines (37 loc) · 938 Bytes
/
Dockerfile
File metadata and controls
40 lines (37 loc) · 938 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Stage 1: Install dependencies
FROM golang:1.24-alpine AS deps
RUN apk add --no-cache libc6-compat git
WORKDIR /app
# Copy manifest
COPY go.mod go.sum ./
RUN go mod download
# Stage 2: Builder
FROM golang:1.24-alpine AS builder
WORKDIR /app
COPY --from=deps /go/pkg /go/pkg
COPY . .
# Build-time Arguments
ARG APP_VERSION=1.0.0
ENV CGO_ENABLED=0
ENV GOOS=linux
# Compile binary
RUN go build -ldflags="-s -w -X main.Version=${APP_VERSION}" -o main .
# Stage 3: Runner
FROM alpine:3.19 AS runner
WORKDIR /app
#metadata
LABEL author="VAXA STUDIO"
LABEL project="Go Distributed Limiter"
# Create non-root user
RUN addgroup --system --gid 1001 gopher && \
adduser --system --uid 1001 gopher
COPY --from=builder --chown=gopher:gopher /app/main ./
# Set Environment Variables
ENV APP_ENV=production
ENV REDIS_ADDR=redis:6379
# Use non-root user to run our application
USER gopher
EXPOSE 8080
ENV PORT 8080
# Run the binary
CMD ["./main"]