-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
57 lines (41 loc) · 1.34 KB
/
Dockerfile
File metadata and controls
57 lines (41 loc) · 1.34 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# Multi-stage Dockerfile for Argus
FROM golang:1.24-alpine AS builder
WORKDIR /app
# Build arguments
ARG BUILD_VERSION=latest
ARG BUILD_TIME
ARG GIT_COMMIT
# Install build dependencies
RUN apk add --no-cache git ca-certificates tzdata
# Copy go mod files and source code
COPY go.mod go.sum ./
COPY . ./
# Download dependencies
RUN go mod download
# Build the application with build info
RUN CGO_ENABLED=0 GOOS=linux go build \
-ldflags="-w -s -X main.Version=${BUILD_VERSION} -X main.BuildTime=${BUILD_TIME} -X main.GitCommit=${GIT_COMMIT}" \
-o /app/service_binary ./cmd/argus
# Final stage
FROM alpine:3.17
# Install runtime dependencies
RUN apk --no-cache add ca-certificates tzdata wget
# Create non-root user
RUN adduser -D -s /bin/sh -u 10001 appuser
# Set working directory
WORKDIR /app
# Copy binary from builder stage
COPY --from=builder /app/service_binary /app/
# Change ownership to appuser
RUN chown -R appuser:appuser /app
# Switch to non-root user with specific UID
USER 10001
# Expose port
EXPOSE 3001
# Set environment variables
ENV CONFIG_DIR=/app/configs
ENV ENVIRONMENT=production
# Health check
HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
CMD wget --no-verbose --tries=1 --spider http://localhost:3001/health || exit 1
CMD ["./service_binary", "-env=${ENVIRONMENT:-production}", "-port=3001"]