ci: cache musl library in docker build workflow (#6392)

* ci: add musl libs into action cache

* build: update Dockerfile.ci
pull/6422/head
Mmx 2024-05-02 22:28:13 +08:00 committed by GitHub
parent b704bba444
commit 7bf5014417
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 44 additions and 11 deletions

View File

@ -32,10 +32,21 @@ jobs:
flavor: | flavor: |
suffix=-ffmpeg,onlatest=true suffix=-ffmpeg,onlatest=true
- uses: actions/setup-go@v4 - uses: actions/setup-go@v5
with: with:
go-version: 'stable' go-version: 'stable'
- name: Cache Musl
id: cache-musl
uses: actions/cache@v4
with:
path: build/musl-libs
key: docker-musl-libs
- name: Download Musl Library
if: steps.cache-musl.outputs.cache-hit != 'true'
run: bash build.sh prepare docker-multiplatform
- name: Build go binary - name: Build go binary
run: bash build.sh dev docker-multiplatform run: bash build.sh dev docker-multiplatform

View File

@ -13,10 +13,21 @@ jobs:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
- uses: actions/setup-go@v4 - uses: actions/setup-go@v5
with: with:
go-version: 'stable' go-version: 'stable'
- name: Cache Musl
id: cache-musl
uses: actions/cache@v4
with:
path: build/musl-libs
key: docker-musl-libs
- name: Download Musl Library
if: steps.cache-musl.outputs.cache-hit != 'true'
run: bash build.sh prepare docker-multiplatform
- name: Build go binary - name: Build go binary
run: bash build.sh release docker-multiplatform run: bash build.sh release docker-multiplatform

View File

@ -3,7 +3,7 @@ ARG TARGETPLATFORM
LABEL MAINTAINER="i@nn.ci" LABEL MAINTAINER="i@nn.ci"
VOLUME /opt/alist/data/ VOLUME /opt/alist/data/
WORKDIR /opt/alist/ WORKDIR /opt/alist/
COPY /${TARGETPLATFORM}/alist ./ COPY /build/${TARGETPLATFORM}/alist ./
COPY entrypoint.sh /entrypoint.sh COPY entrypoint.sh /entrypoint.sh
RUN apk update && \ RUN apk update && \
apk upgrade --no-cache && \ apk upgrade --no-cache && \

View File

@ -96,17 +96,24 @@ BuildDocker() {
go build -o ./bin/alist -ldflags="$ldflags" -tags=jsoniter . go build -o ./bin/alist -ldflags="$ldflags" -tags=jsoniter .
} }
BuildDockerMultiplatform() { PrepareBuildDockerMusl() {
PrepareBuildDocker mkdir -p build/musl-libs
BASE="https://musl.cc/" BASE="https://musl.cc/"
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) 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)
for i in "${FILES[@]}"; do for i in "${FILES[@]}"; do
url="${BASE}${i}.tgz" url="${BASE}${i}.tgz"
curl -L -o "${i}.tgz" "${url}" lib_tgz="build/${i}.tgz"
sudo tar xf "${i}.tgz" --strip-components 1 -C /usr/local curl -L -o "${lib_tgz}" "${url}"
rm -f "${i}.tgz" tar xf "${lib_tgz}" --strip-components 1 -C build/musl-libs
rm -f "${lib_tgz}"
done done
}
BuildDockerMultiplatform() {
PrepareBuildDocker
# run PrepareBuildDockerMusl before build
export PATH=$PATH:$PWD/build/musl-libs/bin
docker_lflags="--extldflags '-static -fpic' $ldflags" docker_lflags="--extldflags '-static -fpic' $ldflags"
export CGO_ENABLED=1 export CGO_ENABLED=1
@ -122,7 +129,7 @@ BuildDockerMultiplatform() {
export GOARCH=$arch export GOARCH=$arch
export CC=${cgo_cc} export CC=${cgo_cc}
echo "building for $os_arch" echo "building for $os_arch"
go build -o ./$os/$arch/alist -ldflags="$docker_lflags" -tags=jsoniter . go build -o build/$os/$arch/alist -ldflags="$docker_lflags" -tags=jsoniter .
done done
DOCKER_ARM_ARCHES=(linux-arm/v6 linux-arm/v7) DOCKER_ARM_ARCHES=(linux-arm/v6 linux-arm/v7)
@ -136,7 +143,7 @@ BuildDockerMultiplatform() {
export GOARM=${GO_ARM[$i]} export GOARM=${GO_ARM[$i]}
export CC=${cgo_cc} export CC=${cgo_cc}
echo "building for $docker_arch" echo "building for $docker_arch"
go build -o ./${docker_arch%%-*}/${docker_arch##*-}/alist -ldflags="$docker_lflags" -tags=jsoniter . go build -o build/${docker_arch%%-*}/${docker_arch##*-}/alist -ldflags="$docker_lflags" -tags=jsoniter .
done done
} }
@ -289,6 +296,10 @@ elif [ "$1" = "release" ]; then
BuildRelease BuildRelease
MakeRelease "md5.txt" MakeRelease "md5.txt"
fi fi
elif [ "$1" = "prepare" ]; then
if [ "$2" = "docker-multiplatform" ]; then
PrepareBuildDockerMusl
fi
else else
echo -e "Parameter error" echo -e "Parameter error"
fi fi