diff --git a/.github/workflows/build_docker.yml b/.github/workflows/build_docker.yml new file mode 100644 index 00000000..1edcee7c --- /dev/null +++ b/.github/workflows/build_docker.yml @@ -0,0 +1,39 @@ +name: build_docker + +on: + push: + branches: [ main ] + +jobs: + build_docker: + name: Docker + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Docker meta + id: meta + uses: docker/metadata-action@v3 + with: + images: xhofe/alist + - name: Replace release with dev + run: | + sed -i 's/release/dev/g' Dockerfile + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: xhofe + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm64,linux/arm/v7,linux/386,linux/arm/v6,linux/s390x \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..ffbb9659 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,14 @@ +FROM alpine:edge as builder +LABEL stage=go-builder +WORKDIR /app/ +COPY ./ ./ +RUN apk add --no-cache bash git go gcc musl-dev curl; \ + bash build.sh release docker + +FROM alpine:edge +LABEL MAINTAINER="i@nn.ci" +VOLUME /opt/alist/data/ +WORKDIR /opt/alist/ +COPY --from=builder /app/bin/alist ./ +EXPOSE 5244 +CMD [ "./alist", "server --no-prefix" ] \ No newline at end of file diff --git a/build.sh b/build.sh index 54a64a02..04ca99ed 100644 --- a/build.sh +++ b/build.sh @@ -4,12 +4,12 @@ goVersion=$(go version | sed 's/go version //') gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD) gitCommit=$(git log --pretty=format:"%h" -1) -if [ "$1" = "release" ]; then - version=$(git describe --long --tags --dirty --always) - webVersion=$(wget -qO- -t1 -T2 "https://api.github.com/repos/alist-org/alist-web/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g') -else +if [ "$1" = "dev" ]; then version="dev" webVersion="dev" +else + version=$(git describe --long --tags --dirty --always) + webVersion=$(wget -qO- -t1 -T2 "https://api.github.com/repos/alist-org/alist-web/releases/latest" | grep "tag_name" | head -n 1 | awk -F ":" '{print $2}' | sed 's/\"//g;s/,//g;s/ //g') fi echo "build version: $gitTag" @@ -24,7 +24,7 @@ ldflags="\ -X 'github.com/alist-org/alist/v3/internal/conf.WebVersion=$webVersion' \ " -FetchWebBuild() { +FetchWebDev() { curl -L https://codeload.github.com/alist-org/web-dist/tar.gz/refs/heads/main -o web-dist-main.tar.gz tar -zxvf web-dist-main.tar.gz rm -rf public/dist @@ -45,9 +45,17 @@ BuildDev() { cd .. || exit } +BuildDocker() { + go build -o ./bin/alist -ldflags="$ldflags" -tags=jsoniter . +} + if [ "$1" = "dev" ]; then - FetchWebBuild - BuildDev + FetchWebDev + if [ "$2" = "docker" ]; then + BuildDocker + else + BuildDev + fi elif [ "$1" = "release" ]; then echo -e "To be implement" else