> For the complete documentation index, see [llms.txt](https://payana-saas.gitbook.io/payana-saas-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://payana-saas.gitbook.io/payana-saas-docs/deployment/backend-dan-indexer.md).

# Deploy Backend & Indexer (Azure)

Keduanya dideploy dengan pola yang sama: build image Docker, push ke registry, Azure App Service (Container) menariknya. Indexer dideploy duluan karena backend membaca tabelnya langsung.

## Konsep dasar (kalau baru pertama pakai Azure)

| Istilah                | Artinya                                                                                                                     |
| ---------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| **Resource Group**     | Folder yang menampung semua resource Azure-mu                                                                               |
| **App Service**        | Aplikasi yang benar-benar berjalan — bisa mode Container atau Code                                                          |
| **App Service Plan**   | "Ukuran server" App Service-mu berjalan di atasnya                                                                          |
| **Container Registry** | Tempat image Docker disimpan — di sini memakai **GHCR** (GitHub Container Registry), gratis dan terintegrasi GitHub Actions |
| **App Settings**       | Nama Azure untuk environment variable                                                                                       |

## Persiapan

```bash
winget install -e --id Microsoft.AzureCLI
az login
az group list -o table
az webapp list -o table
```

Catat nama resource group dan nama App Service untuk backend & indexer.

## Port

Azure App Service for Containers berasumsi port 80 kecuali diberi tahu sebaliknya. Set `WEBSITES_PORT` sesuai port asli masing-masing container:

| Layanan          | Port    |
| ---------------- | ------- |
| `payana-indexer` | `42069` |
| `payana-backend` | `3001`  |

```bash
az webapp config appsettings set --name <nama-app> --resource-group <resource-group> --settings WEBSITES_PORT=42069
```

## Workflow GitHub Actions

Aktifkan dulu di masing-masing repo: **Settings → Actions → General → Workflow permissions → "Read and write permissions"** (supaya token bawaan bisa push ke GHCR tanpa secret tambahan).

```yaml
# .github/workflows/azure-deploy.yml (pola yang sama untuk indexer & backend)
name: Deploy to Azure

on:
  push:
    branches: [main]
  workflow_dispatch:

permissions:
  contents: read
  packages: write

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Log in to GHCR
        uses: docker/login-action@v3
        with:
          registry: ghcr.io
          username: ${{ github.actor }}
          password: ${{ secrets.GITHUB_TOKEN }}

      - name: Build and push image
        uses: docker/build-push-action@v6
        with:
          context: .
          push: true
          tags: |
            ghcr.io/${{ github.repository_owner }}/<nama-image>:latest
            ghcr.io/${{ github.repository_owner }}/<nama-image>:${{ github.sha }}

      - name: Deploy to Azure App Service
        uses: azure/webapps-deploy@v3
        with:
          app-name: <nama-app-azure>
          publish-profile: ${{ secrets.AZURE_PUBLISH_PROFILE }}
          images: ghcr.io/${{ github.repository_owner }}/<nama-image>:${{ github.sha }}
```

Publish profile diambil dari **Portal → App Service → Overview → Download publish profile**, disimpan sebagai secret repo (`AZURE_PONDER_PUBLISH_PROFILE` / `AZURE_BACKEND_PUBLISH_PROFILE`).

Tag ganda (`latest` + commit SHA) penting untuk rollback — lihat [FAQ & Troubleshooting](/payana-saas-docs/lainnya/faq.md).

## App Settings

Isi dari daftar lengkap di [Variabel Lingkungan](/payana-saas-docs/dokumentasi-teknis/variabel-lingkungan.md), lewat Portal (**Configuration → Application settings**) atau CLI:

```bash
az webapp config appsettings set --name <nama-app> --resource-group <resource-group> --settings \
  KEY1="value1" KEY2="value2"
```

## Always On (khusus backend)

Backend menjalankan cron (`paymasterMonitor`, `anomalyDetector`) lewat `node-cron` — kalau App Service idle, jadwal ini berhenti. Aktifkan **Configuration → General settings → Always On** (butuh tier Basic/B1 ke atas, tidak tersedia di Free/F1).

## Firewall database

Pastikan Azure PostgreSQL Flexible Server punya rule **"Allow public access from any Azure service"** aktif — tanpa ini, App Service tidak bisa konek ke database sama sekali (beda dari rule allowlist IP yang dipakai untuk akses dari laptop pribadi).

Lanjut ke [Deploy Frontend](/payana-saas-docs/deployment/frontend.md).


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://payana-saas.gitbook.io/payana-saas-docs/deployment/backend-dan-indexer.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
