Skip to content

Commit 2b2e0af

Browse files
Copilotmandarons
andcommitted
Optimize Dockerfile: remove unused packages, fix entrypoint, use multi-stage build, remove commented line
Co-authored-by: mandarons <50469173+mandarons@users.noreply.github.com>
1 parent 4d59b58 commit 2b2e0af

File tree

2 files changed

+28
-34
lines changed

2 files changed

+28
-34
lines changed

Dockerfile

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,27 @@
11
# syntax=docker/dockerfile:1
22

3+
# Build stage
4+
FROM python:3.10-alpine3.22 AS builder
5+
6+
# Install build dependencies
7+
COPY requirements.txt .
8+
RUN \
9+
echo "**** install build packages ****" && \
10+
apk add --no-cache --virtual=build-dependencies \
11+
git \
12+
gcc \
13+
musl-dev \
14+
python3-dev \
15+
libffi-dev \
16+
openssl-dev \
17+
cargo && \
18+
echo "**** install icloud app ****" && \
19+
pip install -U --no-cache-dir \
20+
pip \
21+
wheel && \
22+
pip install -U --no-cache-dir -r requirements.txt
23+
24+
# Runtime stage
325
FROM python:3.10-alpine3.22
426

527
# set version label
@@ -16,58 +38,30 @@ ENV HOME="/app"
1638
ENV PUID=911
1739
ENV PGID=911
1840

19-
# Install system dependencies and create user first for better caching
41+
# Install runtime dependencies and create user
2042
RUN \
2143
echo "**** update package repository ****" && \
2244
apk update && \
23-
echo "**** install packages ****" && \
45+
echo "**** install runtime packages ****" && \
2446
apk add --no-cache \
25-
sudo \
2647
libmagic \
2748
shadow \
28-
dumb-init \
2949
su-exec && \
3050
echo "**** create user ****" && \
3151
addgroup -g 911 abc && \
3252
adduser -D -u 911 -G abc -h /home/abc -s /bin/sh abc
3353

34-
# Install build dependencies and Python packages
35-
COPY requirements.txt .
36-
RUN \
37-
echo "**** install build packages ****" && \
38-
apk add --no-cache --virtual=build-dependencies \
39-
git \
40-
gcc \
41-
musl-dev \
42-
python3-dev \
43-
libffi-dev \
44-
openssl-dev \
45-
cargo && \
46-
echo "**** install icloud app ****" && \
47-
pip install -U --no-cache-dir \
48-
pip \
49-
wheel && \
50-
pip install -U --no-cache-dir -r requirements.txt && \
51-
echo "**** cleanup ****" && \
52-
apk del --purge \
53-
build-dependencies && \
54-
rm -rf \
55-
/tmp/* \
56-
/root/.cache \
57-
/root/.cargo && \
58-
rm requirements.txt
54+
# Copy Python packages from builder stage
55+
COPY --from=builder /usr/local/lib/python3.10/site-packages /usr/local/lib/python3.10/site-packages
56+
COPY --from=builder /usr/local/bin /usr/local/bin
5957

6058
# add local files
6159
COPY . /app/
6260
WORKDIR /app
6361

64-
# Create necessary directories
65-
RUN mkdir -p /icloud /config/session_data
66-
6762
# Create entrypoint script
6863
COPY docker-entrypoint.sh /usr/local/bin/
6964
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
7065

7166
EXPOSE 80
72-
# ENTRYPOINT ["/usr/bin/dumb-init", "--"]
7367
CMD ["/usr/local/bin/docker-entrypoint.sh"]

docker-entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ done
3939

4040
# Execute the main application as abc user
4141
echo "Starting iCloud Docker application..."
42-
su-exec abc:abc /app/init.sh
42+
exec su-exec abc /app/init.sh

0 commit comments

Comments
 (0)