Skip to content

Commit

Permalink
ci: add musl libs into cache
Browse files Browse the repository at this point in the history
  • Loading branch information
Mmx233 committed Apr 24, 2024
1 parent 7500a62 commit 44edd66
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 9 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/release_docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ jobs:
with:
go-version: 'stable'

- name: Cache Musl
id: cache-musl
uses: actions/cache@v4
with:
path: |
build/musl-libs
# Cache valid for a month
key: $(date +%Y-%m)-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
run: bash build.sh release docker-multiplatform

Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.ci
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ARG TARGETPLATFORM
LABEL MAINTAINER="i@nn.ci"
VOLUME /opt/alist/data/
WORKDIR /opt/alist/
COPY /${TARGETPLATFORM}/alist ./
COPY /build/${TARGETPLATFORM}/alist ./
COPY entrypoint.sh /entrypoint.sh
RUN apk update && \
apk upgrade --no-cache && \
Expand Down
27 changes: 19 additions & 8 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -96,17 +96,24 @@ BuildDocker() {
go build -o ./bin/alist -ldflags="$ldflags" -tags=jsoniter .
}

BuildDockerMultiplatform() {
PrepareBuildDocker

PrepareBuildDockerMusl() {
mkdir -p build/musl-libs
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)
for i in "${FILES[@]}"; do
url="${BASE}${i}.tgz"
curl -L -o "${i}.tgz" "${url}"
sudo tar xf "${i}.tgz" --strip-components 1 -C /usr/local
rm -f "${i}.tgz"
lib_tgz="build/${i}.tgz"
curl -L -o "${lib_tgz}" "${url}"
tar xf "${lib_tgz}" --strip-components 1 -C build/musl-libs
rm -f "${lib_tgz}"
done
}

BuildDockerMultiplatform() {
PrepareBuildDocker

# run PrepareBuildDockerMusl before build
export PATH=$PATH:$PWD/build/musl-libs/bin

docker_lflags="--extldflags '-static -fpic' $ldflags"
export CGO_ENABLED=1
Expand All @@ -122,7 +129,7 @@ BuildDockerMultiplatform() {
export GOARCH=$arch
export CC=${cgo_cc}
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

DOCKER_ARM_ARCHES=(linux-arm/v6 linux-arm/v7)
Expand All @@ -136,7 +143,7 @@ BuildDockerMultiplatform() {
export GOARM=${GO_ARM[$i]}
export CC=${cgo_cc}
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
}

Expand Down Expand Up @@ -289,6 +296,10 @@ elif [ "$1" = "release" ]; then
BuildRelease
MakeRelease "md5.txt"
fi
elif [ "$1" = "prepare" ]; then
if [ "$2" = "docker-multiplatform" ]; then
PrepareBuildDockerMusl
fi
else
echo -e "Parameter error"
fi

0 comments on commit 44edd66

Please sign in to comment.