-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
56 lines (41 loc) · 1.15 KB
/
Dockerfile
File metadata and controls
56 lines (41 loc) · 1.15 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
# syntax=docker/dockerfile:1
FROM golang:1.26-alpine AS builder
# Install build dependencies
RUN apk add --no-cache git ca-certificates tzdata
WORKDIR /build
COPY go.mod go.sum ./
RUN go mod download && go mod verify
# Copy source code
COPY . .
# Build with security flags
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \
go build \
-ldflags="-s -w -extldflags '-static'" \
-trimpath \
-o /xget \
./src
# Runtime stage
FROM alpine:3.20
# Add metadata labels
LABEL maintainer="xget" \
description="xget application" \
version="1.0"
# Install runtime dependencies
RUN apk add --no-cache \
ca-certificates \
tzdata \
&& update-ca-certificates
# Create non-root user and group
RUN addgroup -g 1000 -S xget && \
adduser -u 1000 -S xget -G xget -h /home/xget -s /sbin/nologin
# Create necessary directories with proper ownership
RUN mkdir -p /home/xget/.xget && \
chown -R xget:xget /home/xget
# Copy binary with proper ownership
COPY --from=builder --chown=xget:xget /xget /usr/local/bin/xget
# Set working directory
WORKDIR /home/xget
# Switch to non-root user
USER xget
# Use exec form for better signal handling
ENTRYPOINT ["/usr/local/bin/xget"]