-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
74 lines (55 loc) · 2.07 KB
/
Dockerfile
File metadata and controls
74 lines (55 loc) · 2.07 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# ---------- Build stage ----------
# Use Go Alpine image as builder for smaller image and faster build
FROM golang:1.24-bookworm AS builder
# Set build-time argument for version
ARG DBXGO_VERSION=main
# Install dependencies for building Go project
RUN apt-get update && apt-get install -y git make gcc libc6-dev && rm -rf /var/lib/apt/lists/*
# Set working directory inside container
WORKDIR /app
# Copy project files to container
COPY . .
# Build the Go binary with the specified version
RUN GOOS=linux make build VERSION=${DBXGO_VERSION}
# ---------- Runtime stage ----------
# Use minimal Debian image for runtime
FROM debian:bookworm-slim
# Set default timezone to Shanghai
ENV TZ=Asia/Shanghai
# Install runtime dependencies in a single layer
# - ca-certificates, curl, wget, jq, tzdata, mysql client
# - configure timezone
# - clean apt cache to reduce image size
RUN apt-get update && apt-get install -y --no-install-recommends \
ca-certificates curl wget jq tzdata default-mysql-client && \
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone && \
rm -rf /var/lib/apt/lists/* /var/cache/apt/*
# ==========================
# Store Configuration
# ==========================
ENV STORE_TYPE=file
# ==========================
# Source Configuration
# ==========================
ENV SOURCE_TYPE=mysql
ENV SOURCE_MYSQL_ADDR=127.0.0.1:3306
ENV SOURCE_MYSQL_USER=root
ENV SOURCE_MYSQL_PASSWORD=""
ENV SOURCE_MYSQL_INCLUDE_TABLE_REGEX=""
ENV SOURCE_MYSQL_EXCLUDE_TABLE_REGEX="mysql.*,information_schema.*,performance_schema.*,sys.*"
# ==========================
# Output Configuration
# ==========================
ENV OUTPUT_TYPE=stdout
# Create a non-root user for security
RUN useradd --system --no-create-home --shell /usr/sbin/nologin dbxgo
# Copy the built binary from builder stage
COPY --from=builder /app/dbxgo /usr/local/bin/dbxgo
# Set ownership to the non-root user
RUN chown dbxgo:dbxgo /usr/local/bin/dbxgo
# Switch to non-root user
USER dbxgo
# Set working directory
WORKDIR /app
# Default command to run the binary
CMD ["dbxgo","-c","/app/config.yaml"]