From bee1f9968e8e87d7cac22c6a68fb6fe78f4763ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=A3=8E=E4=B9=8B=E5=87=8C=E6=AE=87?= Date: Fri, 12 Nov 2021 21:54:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=9C=A8=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E8=AF=AD=E4=B9=89=E5=8C=96=E7=89=88=E6=9C=ACtag=E6=97=B6?= =?UTF-8?q?=E8=87=AA=E5=8A=A8=E7=94=9F=E6=88=90static=E5=B9=B6=E6=9E=84?= =?UTF-8?q?=E5=BB=BA=E5=A4=9A=E4=B8=AA=E4=B8=8D=E5=90=8Ctag=E7=9A=84?= =?UTF-8?q?=E5=AE=B9=E5=99=A8=E7=9A=84workflow=EF=BC=8C=E7=AE=80=E5=8C=96?= =?UTF-8?q?=E7=89=88=E6=9C=AC=E5=8F=91=E5=B8=83=E6=B5=81=E7=A8=8B=20(#888)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build_docker_image.yml | 113 +++++++++++++++++++++++ docker/Dockerfile | 17 ++-- 2 files changed, 124 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/build_docker_image.yml diff --git a/.github/workflows/build_docker_image.yml b/.github/workflows/build_docker_image.yml new file mode 100644 index 00000000..e9407441 --- /dev/null +++ b/.github/workflows/build_docker_image.yml @@ -0,0 +1,113 @@ +name: Build And Push Docker Image + +on: + push: + branches: + - 'master' + - 'develop' + # Sequence of patterns matched against refs/tags + tags: + - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 + schedule: + # 参考 https://jasonet.co/posts/scheduled-actions/ + # note: 这里是GMT时间,北京时间减去八小时即可。如北京时间 22:30 => GMT 14:30 + # minute hour day month dayOfWeek + - cron: '00 14 * * *' # GMT 14:00 => 北京时间 22:00 + #- cron: '30 16 * * *' # GMT 16:30(前一天) => 北京时间 00:30 + workflow_dispatch: + +jobs: + build-static: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-node@v1 + with: + node-version: '14' + + - name: build front and back + run: | + yarn install + yarn build + yarn build-back + + - name: copy to static repo + env: + GITHUB_REPO: github.com/${{ github.repository_owner }}/qinglong-static + GITHUB_BRANCH: ${{ github.ref_name }} + run: | + mkdir -p static + cd ./static + cp -rf ../dist ./ && cp -rf ../build ./ + git init -b ${GITHUB_BRANCH} && git add . + git config --local user.name 'github-actions[bot]' + git config --local user.email 'github-actions[bot]@users.noreply.github.com' + git commit --allow-empty -m "copy static at $(date +'%Y-%m-%d %H:%M:%S')" + git push --force --quiet "https://${{ secrets.API_TOKEN }}@${GITHUB_REPO}.git" ${GITHUB_BRANCH}:${GITHUB_BRANCH} + + build: + needs: build-static + + runs-on: ubuntu-latest + + permissions: + packages: write + contents: read + + steps: + - uses: actions/checkout@v2 + + - name: Set time zone + uses: szenius/set-timezone@v1.0 + with: + timezoneLinux: "Asia/Shanghai" + timezoneMacos: "Asia/Shanghai" + timezoneWindows: "China Standard Time" + + - name: Login to DockerHub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + + - name: Login to GHCR + uses: docker/login-action@v1 + with: + registry: ghcr.io + username: ${{ github.repository_owner }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v3 + with: + images: | + ${{ github.repository }} + ghcr.io/${{ github.repository }} + # generate Docker tags based on the following events/attributes + # nightly, master, pr-2, 1.2.3, 1.2, 1 + tags: | + type=schedule,pattern=nightly + type=edge + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}} + + - name: Set up QEMU + uses: docker/setup-qemu-action@v1 + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Build and push + id: docker_build + uses: docker/build-push-action@v2 + with: + build-args: MAINTAINER=${{ github.repository_owner }}, QL_BRANCH=${{ github.ref_name }} + platforms: linux/amd64,linux/arm/v6,linux/arm/v7,linux/arm64,linux/s390x + context: docker/ + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} diff --git a/docker/Dockerfile b/docker/Dockerfile index 86f79f91..bc7e9a5c 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,14 +1,19 @@ FROM node:lts-alpine -LABEL maintainer="whyour" -ARG QL_URL=https://github.com/whyour/qinglong.git +ARG QL_MAINTAINER="whyour" +LABEL maintainer="${QL_MAINTAINER}" +ARG QL_URL=https://github.com/${QL_MAINTAINER}/qinglong.git ARG QL_BRANCH=master ENV PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin \ LANG=zh_CN.UTF-8 \ SHELL=/bin/bash \ PS1="\u@\h:\w \$ " \ - QL_DIR=/ql + QL_DIR=/ql \ + QL_MAINTAINER=${QL_MAINTAINER} \ + QL_URL=${QL_URL} \ + QL_BRANCH=${QL_BRANCH} WORKDIR ${QL_DIR} -RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories \ +RUN set -x \ + && sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories \ && apk update -f \ && apk upgrade \ && apk --no-cache add -f bash \ @@ -42,7 +47,7 @@ RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/re && rm -rf /root/.npm \ && pnpm install --prod \ && rm -rf /root/.pnpm-store \ - && git clone -b ${QL_BRANCH} https://github.com/whyour/qinglong-static.git /static \ + && git clone -b ${QL_BRANCH} https://github.com/${QL_MAINTAINER}/qinglong-static.git /static \ && cp -rf /static/* ${QL_DIR} \ && rm -rf /static -ENTRYPOINT ["./docker/docker-entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["./docker/docker-entrypoint.sh"]