diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 00000000..6958daef --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,48 @@ +name: docker + +on: + push: + branches: + - 'v2' + tags: + - 'v*' + pull_request: + branches: + - 'v2' + +jobs: + 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: Set up Node + uses: actions/setup-node@v2 + with: + node-version: '16' + - name: Build web + run: bash build.sh web + - 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/ppc64le,linux/s390x \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..93e3b3e5 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,12 @@ +FROM golang:alpine as builder +LABEL stage=go-builder +WORKDIR /app/ +COPY ./ ./ +RUN bash build.sh docker + +FROM alpine +LABEL MAINTAINER="i@nn.ci" +WORKDIR /opt/alist/ +COPY --from=builder /alist/bin/alist ./ +EXPOSE 5244 +CMD [ "./alist" ] \ No newline at end of file diff --git a/build.sh b/build.sh index 8a626f61..6267932c 100644 --- a/build.sh +++ b/build.sh @@ -1,4 +1,33 @@ #!/bin/bash +if [ "$1" == "web" ]; then + git clone https://github.com/Xhofe/alist-web.git + cd alist-web || exit + yarn + yarn build + mv dist ../public + cd .. + exit 0 +fi + +if [ "$1" == "docker" ]; then + apk add --no-cache git + appName="alist" + builtAt="$(date +'%F %T %z')" + goVersion=$(go version | sed 's/go version //') + gitAuthor=$(git show -s --format='format:%aN <%ae>' HEAD) + gitCommit=$(git log --pretty=format:"%h" -1) + gitTag=$(git describe --abbrev=0 --tags) + ldflags="\ +-w -s \ +-X 'github.com/Xhofe/alist/conf.BuiltAt=$builtAt' \ +-X 'github.com/Xhofe/alist/conf.GoVersion=$goVersion' \ +-X 'github.com/Xhofe/alist/conf.GitAuthor=$gitAuthor' \ +-X 'github.com/Xhofe/alist/conf.GitCommit=$gitCommit' \ +-X 'github.com/Xhofe/alist/conf.GitTag=$gitTag' \ +" + go build -o ./bin/alist -ldflags="$ldflags" alist.go + exit 0 +fi cd alist-web || exit webCommit=$(git log --pretty=format:"%h" -1)