Skip to content

Commit d0c22a1

Browse files
dezhishenCopilot
andauthored
feat(ci): add the default user for docker image (#1036)
Co-authored-by: Copilot <[email protected]>
1 parent 57fceab commit d0c22a1

File tree

3 files changed

+45
-13
lines changed

3 files changed

+45
-13
lines changed

Dockerfile

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### Default image is base. You can add other support by modifying BASE_IMAGE_TAG. The following parameters are supported: base (default), aria2, ffmpeg, aio
2+
ARG BASE_IMAGE_TAG=base
3+
14
FROM alpine:edge AS builder
25
LABEL stage=go-builder
36
WORKDIR /app/
@@ -7,21 +10,26 @@ RUN go mod download
710
COPY ./ ./
811
RUN bash build.sh release docker
912

10-
### Default image is base. You can add other support by modifying BASE_IMAGE_TAG. The following parameters are supported: base (default), aria2, ffmpeg, aio
11-
ARG BASE_IMAGE_TAG=base
1213
FROM openlistteam/openlist-base-image:${BASE_IMAGE_TAG}
13-
14+
LABEL MAINTAINER="OpenList"
1415
ARG INSTALL_FFMPEG=false
1516
ARG INSTALL_ARIA2=false
16-
LABEL MAINTAINER="OpenList"
17+
ARG USER=openlist
18+
ARG UID=1001
19+
ARG GID=1001
1720

1821
WORKDIR /opt/openlist/
1922

2023
COPY --chmod=755 --from=builder /app/bin/openlist ./
2124
COPY --chmod=755 entrypoint.sh /entrypoint.sh
25+
RUN adduser -u ${UID} -g ${GID} -h /opt/openlist/data -D -s /bin/sh ${USER} \
26+
&& chown -R ${UID}:${GID} /opt \
27+
&& chown -R ${UID}:${GID} /entrypoint.sh
28+
29+
USER ${USER}
2230
RUN /entrypoint.sh version
2331

24-
ENV PUID=0 PGID=0 UMASK=022 RUN_ARIA2=${INSTALL_ARIA2}
32+
ENV UMASK=022 RUN_ARIA2=${INSTALL_ARIA2}
2533
VOLUME /opt/openlist/data/
2634
EXPOSE 5244 5245
2735
CMD [ "/entrypoint.sh" ]

Dockerfile.ci

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,26 @@
11
ARG BASE_IMAGE_TAG=base
22
FROM ghcr.io/openlistteam/openlist-base-image:${BASE_IMAGE_TAG}
3-
3+
LABEL MAINTAINER="OpenList"
44
ARG TARGETPLATFORM
55
ARG INSTALL_FFMPEG=false
66
ARG INSTALL_ARIA2=false
7-
LABEL MAINTAINER="OpenList"
7+
ARG USER=openlist
8+
ARG UID=1001
9+
ARG GID=1001
810

911
WORKDIR /opt/openlist/
1012

1113
COPY --chmod=755 /build/${TARGETPLATFORM}/openlist ./
1214
COPY --chmod=755 entrypoint.sh /entrypoint.sh
15+
16+
RUN adduser -u ${UID} -g ${GID} -h /opt/openlist/data -D -s /bin/sh ${USER} \
17+
&& chown -R ${UID}:${GID} /opt \
18+
&& chown -R ${UID}:${GID} /entrypoint.sh
19+
20+
USER ${USER}
1321
RUN /entrypoint.sh version
1422

15-
ENV PUID=0 PGID=0 UMASK=022 RUN_ARIA2=${INSTALL_ARIA2}
23+
ENV UMASK=022 RUN_ARIA2=${INSTALL_ARIA2}
1624
VOLUME /opt/openlist/data/
1725
EXPOSE 5244 5245
1826
CMD [ "/entrypoint.sh" ]

entrypoint.sh

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,26 @@ umask ${UMASK}
55
if [ "$1" = "version" ]; then
66
./openlist version
77
else
8+
# Define the target directory path for openlist service
9+
OPENLIST_DIR="/opt/service/start/openlist"
10+
if [ ! -d "$OPENLIST_DIR" ]; then
11+
cp -r /opt/service/stop/openlist "$OPENLIST_DIR" 2>/dev/null
12+
fi
13+
# Define the target directory path for aria2 service
14+
ARIA2_DIR="/opt/service/start/aria2"
15+
816
if [ "$RUN_ARIA2" = "true" ]; then
9-
cp -a /opt/service/stop/aria2 /opt/service/start 2>/dev/null
17+
# If aria2 should run and target directory doesn't exist, copy it
18+
if [ ! -d "$ARIA2_DIR" ]; then
19+
mkdir -p "$ARIA2_DIR"
20+
cp -r /opt/service/stop/aria2/* "$ARIA2_DIR" 2>/dev/null
21+
fi
22+
else
23+
# If aria2 should NOT run and target directory exists, remove it
24+
if [ -d "$ARIA2_DIR" ]; then
25+
rm -rf "$ARIA2_DIR"
26+
fi
1027
fi
11-
12-
chown -R ${PUID}:${PGID} /opt
13-
exec su-exec ${PUID}:${PGID} runsvdir /opt/service/start
14-
fi
28+
29+
exec runsvdir /opt/service/start
30+
fi

0 commit comments

Comments
 (0)