From dc78df47bd71154c915af07c938becd4ac64f14d Mon Sep 17 00:00:00 2001 From: Methapon2001 <61303214+Methapon2001@users.noreply.github.com> Date: Tue, 25 Feb 2025 14:06:50 +0700 Subject: [PATCH] refactor: workflow --- .github/workflows/gitea-local.yaml | 89 ++++++++++++++++++++++ .github/workflows/local-build-release.yaml | 31 -------- .github/workflows/local-release-demo.yml | 22 ------ .github/workflows/local-release-dev.yml | 22 ------ 4 files changed, 89 insertions(+), 75 deletions(-) create mode 100644 .github/workflows/gitea-local.yaml delete mode 100644 .github/workflows/local-build-release.yaml delete mode 100644 .github/workflows/local-release-demo.yml delete mode 100644 .github/workflows/local-release-dev.yml diff --git a/.github/workflows/gitea-local.yaml b/.github/workflows/gitea-local.yaml new file mode 100644 index 00000000..6b2afdbe --- /dev/null +++ b/.github/workflows/gitea-local.yaml @@ -0,0 +1,89 @@ +name: Gitea Action + +run-name: Build ${{ github.actor }} + +# Intended for local gitea instance only. + +on: + workflow_dispatch: + +env: + REGISTRY: ${{ vars.CONTAINER_REGISTRY }} + REGISTRY_USERNAME: ${{ vars.CONTAINER_REGISTRY_USERNAME }} + REGISTRY_PASSWORD: ${{ secrets.CONTAINER_REGISTRY_PASSWORD }} + CONTAINER_IMAGE_NAME: ${{ vars.CONTAINER_REGISTRY }}/${{ vars.CONTAINER_IMAGE_OWNER }}/${{ vars.CONTAINER_IMAGE_NAME }}:latest +jobs: + gitea-release: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + - name: Login to Docker Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ env.REGISTRY_USERNAME }} + password: ${{ env.REGISTRY_PASSWORD }} + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v2 + with: + config-inline: | + [registry."${{ env.REGISTRY }}"] + ca=["/etc/ssl/certs/ca-certificates.crt"] + - name: Build and Push Docker Image + uses: docker/build-push-action@v3 + with: + context: . + platforms: linux/amd64 + tags: ${{ env.CONTAINER_IMAGE_NAME }} + push: true + - name: Remote Deploy Development + uses: appleboy/ssh-action@v1.2.1 + with: + host: ${{ vars.SSH_DEVELOPMENT_HOST }} + port: ${{ vars.SSH_DEVELOPMENT_PORT }} + username: ${{ secrets.SSH_DEVELOPMENT_USER }} + password: ${{ secrets.SSH_DEVELOPMENT_PASSWORD }} + script: eval "${{ secrets.SSH_DEVELOPMENT_DEPLOY_CMD }}" & wait + - name: Remote Deploy Test + uses: appleboy/ssh-action@v1.2.1 + with: + host: ${{ vars.SSH_TEST_HOST }} + port: ${{ vars.SSH_TEST_PORT }} + username: ${{ secrets.SSH_TEST_USER }} + password: ${{ secrets.SSH_TEST_PASSWORD }} + script: eval "${{ secrets.SSH_TEST_DEPLOY_CMD }}" & wait + - name: Notify Discord Success + if: success() + run: | + curl -H "Content-Type: application/json" -X POST \ + -d '{ + "embeds": [{ + "title": "✅ Gitea Local Deployment Success!", + "description": "**Details:**\n- Image: `${{ env.CONTAINER_IMAGE_NAME }}`\n- Deployed by: `${{ github.actor }}`", + "color": 3066993, + "footer": { + "text": "Gitea Local Release Notification", + "icon_url": "https://example.com/success-icon.png" + }, + "timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'" + }] + }' \ + ${{ secrets.DISCORD_WEBHOOK }} + - name: Notify Discord Failure + if: failure() + run: | + curl -H "Content-Type: application/json" -X POST \ + -d '{ + "embeds": [{ + "title": "❌ Gitea Local Deployment Failed!", + "description": "**Details:**\n- Image: `${{ env.CONTAINER_IMAGE_NAME }}`\n- Attempted by: `${{ github.actor }}`", + "color": 15158332, + "footer": { + "text": "Gitea Local Release Notification", + "icon_url": "https://example.com/failure-icon.png" + }, + "timestamp": "'$(date -u +%Y-%m-%dT%H:%M:%SZ)'" + }] + }' \ + ${{ secrets.DISCORD_WEBHOOK }} diff --git a/.github/workflows/local-build-release.yaml b/.github/workflows/local-build-release.yaml deleted file mode 100644 index a14cbadf..00000000 --- a/.github/workflows/local-build-release.yaml +++ /dev/null @@ -1,31 +0,0 @@ -name: local-build-release - -# Intended for local network use. -# Remote access is possible if the host has a public IP address. - -on: - workflow_dispatch: - -env: - REGISTRY: ${{ vars.DOCKER_REGISTRY }} - -jobs: - local-build-release: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Setup Docker Buildx - uses: docker/setup-buildx-action@v2 - with: - config-inline: | - [registry."${{ env.REGISTRY }}"] - http = true - insecure = true - - name: Build and Push Docker Image - uses: docker/build-push-action@v3 - with: - context: . - platforms: linux/amd64 - push: true - tags: ${{ env.REGISTRY }}/jws/jws-frontend:latest - allow: security.insecure diff --git a/.github/workflows/local-release-demo.yml b/.github/workflows/local-release-demo.yml deleted file mode 100644 index 3d373a80..00000000 --- a/.github/workflows/local-release-demo.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: local-release-demo - -# Intended for local network use. -# Remote access is possible if the host has a public IP address. - -on: - workflow_dispatch: - -jobs: - local-release-demo: - runs-on: ubuntu-latest - steps: - - name: Remote deploy internal chamomind server - uses: appleboy/ssh-action@v1.0.3 - with: - host: ${{ secrets.HOST }} - username: ${{ secrets.USERNAME }} - password: ${{ secrets.PASSWORD }} - script: | - cd ~/repositories/jws-frontend - git pull - docker compose up -d --build diff --git a/.github/workflows/local-release-dev.yml b/.github/workflows/local-release-dev.yml deleted file mode 100644 index 5bc0101e..00000000 --- a/.github/workflows/local-release-dev.yml +++ /dev/null @@ -1,22 +0,0 @@ -name: local-release-dev - -# Intended for local network use. -# Remote access is possible if the host has a public IP address. - -on: - workflow_dispatch: - -jobs: - local-release-dev: - runs-on: ubuntu-latest - steps: - - name: Remote deploy internal chamomind server - uses: appleboy/ssh-action@v1.0.3 - with: - host: ${{ secrets.HOST }} - username: ${{ secrets.USERNAME }} - password: ${{ secrets.PASSWORD }} - script: | - cd ~/repositories/jws-frontend - git pull - docker compose up -d --build