diff --git a/.github/workflows/github-bot.yml b/.github/workflows/github-bot.yml new file mode 100644 index 000000000..297cac5c5 --- /dev/null +++ b/.github/workflows/github-bot.yml @@ -0,0 +1,57 @@ +name: GitHub Bot CI/CD + +on: + push: + branches: + - "release/*" + paths: + - "github-bot/**" + workflow_dispatch: + +jobs: + docker-push: + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./github-bot + steps: + - name: Checkout + uses: actions/checkout@v2 + + - name: Docker Hub login + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_TOKEN }} + + - name: Version tag + run: 'echo "VERSION_TAG=$(cat package.json | grep version | head -1 | awk -F: ''{ print $2 }'' | sed ''s/[", ]//g'')" >> $GITHUB_ENV' + + - 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: + context: ./ + file: ./Dockerfile + push: true + tags: ${{ secrets.DOCKER_USERNAME }}/tachi-gh-bot:stable,${{ secrets.DOCKER_USERNAME }}/tachi-bot:${{ env.VERSION_TAG }}, + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }} + deploy: + runs-on: ubuntu-latest + defaults: + run: + working-directory: ./github-bot + needs: [docker-push] + steps: + - name: Deploy + uses: appleboy/ssh-action@1a8b3784eaa665f677fa114edd5683bb6a6bfaa8 + with: + host: ${{ secrets.TACHI_HOST }} + username: tachi + key: ${{ secrets.TACHI_KEY }} + script: tachi-github-bot-deploy diff --git a/github-bot/Dockerfile b/github-bot/Dockerfile new file mode 100644 index 000000000..a3baa08f2 --- /dev/null +++ b/github-bot/Dockerfile @@ -0,0 +1,9 @@ +FROM node:16 as build +WORKDIR /app +COPY --chown=node:node . /app +RUN npm install --silent -g pnpm@6 && groupmod -g 1003 node && chown node:node /app +USER node +RUN pnpm install --silent && pnpm build && pnpm prune --silent --production && pnpm store prune --silent +HEALTHCHECK --interval=15s --timeout=5s CMD curl -f http://localhost:8080 || exit 1 +ENV NODE_PATH=js/ +CMD ["node", "js/main.js"]