diff --git a/.github/workflows/docker-deploy.yml b/.github/workflows/docker-deploy.yml new file mode 100644 index 0000000..3284e6d --- /dev/null +++ b/.github/workflows/docker-deploy.yml @@ -0,0 +1,72 @@ +name: deploy to docker hub + +on: + push: + tags: + - "v*.*.*" + branches: + - 'master' + +jobs: + docker-deploy: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v4 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v3 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + # 提供 docker 元数据,构建 docker images tag 时使用 + - + name: Extract Docker metadata + id: meta + uses: docker/metadata-action@v4 + with: + images: ${{ env.IMAGE_NAME }} + tags: | + # set latest tag for default branch + type=raw,value=latest,enable={{is_default_branch}} + # tag event + type=ref,enable=true,priority=600,prefix=,suffix=,event=tag + + # - + # name: Login to Docker Hub + # uses: docker/login-action@v3 + # with: + # # registry: ghcr.io # 声明镜像源 + # username: ${{ secrets.DOCKER_USERNAME }} + # password: ${{ secrets.DOCKER_PASSWORD }} # ${{ secrets.HUB_GITHUB_TOKEN }} + # - + # name: Build and push + # uses: docker/build-push-action@v5 + # with: + # push: true + # tags: ${{ steps.meta.outputs.tags }}:latest + + - + name: Build and push Docker Image + run: | + docker build -t ${{ env.REGISTRY }}/${{ steps.meta.outputs.tags }} -f Dockerfile . + docker login --username=${{ secrets.DOCKER_USERNAME }} --password ${{ secrets.DOCKER_PASSWORD }} ${{ env.REGISTRY }} + docker push ${{ env.REGISTRY }}/${{ steps.meta.outputs.tags }} + + # - + # name: Deploy Docker App + # uses: appleboy/ssh-action@master + # env: + # TZ: Asia/Shanghai + # with: + # host: ${{ secrets.HOST }} + # username: ${{ secrets.HOST_USERNAME }} + # key: ${{ secrets.HOST_SSHKEY }} + # port: ${{ secrets.PORT }} + # script: | + # wget https://raw.githubusercontent.com/${{ env.IMAGE_NAME }}/master/docker/docker-compose.yml + # ls + # cat docker-compose.yml + # docker-compose down -v + # docker-compose up -d diff --git a/.github/workflows/release.yml b/.github/workflows/npm-publish.yml similarity index 51% rename from .github/workflows/release.yml rename to .github/workflows/npm-publish.yml index 3434854..5d83dfe 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/npm-publish.yml @@ -1,6 +1,6 @@ # see: https://help.github.com/actions/language-and-framework-guides/publishing-nodejs-packages -name: Publish Package to npmjs +name: Publish to NPM on: push: @@ -23,39 +23,40 @@ jobs: concurrency: group: ${{ github.workflow }}-${{ github.ref }} steps: - - name: Checkout - uses: actions/checkout@v3 + - + name: Checkout + uses: actions/checkout@v4 with: submodules: 'recursive' - - - name: Install Node.js + - + name: Install Node.js uses: actions/setup-node@v3 with: node-version: 18 registry-url: https://registry.npmjs.com - - - uses: pnpm/action-setup@v2 + - name: Install pnpm + uses: pnpm/action-setup@v2 id: pnpm-install with: version: 8 run_install: false - - - name: Get pnpm store directory + - + name: Get pnpm store directory id: pnpm-cache shell: bash run: | echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT - - - uses: actions/cache@v3 + - name: Setup pnpm cache + uses: actions/cache@v3 with: path: ${{ steps.pnpm-cache.outputs.STORE_PATH }} key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }} restore-keys: | ${{ runner.os }}-pnpm-store- - - - name: Install dependencies + - + name: Install dependencies run: pnpm install --no-frozen-lockfile --ignore-scripts # - name: Build and npm-publish @@ -74,8 +75,8 @@ jobs: # with: # github_token: ${{ secrets.GITHUB_TOKEN }} # publish_dir: ./docs - - - name: Github Release + - + name: Github Release uses: softprops/action-gh-release@v1 if: startsWith(github.ref, 'refs/tags/') with: @@ -88,47 +89,3 @@ jobs: # ${{ secrets.ReleaseZipName }}.zip # LICENSE - docker-deploy: - runs-on: ubuntu-latest - steps: - - # 提供 docker 元数据,构建 docker images tag 时使用 - - name: Extract Docker metadata - id: meta - uses: docker/metadata-action@v4 - with: - images: ${{ env.IMAGE_NAME }} - tags: | - # set latest tag for default branch - type=raw,value=latest,enable={{is_default_branch}} - # tag event - type=ref,enable=true,priority=600,prefix=,suffix=,event=tag - - # 构建镜像 使用 docker/Build-And-push@v5 插件有问题 - - uses: actions/checkout@v2 - - name: Build Docker Image - run: | - docker build -t ${{ env.REGISTRY }}/${{ steps.meta.outputs.tags }} -f ./docker/nginx/Dockerfile . - - name: Push Docker Image - run: | - docker login --username=${{ secrets.DOCKER_USERNAME }} --password ${{ secrets.DOCKER_PASSWORD }} ${{ env.REGISTRY }} - docker push ${{ env.REGISTRY }}/${{ steps.meta.outputs.tags }} - - # 运行 docker 服务 - # 另外一种选择是通过 scp 将文件传到指定服务器,完成 docker-compose 启动 - # - name: Deploy Docker App - # uses: appleboy/ssh-action@master - # env: - # TZ: Asia/Shanghai - # with: - # host: ${{ secrets.HOST }} - # username: ${{ secrets.HOST_USERNAME }} - # key: ${{ secrets.HOST_SSHKEY }} - # port: ${{ secrets.PORT }} - # script: | - # # 获取 docker-compose 文件 - # wget https://raw.githubusercontent.com/${{ env.IMAGE_NAME }}/master/docker/docker-compose.yml - # ls - # cat docker-compose.yml - # docker-compose down -v - # docker-compose up -d