From ab37ab61662bc648385a11017e8533f1be4c890c Mon Sep 17 00:00:00 2001 From: yiyun Date: Wed, 13 Apr 2022 21:25:09 +0800 Subject: [PATCH] ci(deploy,.github): update --- .../workflows/QQBotHub-docker-push-beta.yml | 50 ++++++++++++++ .../QQBotHub-docker-push-release.yml | 52 ++++++++++++++ .github/workflows/QQBotHub-release.yml | 67 +++++++++++++++++++ .../workflows/QQHelloWorldPlugin-release.yml | 49 ++++++++++++++ .github/workflows/sync-gitee.yml | 20 ++++++ app.json | 32 +++++++++ deploy/flyio/Dockerfile | 9 +++ deploy/flyio/flyio-PluginCore.Config.json | 1 + deploy/flyio/flyio-entrypoint.sh | 21 ++++++ deploy/heroku/Dockerfile | 13 ++++ deploy/heroku/heroku-PluginCore.Config.json | 1 + deploy/heroku/heroku-entrypoint.sh | 29 ++++++++ deploy/heroku/settings.json | 4 ++ deploy/railway/Dockerfile | 13 ++++ deploy/railway/railway-PluginCore.Config.json | 1 + deploy/railway/railway-entrypoint.sh | 29 ++++++++ deploy/railway/settings.json | 4 ++ heroku.yml | 3 + 18 files changed, 398 insertions(+) create mode 100644 .github/workflows/QQBotHub-docker-push-beta.yml create mode 100644 .github/workflows/QQBotHub-docker-push-release.yml create mode 100644 .github/workflows/QQBotHub-release.yml create mode 100644 .github/workflows/QQHelloWorldPlugin-release.yml create mode 100644 .github/workflows/sync-gitee.yml create mode 100644 app.json create mode 100644 deploy/flyio/Dockerfile create mode 100644 deploy/flyio/flyio-PluginCore.Config.json create mode 100644 deploy/flyio/flyio-entrypoint.sh create mode 100644 deploy/heroku/Dockerfile create mode 100644 deploy/heroku/heroku-PluginCore.Config.json create mode 100644 deploy/heroku/heroku-entrypoint.sh create mode 100644 deploy/heroku/settings.json create mode 100644 deploy/railway/Dockerfile create mode 100644 deploy/railway/railway-PluginCore.Config.json create mode 100644 deploy/railway/railway-entrypoint.sh create mode 100644 deploy/railway/settings.json create mode 100644 heroku.yml diff --git a/.github/workflows/QQBotHub-docker-push-beta.yml b/.github/workflows/QQBotHub-docker-push-beta.yml new file mode 100644 index 000000000..7429f706b --- /dev/null +++ b/.github/workflows/QQBotHub-docker-push-beta.yml @@ -0,0 +1,50 @@ +name: Docker Image CI/CD - Beta - Dragonfly + +on: + push: + branches: [ main ] + +jobs: + # build and push + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Get latest release + id: last_release + uses: InsonusK/get-latest-release@v1.0.1 + with: + myToken: ${{ github.token }} + exclude_types: "release, prerelease" + view_top: 1 + + - name: Set outputs + id: vars + run: | + echo ::set-output name=IMAGE_NAME::qqbothub + + - name: Build Image + run: | + docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ steps.vars.outputs.IMAGE_NAME }}:${{ steps.last_release.outputs.tag_name }}-beta -f src/WebApi/Dockerfile . + + - name: Login to Registry - Docker Hub + run: docker login --username=${{ secrets.DOCKER_USERNAME }} --password ${{ secrets.DOCKER_PASSWORD }} + + - name: Push Image - Docker + # push: last_release-beta + run: | + docker push ${{ secrets.DOCKER_USERNAME }}/${{ steps.vars.outputs.IMAGE_NAME }}:${{ steps.last_release.outputs.tag_name }}-beta + + - name: Login to Registry - ghcr.io + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + + - name: Push Image - ghcr.io + # push: last_release-beta + run: | + IMAGE_ID=ghcr.io/${{ github.repository_owner }}/${{ steps.vars.outputs.IMAGE_NAME }} + VERSION=${{ steps.last_release.outputs.tag_name }}-beta + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + docker tag ${{ secrets.DOCKER_USERNAME }}/${{ steps.vars.outputs.IMAGE_NAME }}:${{ steps.last_release.outputs.tag_name }}-beta $IMAGE_ID:$VERSION + docker push $IMAGE_ID:$VERSION diff --git a/.github/workflows/QQBotHub-docker-push-release.yml b/.github/workflows/QQBotHub-docker-push-release.yml new file mode 100644 index 000000000..543819ded --- /dev/null +++ b/.github/workflows/QQBotHub-docker-push-release.yml @@ -0,0 +1,52 @@ +name: Docker Image CI/CD - Release - Dragonfly + +on: +# release: +# types: [published] + push: + tags: + - 'QQBotHub-v*' + +jobs: + # build and push + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + + - name: Set outputs + id: vars + run: | + #echo ::set-output name=RELEASE_VERSION::$(echo ${GITHUB_REF:10}) + # 去掉前面的 refs/tags/QQBotHub- + echo ::set-output name=RELEASE_VERSION::$(echo ${GITHUB_REF:19}) + echo ::set-output name=IMAGE_NAME::qqbothub + + - name: Build Image + run: | + docker build -t ${{ secrets.DOCKER_USERNAME }}/${{ steps.vars.outputs.IMAGE_NAME }}:${{ steps.vars.outputs.RELEASE_VERSION }} -f src/WebApi/Dockerfile . + + - name: Login to Registry - Docker Hub + run: docker login --username=${{ secrets.DOCKER_USERNAME }} --password ${{ secrets.DOCKER_PASSWORD }} + + - name: Push Image - Docker Hub + # push: RELEASE_VERSION, latest + run: | + docker push ${{ secrets.DOCKER_USERNAME }}/${{ steps.vars.outputs.IMAGE_NAME }}:${{ steps.vars.outputs.RELEASE_VERSION }} + docker tag ${{ secrets.DOCKER_USERNAME }}/${{ steps.vars.outputs.IMAGE_NAME }}:${{ steps.vars.outputs.RELEASE_VERSION }} ${{ secrets.DOCKER_USERNAME }}/${{ steps.vars.outputs.IMAGE_NAME }}:latest + docker push ${{ secrets.DOCKER_USERNAME }}/${{ steps.vars.outputs.IMAGE_NAME }}:latest + + - name: Login to Registry - ghcr.io + run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + + - name: Push Image - ghcr.io + # push: RELEASE_VERSION, latest + run: | + IMAGE_ID=ghcr.io/${{ github.repository_owner }}/${{ steps.vars.outputs.IMAGE_NAME }} + VERSION=${{ steps.vars.outputs.RELEASE_VERSION }} + echo IMAGE_ID=$IMAGE_ID + echo VERSION=$VERSION + docker tag ${{ secrets.DOCKER_USERNAME }}/${{ steps.vars.outputs.IMAGE_NAME }}:latest $IMAGE_ID:$VERSION + docker push $IMAGE_ID:$VERSION + docker tag $IMAGE_ID:$VERSION $IMAGE_ID:latest + docker push $IMAGE_ID:latest diff --git a/.github/workflows/QQBotHub-release.yml b/.github/workflows/QQBotHub-release.yml new file mode 100644 index 000000000..90ba46901 --- /dev/null +++ b/.github/workflows/QQBotHub-release.yml @@ -0,0 +1,67 @@ +name: QQBotHub Release + +on: + push: + tags: + - 'QQBotHub-v*' + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - name: Checkout source + uses: actions/checkout@v2 + + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 6.0.100 + + - name: Build + run: | + cd ./src/QQBotHub.Web + # win-x64 + dotnet publish -c Release -r win-x64 -p:PublishSingleFile=true --output ../../win-x64 --self-contained true + # win-x86 + dotnet publish -c Release -r win-x86 -p:PublishSingleFile=true --output ../../win-x86 --self-contained true + # linux-x64 + dotnet publish -c Release -r linux-x64 -p:PublishSingleFile=true --output ../../linux-x64 --self-contained true + # linux-arm + dotnet publish -c Release -r linux-arm -p:PublishSingleFile=true --output ../../linux-arm --self-contained true + # linux-arm64 + dotnet publish -c Release -r linux-arm64 -p:PublishSingleFile=true --output ../../linux-arm64 --self-contained true + # osx-x64 + dotnet publish -c Release -r osx-x64 -p:PublishSingleFile=true --output ../../osx-x64 --self-contained true + # osx.10.10-x64 + dotnet publish -c Release -r osx.10.10-x64 -p:PublishSingleFile=true --output ../../osx.10.10-x64 --self-contained true + + - name: Zip the Build + run: | + zip -r QQBotHub-win-x64.zip ./win-x64/ + zip -r QQBotHub-win-x86.zip ./win-x86/ + zip -r QQBotHub-linux-x64.zip ./linux-x64/ + zip -r QQBotHub-linux-arm.zip ./linux-arm/ + zip -r QQBotHub-linux-arm64.zip ./linux-arm64/ + zip -r QQBotHub-osx-x64.zip ./osx-x64/ + zip -r QQBotHub-osx.10.10-x64.zip ./osx.10.10-x64/ + + - name: Create Release and Upload Release Asset + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + #tag_name: ${{ github.ref }} + #name: ${{ github.ref }} + body: TODO New Release. + #body_path: CHANGELOG.txt + draft: false + prerelease: false + files: | + QQBotHub-win-x64.zip + QQBotHub-win-x86.zip + QQBotHub-linux-x64.zip + QQBotHub-linux-arm.zip + QQBotHub-linux-arm64.zip + QQBotHub-osx-x64.zip + QQBotHub-osx.10.10-x64.zip \ No newline at end of file diff --git a/.github/workflows/QQHelloWorldPlugin-release.yml b/.github/workflows/QQHelloWorldPlugin-release.yml new file mode 100644 index 000000000..9a71cf421 --- /dev/null +++ b/.github/workflows/QQHelloWorldPlugin-release.yml @@ -0,0 +1,49 @@ +name: QQHelloWorldPlugin Release + +on: + push: + tags: + - 'QQHelloWorldPlugin-v*' + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - name: Checkout source + uses: actions/checkout@v2 + + - name: Setup .NET Core + uses: actions/setup-dotnet@v1 + with: + dotnet-version: 6.0.100 + + - name: Build + run: | + cd ./plugins/QQHelloWorldPlugin + dotnet build --configuration Release + ls + ls ./bin/Release/ + + - name: Zip the Build + run: | + cd ./plugins/QQHelloWorldPlugin/bin/Release + zip -r QQHelloWorldPlugin-net6.0.zip ./net6.0/ + cd ../../../../ + mv ./src/QQHelloWorldPlugin/bin/Release/*.zip ./ + + - name: Create Release and Upload Release Asset + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + #tag_name: ${{ github.ref }} + #name: ${{ github.ref }} + body: TODO New Release. + #body_path: CHANGELOG.txt + draft: false + prerelease: false + files: | + QQHelloWorldPlugin-net6.0.zip + LICENSE + README.md \ No newline at end of file diff --git a/.github/workflows/sync-gitee.yml b/.github/workflows/sync-gitee.yml new file mode 100644 index 000000000..95d362ce1 --- /dev/null +++ b/.github/workflows/sync-gitee.yml @@ -0,0 +1,20 @@ +name: Sync to Gitee + +on: + push: + branches: [main] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - name: Sync to Gitee + uses: wearerequired/git-mirror-action@master + env: + # 在 Settings->Secrets 配置 GITEE_SSH_PRIVATE_KEY + SSH_PRIVATE_KEY: ${{ secrets.GITEE_SSH_PRIVATE_KEY }} + with: + # GitHub 源仓库地址 + source-repo: git@github.com:yiyungent/QQBotHub.git + # Gitee 目标仓库地址 + destination-repo: git@gitee.com:yiyungent/QQBotHub.git diff --git a/app.json b/app.json new file mode 100644 index 000000000..df06f470d --- /dev/null +++ b/app.json @@ -0,0 +1,32 @@ +{ + "name": "QQBotHub", + "description": "QQ 机器人 | 基于 Konata.Core - Heroku Deploy", + "keywords": ["yiyungent", "QQBotHub"], + "website": "https://github.com/yiyungent/QQBotHub", + "repository": "https://github.com/yiyungent/QQBotHub", + "success_url": "/", + "env": { + "PLUGINCORE_ADMIN_USERNAME": { + "description": "PluginCore Admin 用户名", + "value": "admin", + "required": true + }, + "PLUGINCORE_ADMIN_PASSWORD": { + "description": "PluginCore Admin 密码", + "value": "ABC12345", + "required": true + }, + "BOT_QQ": { + "description": "机器人 QQ", + "value": "", + "required": true + }, + "BOT_PASSWORD": { + "description": "机器人 QQ 密码", + "value": "", + "required": true + } + }, + + "stack": "container" +} diff --git a/deploy/flyio/Dockerfile b/deploy/flyio/Dockerfile new file mode 100644 index 000000000..57c59af3c --- /dev/null +++ b/deploy/flyio/Dockerfile @@ -0,0 +1,9 @@ +# fly.io Dockerfile + +FROM yiyungent/dragonfly:v0.1.3 + +ADD flyio-entrypoint.sh ./flyio-entrypoint.sh +RUN chmod +x ./flyio-entrypoint.sh +ADD flyio-PluginCore.Config.json ./flyio-PluginCore.Config.json + +ENTRYPOINT ["/bin/sh", "./flyio-entrypoint.sh"] \ No newline at end of file diff --git a/deploy/flyio/flyio-PluginCore.Config.json b/deploy/flyio/flyio-PluginCore.Config.json new file mode 100644 index 000000000..3e23ce324 --- /dev/null +++ b/deploy/flyio/flyio-PluginCore.Config.json @@ -0,0 +1 @@ +{"Admin":{"UserName":"PLUGINCORE_ADMIN_USERNAME","Password":"PLUGINCORE_ADMIN_PASSWORD"},"FrontendMode":"LocalEmbedded","RemoteFrontend":"https://cdn.jsdelivr.net/gh/yiyungent/plugincore-admin-frontend@0.3.0/dist-cdn","PluginWidgetDebug":false} \ No newline at end of file diff --git a/deploy/flyio/flyio-entrypoint.sh b/deploy/flyio/flyio-entrypoint.sh new file mode 100644 index 000000000..046c28d00 --- /dev/null +++ b/deploy/flyio/flyio-entrypoint.sh @@ -0,0 +1,21 @@ +#!/bin/sh + +# region env +export ASPNETCORE_URLS="http://+:$PORT" +export ASPNETCORE_ENVIRONMENT="Production" +export TZ="Asia/Shanghai" +# endregion env + +# region PluginCore +echo ${PLUGINCORE_ADMIN_USERNAME} +echo ${PLUGINCORE_ADMIN_PASSWORD} + +mkdir App_Data + +touch /app/App_Data/PluginCore.Config.json + +cat '/app/heroku-PluginCore.Config.json' | sed "s/PLUGINCORE_ADMIN_USERNAME/${PLUGINCORE_ADMIN_USERNAME}/g" | tee '/app/App_Data/PluginCore.Config.json' +cat '/app/App_Data/PluginCore.Config.json' | sed "s/PLUGINCORE_ADMIN_PASSWORD/${PLUGINCORE_ADMIN_PASSWORD}/g" | tee '/app/App_Data/PluginCore.Config.json' +# endregion PluginCore + +dotnet WebApi.dll \ No newline at end of file diff --git a/deploy/heroku/Dockerfile b/deploy/heroku/Dockerfile new file mode 100644 index 000000000..906df0fda --- /dev/null +++ b/deploy/heroku/Dockerfile @@ -0,0 +1,13 @@ +# Heroku Dockerfile + +FROM yiyungent/qqbothub:v0.0.1 + +# 处于 /app 目录下 +ADD heroku-entrypoint.sh ./heroku-entrypoint.sh +RUN chmod +x ./heroku-entrypoint.sh +ADD heroku-PluginCore.Config.json ./heroku-PluginCore.Config.json + +RUN rm /app/settings.json +ADD settings.json ./settings.json + +ENTRYPOINT ["/bin/sh", "./heroku-entrypoint.sh"] \ No newline at end of file diff --git a/deploy/heroku/heroku-PluginCore.Config.json b/deploy/heroku/heroku-PluginCore.Config.json new file mode 100644 index 000000000..3e23ce324 --- /dev/null +++ b/deploy/heroku/heroku-PluginCore.Config.json @@ -0,0 +1 @@ +{"Admin":{"UserName":"PLUGINCORE_ADMIN_USERNAME","Password":"PLUGINCORE_ADMIN_PASSWORD"},"FrontendMode":"LocalEmbedded","RemoteFrontend":"https://cdn.jsdelivr.net/gh/yiyungent/plugincore-admin-frontend@0.3.0/dist-cdn","PluginWidgetDebug":false} \ No newline at end of file diff --git a/deploy/heroku/heroku-entrypoint.sh b/deploy/heroku/heroku-entrypoint.sh new file mode 100644 index 000000000..1281cb8bb --- /dev/null +++ b/deploy/heroku/heroku-entrypoint.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +# region env +export ASPNETCORE_URLS="http://+:$PORT" +export ASPNETCORE_ENVIRONMENT="Production" +export TZ="Asia/Shanghai" +# endregion env + +# region PluginCore +echo ${PLUGINCORE_ADMIN_USERNAME} +echo ${PLUGINCORE_ADMIN_PASSWORD} + +mkdir App_Data + +touch /app/App_Data/PluginCore.Config.json + +cat '/app/heroku-PluginCore.Config.json' | sed "s/PLUGINCORE_ADMIN_USERNAME/${PLUGINCORE_ADMIN_USERNAME}/g" | tee '/app/App_Data/PluginCore.Config.json' +cat '/app/App_Data/PluginCore.Config.json' | sed "s/PLUGINCORE_ADMIN_PASSWORD/${PLUGINCORE_ADMIN_PASSWORD}/g" | tee '/app/App_Data/PluginCore.Config.json' +# endregion PluginCore + +# region QQ Bot +echo ${BOT_QQ} +echo ${BOT_PASSWORD} + +cat '/app/settings.json' | sed "s/BOT_QQ/${BOT_QQ}/g" | tee '/app/settings.json' +cat '/app/settings.json' | sed "s/BOT_PASSWORD/${BOT_PASSWORD}/g" | tee '/app/settings.json' +# endregion QQ Bot + +dotnet WebApi.dll \ No newline at end of file diff --git a/deploy/heroku/settings.json b/deploy/heroku/settings.json new file mode 100644 index 000000000..9fea58ed4 --- /dev/null +++ b/deploy/heroku/settings.json @@ -0,0 +1,4 @@ +{ + "QQ": "BOT_QQ", + "Password": "BOT_PASSWORD" +} \ No newline at end of file diff --git a/deploy/railway/Dockerfile b/deploy/railway/Dockerfile new file mode 100644 index 000000000..ff5ef0f8e --- /dev/null +++ b/deploy/railway/Dockerfile @@ -0,0 +1,13 @@ +# Railway Dockerfile + +FROM yiyungent/qqbothub:v0.0.1 + +# 处于 /app 目录下 +ADD railway-entrypoint.sh ./railway-entrypoint.sh +RUN chmod +x ./railway-entrypoint.sh +ADD railway-PluginCore.Config.json ./railway-PluginCore.Config.json + +RUN rm /app/settings.json +ADD settings.json ./settings.json + +ENTRYPOINT ["/bin/sh", "./railway-entrypoint.sh"] \ No newline at end of file diff --git a/deploy/railway/railway-PluginCore.Config.json b/deploy/railway/railway-PluginCore.Config.json new file mode 100644 index 000000000..3e23ce324 --- /dev/null +++ b/deploy/railway/railway-PluginCore.Config.json @@ -0,0 +1 @@ +{"Admin":{"UserName":"PLUGINCORE_ADMIN_USERNAME","Password":"PLUGINCORE_ADMIN_PASSWORD"},"FrontendMode":"LocalEmbedded","RemoteFrontend":"https://cdn.jsdelivr.net/gh/yiyungent/plugincore-admin-frontend@0.3.0/dist-cdn","PluginWidgetDebug":false} \ No newline at end of file diff --git a/deploy/railway/railway-entrypoint.sh b/deploy/railway/railway-entrypoint.sh new file mode 100644 index 000000000..36fbfa185 --- /dev/null +++ b/deploy/railway/railway-entrypoint.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +# region env +export ASPNETCORE_URLS="http://+:$PORT" +export ASPNETCORE_ENVIRONMENT="Production" +export TZ="Asia/Shanghai" +# endregion env + +# region PluginCore +echo ${PLUGINCORE_ADMIN_USERNAME} +echo ${PLUGINCORE_ADMIN_PASSWORD} + +mkdir App_Data + +touch /app/App_Data/PluginCore.Config.json + +cat '/app/railway-PluginCore.Config.json' | sed "s/PLUGINCORE_ADMIN_USERNAME/${PLUGINCORE_ADMIN_USERNAME}/g" | tee '/app/App_Data/PluginCore.Config.json' +cat '/app/App_Data/PluginCore.Config.json' | sed "s/PLUGINCORE_ADMIN_PASSWORD/${PLUGINCORE_ADMIN_PASSWORD}/g" | tee '/app/App_Data/PluginCore.Config.json' +# endregion PluginCore + +# region QQ Bot +echo ${BOT_QQ} +echo ${BOT_PASSWORD} + +cat '/app/settings.json' | sed "s/BOT_QQ/${BOT_QQ}/g" | tee '/app/settings.json' +cat '/app/settings.json' | sed "s/BOT_PASSWORD/${BOT_PASSWORD}/g" | tee '/app/settings.json' +# endregion QQ Bot + +dotnet WebApi.dll \ No newline at end of file diff --git a/deploy/railway/settings.json b/deploy/railway/settings.json new file mode 100644 index 000000000..9fea58ed4 --- /dev/null +++ b/deploy/railway/settings.json @@ -0,0 +1,4 @@ +{ + "QQ": "BOT_QQ", + "Password": "BOT_PASSWORD" +} \ No newline at end of file diff --git a/heroku.yml b/heroku.yml new file mode 100644 index 000000000..e9d2ac033 --- /dev/null +++ b/heroku.yml @@ -0,0 +1,3 @@ +build: + docker: + web: deploy/heroku/Dockerfile \ No newline at end of file