Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
63 lines (48 loc) · 1.35 KB
/
Copy pathDockerfile
File metadata and controls
63 lines (48 loc) · 1.35 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
# Stage 1: Builder
FROM rust:alpine3.23 AS builder
LABEL maintainer="mingcheng <mingcheng@apache.org>"
# Install build dependencies required for compilation
RUN apk add --no-cache \
build-base \
git \
musl-dev \
libressl-dev \
pkgconfig \
perl
WORKDIR /build
COPY . .
# Build the application with optimizations
RUN cargo build --release --locked && \
strip target/release/aigitcommit && \
cp target/release/aigitcommit /bin/aigitcommit
# Stage 2: Runtime
FROM alpine:3 AS runtime
# Set timezone (configurable via build args)
ARG TZ=Asia/Shanghai
ENV TZ=${TZ}
# Install only runtime dependencies
RUN apk add --no-cache \
tzdata \
git \
curl \
ca-certificates && \
ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && \
echo $TZ > /etc/timezone && \
# Clean up apk cache to reduce image size
rm -rf /var/cache/apk/*
# Copy the compiled binary from builder stage
COPY --from=builder /bin/aigitcommit /bin/aigitcommit
# Create a non-root user for security
RUN addgroup -g 1000 aigit && \
adduser -D -u 1000 -G aigit aigit
# Set the working directory
WORKDIR /repo
# Change ownership of the working directory
RUN chown -R aigit:aigit /repo
# Switch to non-root user
USER aigit
RUN aigitcommit --version
# Define the entrypoint
ENTRYPOINT ["/bin/aigitcommit"]
# Default command (can be overridden)
CMD ["--help"]