From 719c0e5a42e0997993a1d1bcedb07a6bc0c5be2a Mon Sep 17 00:00:00 2001 From: asepharyana Date: Sat, 1 Aug 2026 16:58:21 +0700 Subject: [PATCH] =?UTF-8?q?ci:=20restore=20legacy=20.github=20workflows=20?= =?UTF-8?q?(era=20GitHub=20asli)=20=E2=80=94=20hapus=20hanya=20jika=20mema?= =?UTF-8?q?ng=20mirror-only?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build.yml | 57 ++++++++++++++++++++++++++++++ .github/workflows/cloudflare.yml | 33 ++++++++++++++++++ .github/workflows/deploy.yml | 59 ++++++++++++++++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/cloudflare.yml create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..cbd1958 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,57 @@ +name: Build and Push to GHCR + +on: + push: + branches: [master] + paths: + - 'src/**' + - 'Dockerfile' + - 'package.json' + - 'bun.lock*' + - '.github/workflows/**' + workflow_dispatch: + +env: + REGISTRY: ghcr.io + IMAGE_NAME: ghcr.io/mytheclipse/proxy-bun + +jobs: + build-and-push: + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Log in to Container Registry + uses: docker/login-action@v3 + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Extract metadata + id: meta + uses: docker/metadata-action@v5 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + tags: | + type=sha,prefix= + + - name: Build and push Docker image + uses: docker/build-push-action@v5 + with: + context: . + push: true + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + + - name: Trigger deployment + uses: peter-evans/repository-dispatch@v3 + with: + token: ${{ secrets.DEPLOY_TOKEN }} + event-type: deploy + client-payload: '{"image_tag": "${{ steps.meta.outputs.version }}"}' diff --git a/.github/workflows/cloudflare.yml b/.github/workflows/cloudflare.yml new file mode 100644 index 0000000..1a8540a --- /dev/null +++ b/.github/workflows/cloudflare.yml @@ -0,0 +1,33 @@ +name: Deploy to Cloudflare Workers + +on: + push: + branches: + - master + workflow_dispatch: + +jobs: + deploy: + name: Deploy to Cloudflare Workers + runs-on: ubuntu-latest + steps: + - name: Checkout Code + uses: actions/checkout@v4 + + - name: Setup Bun + uses: oven-sh/setup-bun@v2 + with: + bun-version: latest + + - name: Install Dependencies + run: bun install --frozen-lockfile + + - name: Run Tests + run: bun test + + - name: Deploy Worker + uses: cloudflare/wrangler-action@v3 + with: + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + command: deploy + wranglerVersion: "4.110.0" diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..914ba7c --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,59 @@ +name: Deploy to VPS + +on: + repository_dispatch: + types: [deploy] + workflow_dispatch: + +env: + VPS_HOST: 45.127.35.244 + VPS_USER: root + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Setup SSH + uses: webfactory/ssh-agent@v0.9.0 + with: + ssh-private-key: ${{ secrets.VPS_SSH_KEY }} + + - name: Add VPS to known_hosts + run: | + mkdir -p ~/.ssh + ssh-keyscan -H ${{ env.VPS_HOST }} >> ~/.ssh/known_hosts + + - name: Pull and restart container + run: | + ssh ${{ env.VPS_USER }}@${{ env.VPS_HOST }} << 'DEPLOY_EOF' + set -e + IMAGE_TAG="${{ github.event.client_payload.image_tag }}" + IMAGE="ghcr.io/mytheclipse/proxy-bun:${IMAGE_TAG}" + + echo "=== Logging in to GHCR ===" + echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin + + echo "=== Pulling image: ${IMAGE} ===" + docker pull "${IMAGE}" + + echo "=== Updating docker-compose.yml ===" + cd /opt/edge-proxy + sed -i "s|image:.*|image: ${IMAGE}|" docker-compose.yml + + echo "=== Stopping old container ===" + docker compose down || true + + echo "=== Starting new container ===" + docker compose up -d + + echo "=== Waiting for health check ===" + sleep 5 + curl -sf http://localhost:3000/health || echo "Health check failed" + + echo "=== Deployment complete ===" + DEPLOY_EOF + + - name: Verify deployment + run: | + sleep 10 + curl -sf https://proxy.asepharyana.my.id/health || echo "External health check failed"