Skip to content

Commit c6aa26b

Browse files
committed
refactor(ci): Refactor Docker build to use base images and dynamic Dockerfile generation (#904)
1 parent f1a6426 commit c6aa26b

File tree

5 files changed

+31
-74
lines changed

5 files changed

+31
-74
lines changed

.github/workflows/release_docker.yml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -125,15 +125,19 @@ jobs:
125125
image: ["latest", "ffmpeg", "aria2", "aio"]
126126
include:
127127
- image: "latest"
128+
base_image_tag: "base"
128129
build_arg: ""
129130
tag_favor: ""
130131
- image: "ffmpeg"
132+
base_image_tag: "ffmpeg"
131133
build_arg: INSTALL_FFMPEG=true
132134
tag_favor: "suffix=-ffmpeg,onlatest=true"
133135
- image: "aria2"
136+
base_image_tag: "aria2"
134137
build_arg: INSTALL_ARIA2=true
135138
tag_favor: "suffix=-aria2,onlatest=true"
136139
- image: "aio"
140+
base_image_tag: "aio"
137141
build_arg: |
138142
INSTALL_FFMPEG=true
139143
INSTALL_ARIA2=true
@@ -189,7 +193,9 @@ jobs:
189193
context: .
190194
file: Dockerfile.ci
191195
push: ${{ env.IMAGE_PUSH == 'true' }}
192-
build-args: ${{ matrix.build_arg }}
196+
build-args: |
197+
BASE_IMAGE_TAG=${{ matrix.base_image_tag }}
198+
${{ matrix.build_arg }}
193199
tags: ${{ steps.meta.outputs.tags }}
194200
labels: ${{ steps.meta.outputs.labels }}
195201
platforms: ${{ env.RELEASE_PLATFORMS }}
@@ -203,15 +209,19 @@ jobs:
203209
image: ["latest", "ffmpeg", "aria2", "aio"]
204210
include:
205211
- image: "latest"
212+
base_image_tag: "base"
206213
build_arg: ""
207214
tag_favor: "suffix=-lite,onlatest=true"
208215
- image: "ffmpeg"
216+
base_image_tag: "ffmpeg"
209217
build_arg: INSTALL_FFMPEG=true
210218
tag_favor: "suffix=-lite-ffmpeg,onlatest=true"
211219
- image: "aria2"
220+
base_image_tag: "aria2"
212221
build_arg: INSTALL_ARIA2=true
213222
tag_favor: "suffix=-lite-aria2,onlatest=true"
214223
- image: "aio"
224+
base_image_tag: "aio"
215225
build_arg: |
216226
INSTALL_FFMPEG=true
217227
INSTALL_ARIA2=true
@@ -267,7 +277,9 @@ jobs:
267277
context: .
268278
file: Dockerfile.ci
269279
push: ${{ env.IMAGE_PUSH == 'true' }}
270-
build-args: ${{ matrix.build_arg }}
280+
build-args: |
281+
BASE_IMAGE_TAG=${{ matrix.base_image_tag }}
282+
${{ matrix.build_arg }}
271283
tags: ${{ steps.meta.outputs.tags }}
272284
labels: ${{ steps.meta.outputs.labels }}
273-
platforms: ${{ env.RELEASE_PLATFORMS }}
285+
platforms: ${{ env.RELEASE_PLATFORMS }}

.github/workflows/test_docker.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,19 @@ jobs:
7777
image: ["latest", "ffmpeg", "aria2", "aio"]
7878
include:
7979
- image: "latest"
80+
base_image_tag: "base"
8081
build_arg: ""
8182
tag_favor: ""
8283
- image: "ffmpeg"
84+
base_image_tag: "ffmpeg"
8385
build_arg: INSTALL_FFMPEG=true
8486
tag_favor: "suffix=-ffmpeg,onlatest=true"
8587
- image: "aria2"
88+
base_image_tag: "aria2"
8689
build_arg: INSTALL_ARIA2=true
8790
tag_favor: "suffix=-aria2,onlatest=true"
8891
- image: "aio"
92+
base_image_tag: "aio"
8993
build_arg: |
9094
INSTALL_FFMPEG=true
9195
INSTALL_ARIA2=true
@@ -137,7 +141,9 @@ jobs:
137141
context: .
138142
file: Dockerfile.ci
139143
push: ${{ env.IMAGE_PUSH == 'true' }}
140-
build-args: ${{ matrix.build_arg }}
144+
build-args: |
145+
BASE_IMAGE_TAG=${{ matrix.base_image_tag }}
146+
${{ matrix.build_arg }}
141147
tags: ${{ steps.meta.outputs.tags }}
142148
labels: ${{ steps.meta.outputs.labels }}
143149
platforms: ${{ env.RELEASE_PLATFORMS }}

Dockerfile

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM docker.io/library/alpine:edge AS builder
1+
FROM alpine:edge AS builder
22
LABEL stage=go-builder
33
WORKDIR /app/
44
RUN apk add --no-cache bash curl jq gcc git go musl-dev
@@ -7,46 +7,16 @@ RUN go mod download
77
COPY ./ ./
88
RUN bash build.sh release docker
99

10-
FROM alpine:edge
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
12+
FROM openlistteam/openlist-base-image:${BASE_IMAGE_TAG}
1113

1214
ARG INSTALL_FFMPEG=false
1315
ARG INSTALL_ARIA2=false
1416
LABEL MAINTAINER="OpenList"
1517

1618
WORKDIR /opt/openlist/
1719

18-
RUN apk update && \
19-
apk upgrade --no-cache && \
20-
apk add --no-cache bash ca-certificates su-exec tzdata runit; \
21-
[ "$INSTALL_FFMPEG" = "true" ] && apk add --no-cache ffmpeg; \
22-
[ "$INSTALL_ARIA2" = "true" ] && apk add --no-cache curl aria2 && \
23-
mkdir -p /opt/aria2/.aria2 && \
24-
wget https://github.com/P3TERX/aria2.conf/archive/refs/heads/master.tar.gz -O /tmp/aria-conf.tar.gz && \
25-
tar -zxvf /tmp/aria-conf.tar.gz -C /opt/aria2/.aria2 --strip-components=1 && rm -f /tmp/aria-conf.tar.gz && \
26-
sed -i 's|rpc-secret|#rpc-secret|g' /opt/aria2/.aria2/aria2.conf && \
27-
sed -i 's|/root/.aria2|/opt/aria2/.aria2|g' /opt/aria2/.aria2/aria2.conf && \
28-
sed -i 's|/root/.aria2|/opt/aria2/.aria2|g' /opt/aria2/.aria2/script.conf && \
29-
sed -i 's|/root|/opt/aria2|g' /opt/aria2/.aria2/aria2.conf && \
30-
sed -i 's|/root|/opt/aria2|g' /opt/aria2/.aria2/script.conf && \
31-
mkdir -p /opt/service/stop/aria2/log && \
32-
echo '#!/bin/sh' > /opt/service/stop/aria2/run && \
33-
echo 'exec 2>&1' >> /opt/service/stop/aria2/run && \
34-
echo 'exec aria2c --enable-rpc --rpc-allow-origin-all --conf-path=/opt/aria2/.aria2/aria2.conf' >> /opt/service/stop/aria2/run && \
35-
echo '#!/bin/sh' > /opt/service/stop/aria2/log/run && \
36-
echo 'mkdir -p /opt/openlist/data/log/aria2 2>/dev/null' >> /opt/service/stop/aria2/log/run && \
37-
echo 'exec svlogd /opt/openlist/data/log/aria2' >> /opt/service/stop/aria2/log/run && \
38-
chmod +x /opt/service/stop/aria2/run /opt/service/stop/aria2/log/run && \
39-
touch /opt/aria2/.aria2/aria2.session && \
40-
/opt/aria2/.aria2/tracker.sh ; \
41-
rm -rf /var/cache/apk/*
42-
43-
RUN mkdir -p /opt/service/start/openlist && \
44-
echo '#!/bin/sh' > /opt/service/start/openlist/run && \
45-
echo 'exec 2>&1' >> /opt/service/start/openlist/run && \
46-
echo 'cd /opt/openlist' >> /opt/service/start/openlist/run && \
47-
echo 'exec ./openlist server --no-prefix' >> /opt/service/start/openlist/run && \
48-
chmod +x /opt/service/start/openlist/run
49-
5020
COPY --chmod=755 --from=builder /app/bin/openlist ./
5121
COPY --chmod=755 entrypoint.sh /entrypoint.sh
5222
RUN /entrypoint.sh version

Dockerfile.ci

Lines changed: 2 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
FROM docker.io/library/alpine:edge
1+
ARG BASE_IMAGE_TAG=base
2+
FROM ghcr.io/openlistteam/openlist-base-image:${BASE_IMAGE_TAG}
23

34
ARG TARGETPLATFORM
45
ARG INSTALL_FFMPEG=false
@@ -7,38 +8,6 @@ LABEL MAINTAINER="OpenList"
78

89
WORKDIR /opt/openlist/
910

10-
RUN apk update && \
11-
apk upgrade --no-cache && \
12-
apk add --no-cache bash ca-certificates su-exec tzdata runit; \
13-
[ "$INSTALL_FFMPEG" = "true" ] && apk add --no-cache ffmpeg; \
14-
[ "$INSTALL_ARIA2" = "true" ] && apk add --no-cache curl aria2 && \
15-
mkdir -p /opt/aria2/.aria2 && \
16-
wget https://github.com/P3TERX/aria2.conf/archive/refs/heads/master.tar.gz -O /tmp/aria-conf.tar.gz && \
17-
tar -zxvf /tmp/aria-conf.tar.gz -C /opt/aria2/.aria2 --strip-components=1 && rm -f /tmp/aria-conf.tar.gz && \
18-
sed -i 's|rpc-secret|#rpc-secret|g' /opt/aria2/.aria2/aria2.conf && \
19-
sed -i 's|/root/.aria2|/opt/aria2/.aria2|g' /opt/aria2/.aria2/aria2.conf && \
20-
sed -i 's|/root/.aria2|/opt/aria2/.aria2|g' /opt/aria2/.aria2/script.conf && \
21-
sed -i 's|/root|/opt/aria2|g' /opt/aria2/.aria2/aria2.conf && \
22-
sed -i 's|/root|/opt/aria2|g' /opt/aria2/.aria2/script.conf && \
23-
mkdir -p /opt/service/stop/aria2/log && \
24-
echo '#!/bin/sh' > /opt/service/stop/aria2/run && \
25-
echo 'exec 2>&1' >> /opt/service/stop/aria2/run && \
26-
echo 'exec aria2c --enable-rpc --rpc-allow-origin-all --conf-path=/opt/aria2/.aria2/aria2.conf' >> /opt/service/stop/aria2/run && \
27-
echo '#!/bin/sh' > /opt/service/stop/aria2/log/run && \
28-
echo 'mkdir -p /opt/openlist/data/log/aria2 2>/dev/null' >> /opt/service/stop/aria2/log/run && \
29-
echo 'exec svlogd /opt/openlist/data/log/aria2' >> /opt/service/stop/aria2/log/run && \
30-
chmod +x /opt/service/stop/aria2/run /opt/service/stop/aria2/log/run && \
31-
touch /opt/aria2/.aria2/aria2.session && \
32-
/opt/aria2/.aria2/tracker.sh ; \
33-
rm -rf /var/cache/apk/*
34-
35-
RUN mkdir -p /opt/service/start/openlist && \
36-
echo '#!/bin/sh' > /opt/service/start/openlist/run && \
37-
echo 'exec 2>&1' >> /opt/service/start/openlist/run && \
38-
echo 'cd /opt/openlist' >> /opt/service/start/openlist/run && \
39-
echo 'exec ./openlist server --no-prefix' >> /opt/service/start/openlist/run && \
40-
chmod +x /opt/service/start/openlist/run
41-
4211
COPY --chmod=755 /build/${TARGETPLATFORM}/openlist ./
4312
COPY --chmod=755 entrypoint.sh /entrypoint.sh
4413
RUN /entrypoint.sh version

build.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ BuildDocker() {
164164
PrepareBuildDockerMusl() {
165165
mkdir -p build/musl-libs
166166
BASE="https://github.com/OpenListTeam/musl-compilers/releases/latest/download/"
167-
FILES=(x86_64-linux-musl-cross aarch64-linux-musl-cross i486-linux-musl-cross s390x-linux-musl-cross armv6-linux-musleabihf-cross armv7l-linux-musleabihf-cross riscv64-linux-musl-cross powerpc64le-linux-musl-cross)
167+
FILES=(x86_64-linux-musl-cross aarch64-linux-musl-cross i486-linux-musl-cross armv6-linux-musleabihf-cross armv7l-linux-musleabihf-cross riscv64-linux-musl-cross powerpc64le-linux-musl-cross) ## Disable s390x-linux-musl-cross builds
168168
for i in "${FILES[@]}"; do
169169
url="${BASE}${i}.tgz"
170170
lib_tgz="build/${i}.tgz"
@@ -183,8 +183,8 @@ BuildDockerMultiplatform() {
183183
docker_lflags="--extldflags '-static -fpic' $ldflags"
184184
export CGO_ENABLED=1
185185

186-
OS_ARCHES=(linux-amd64 linux-arm64 linux-386 linux-s390x linux-riscv64 linux-ppc64le)
187-
CGO_ARGS=(x86_64-linux-musl-gcc aarch64-linux-musl-gcc i486-linux-musl-gcc s390x-linux-musl-gcc riscv64-linux-musl-gcc powerpc64le-linux-musl-gcc)
186+
OS_ARCHES=(linux-amd64 linux-arm64 linux-386 linux-riscv64 linux-ppc64le) ## Disable linux-s390x builds
187+
CGO_ARGS=(x86_64-linux-musl-gcc aarch64-linux-musl-gcc i486-linux-musl-gcc riscv64-linux-musl-gcc powerpc64le-linux-musl-gcc) ## Disable s390x-linux-musl-gcc builds
188188
for i in "${!OS_ARCHES[@]}"; do
189189
os_arch=${OS_ARCHES[$i]}
190190
cgo_cc=${CGO_ARGS[$i]}

0 commit comments

Comments
 (0)