From 54c9cdeed873d2179073bbb8c8aea91dc8418612 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Fri, 10 May 2024 19:11:59 +0530 Subject: [PATCH 1/3] [web] Switch to (almost) continuous deployments Every day except Sunday, at 8:00 am, the code on main will be automatically deployed to production for all web apps (photos, auth, cast, accounts, payments) --- .github/workflows/auth-lint.yml | 2 +- .github/workflows/desktop-lint.yml | 2 +- .github/workflows/docs-verify-build.yml | 2 +- .github/workflows/mobile-lint.yml | 2 +- .github/workflows/server-lint.yml | 2 +- .github/workflows/web-deploy-accounts.yml | 43 ------- .github/workflows/web-deploy-auth.yml | 43 ------- .github/workflows/web-deploy-cast.yml | 43 ------- ...b-deploy-photos.yml => web-deploy-one.yml} | 28 +++-- .github/workflows/web-deploy-payments.yml | 43 ------- ...web-preview.yml => web-deploy-preview.yml} | 2 +- ...web-nightly.yml => web-deploy-staging.yml} | 44 +++---- .github/workflows/web-deploy.yml | 109 ++++++++++++++++++ .github/workflows/web-lint.yml | 2 +- 14 files changed, 154 insertions(+), 213 deletions(-) delete mode 100644 .github/workflows/web-deploy-accounts.yml delete mode 100644 .github/workflows/web-deploy-auth.yml delete mode 100644 .github/workflows/web-deploy-cast.yml rename .github/workflows/{web-deploy-photos.yml => web-deploy-one.yml} (59%) delete mode 100644 .github/workflows/web-deploy-payments.yml rename .github/workflows/{web-preview.yml => web-deploy-preview.yml} (98%) rename .github/workflows/{web-nightly.yml => web-deploy-staging.yml} (86%) create mode 100644 .github/workflows/web-deploy.yml diff --git a/.github/workflows/auth-lint.yml b/.github/workflows/auth-lint.yml index 63d644c2e3..e7c42e1a6b 100644 --- a/.github/workflows/auth-lint.yml +++ b/.github/workflows/auth-lint.yml @@ -3,7 +3,7 @@ name: "Lint (auth)" on: # Run on every push to a branch other than main that changes auth/ push: - branches-ignore: [main, "deploy/**", "deploy-f/**"] + branches-ignore: [main] paths: - "auth/**" - ".github/workflows/auth-lint.yml" diff --git a/.github/workflows/desktop-lint.yml b/.github/workflows/desktop-lint.yml index 0c1929e6ac..d1cfda884d 100644 --- a/.github/workflows/desktop-lint.yml +++ b/.github/workflows/desktop-lint.yml @@ -3,7 +3,7 @@ name: "Lint (desktop)" on: # Run on every push to a branch other than main that changes desktop/ push: - branches-ignore: [main, "deploy/**", "deploy-f/**"] + branches-ignore: [main] paths: - "desktop/**" - ".github/workflows/desktop-lint.yml" diff --git a/.github/workflows/docs-verify-build.yml b/.github/workflows/docs-verify-build.yml index 5d31ff8378..addb52a059 100644 --- a/.github/workflows/docs-verify-build.yml +++ b/.github/workflows/docs-verify-build.yml @@ -6,7 +6,7 @@ name: "Verify build (docs)" on: # Run on every push to a branch other than main that changes docs/ push: - branches-ignore: [main, "deploy/**", "deploy-f/**"] + branches-ignore: [main] paths: - "docs/**" - ".github/workflows/docs-verify-build.yml" diff --git a/.github/workflows/mobile-lint.yml b/.github/workflows/mobile-lint.yml index 8abc6f0c73..493185b6bd 100644 --- a/.github/workflows/mobile-lint.yml +++ b/.github/workflows/mobile-lint.yml @@ -3,7 +3,7 @@ name: "Lint (mobile)" on: # Run on every push to a branch other than main that changes mobile/ push: - branches-ignore: [main, f-droid, "deploy/**", "deploy-f/**"] + branches-ignore: [main, f-droid] paths: - "mobile/**" - ".github/workflows/mobile-lint.yml" diff --git a/.github/workflows/server-lint.yml b/.github/workflows/server-lint.yml index 30038b3b9f..c051d02901 100644 --- a/.github/workflows/server-lint.yml +++ b/.github/workflows/server-lint.yml @@ -3,7 +3,7 @@ name: "Lint (server)" on: # Run on every push to a branch other than main that changes server/ push: - branches-ignore: [main, "deploy/**", "deploy-f/**"] + branches-ignore: [main] paths: - "server/**" - ".github/workflows/server-lint.yml" diff --git a/.github/workflows/web-deploy-accounts.yml b/.github/workflows/web-deploy-accounts.yml deleted file mode 100644 index 33da5ee6f1..0000000000 --- a/.github/workflows/web-deploy-accounts.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: "Deploy (accounts)" - -on: - push: - # Run workflow on pushes to the deploy/accounts - branches: [deploy/accounts, deploy-f/accounts] - -jobs: - deploy: - runs-on: ubuntu-latest - - defaults: - run: - working-directory: web - - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - submodules: recursive - - - name: Setup node and enable yarn caching - uses: actions/setup-node@v4 - with: - node-version: 20 - cache: "yarn" - cache-dependency-path: "web/yarn.lock" - - - name: Install dependencies - run: yarn install - - - name: Build accounts - run: yarn build:accounts - - - name: Publish accounts - uses: cloudflare/pages-action@1 - with: - accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} - projectName: ente - branch: deploy/accounts - directory: web/apps/accounts/out - wranglerVersion: "3" diff --git a/.github/workflows/web-deploy-auth.yml b/.github/workflows/web-deploy-auth.yml deleted file mode 100644 index d195b62f8c..0000000000 --- a/.github/workflows/web-deploy-auth.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: "Deploy (auth)" - -on: - push: - # Run workflow on pushes to the deploy/auth - branches: [deploy/auth] - -jobs: - deploy: - runs-on: ubuntu-latest - - defaults: - run: - working-directory: web - - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - submodules: recursive - - - name: Setup node and enable yarn caching - uses: actions/setup-node@v4 - with: - node-version: 20 - cache: "yarn" - cache-dependency-path: "web/yarn.lock" - - - name: Install dependencies - run: yarn install - - - name: Build auth - run: yarn build:auth - - - name: Publish auth - uses: cloudflare/pages-action@1 - with: - accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} - projectName: ente - branch: deploy/auth - directory: web/apps/auth/out - wranglerVersion: "3" diff --git a/.github/workflows/web-deploy-cast.yml b/.github/workflows/web-deploy-cast.yml deleted file mode 100644 index 01e17486d0..0000000000 --- a/.github/workflows/web-deploy-cast.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: "Deploy (cast)" - -on: - push: - # Run workflow on pushes to the deploy/cast - branches: [deploy/cast, deploy-f/cast] - -jobs: - deploy: - runs-on: ubuntu-latest - - defaults: - run: - working-directory: web - - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - submodules: recursive - - - name: Setup node and enable yarn caching - uses: actions/setup-node@v4 - with: - node-version: 20 - cache: "yarn" - cache-dependency-path: "web/yarn.lock" - - - name: Install dependencies - run: yarn install - - - name: Build cast - run: yarn build:cast - - - name: Publish cast - uses: cloudflare/pages-action@1 - with: - accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} - projectName: ente - branch: deploy/cast - directory: web/apps/cast/out - wranglerVersion: "3" diff --git a/.github/workflows/web-deploy-photos.yml b/.github/workflows/web-deploy-one.yml similarity index 59% rename from .github/workflows/web-deploy-photos.yml rename to .github/workflows/web-deploy-one.yml index cb3a9db86d..bdf1773aec 100644 --- a/.github/workflows/web-deploy-photos.yml +++ b/.github/workflows/web-deploy-one.yml @@ -1,9 +1,19 @@ -name: "Deploy (photos)" +name: "Deploy one (web)" on: - push: - # Run workflow on pushes to the deploy/photos - branches: [deploy/photos] + workflow_dispatch: + inputs: + app: + description: "App to build and deploy" + type: choice + required: true + default: "photos" + options: + - "accounts" + - "auth" + - "cast" + - "payments" + - "photos" jobs: deploy: @@ -29,15 +39,15 @@ jobs: - name: Install dependencies run: yarn install - - name: Build photos - run: yarn build:photos + - name: Build ${{ inputs.app }} + run: yarn build:${{ inputs.app }} - - name: Publish photos + - name: Publish ${{ inputs.app }} to preview uses: cloudflare/pages-action@1 with: accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} projectName: ente - branch: deploy/photos - directory: web/apps/photos/out + branch: deploy/${{ inputs.app }} + directory: web/apps/${{ inputs.app }}/out wranglerVersion: "3" diff --git a/.github/workflows/web-deploy-payments.yml b/.github/workflows/web-deploy-payments.yml deleted file mode 100644 index 367e1db186..0000000000 --- a/.github/workflows/web-deploy-payments.yml +++ /dev/null @@ -1,43 +0,0 @@ -name: "Deploy (payments)" - -on: - push: - # Run workflow on pushes to the deploy/payments - branches: [deploy/payments] - -jobs: - deploy: - runs-on: ubuntu-latest - - defaults: - run: - working-directory: web - - steps: - - name: Checkout code - uses: actions/checkout@v4 - with: - submodules: recursive - - - name: Setup node and enable yarn caching - uses: actions/setup-node@v4 - with: - node-version: 20 - cache: "yarn" - cache-dependency-path: "web/yarn.lock" - - - name: Install dependencies - run: yarn install - - - name: Build payments - run: yarn build:payments - - - name: Publish payments - uses: cloudflare/pages-action@1 - with: - accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} - projectName: ente - branch: deploy/payments - directory: web/apps/payments/dist - wranglerVersion: "3" diff --git a/.github/workflows/web-preview.yml b/.github/workflows/web-deploy-preview.yml similarity index 98% rename from .github/workflows/web-preview.yml rename to .github/workflows/web-deploy-preview.yml index 8f39c02474..4cf5986de7 100644 --- a/.github/workflows/web-preview.yml +++ b/.github/workflows/web-deploy-preview.yml @@ -1,4 +1,4 @@ -name: "Preview (web)" +name: "Deploy preview (web)" on: workflow_dispatch: diff --git a/.github/workflows/web-nightly.yml b/.github/workflows/web-deploy-staging.yml similarity index 86% rename from .github/workflows/web-nightly.yml rename to .github/workflows/web-deploy-staging.yml index 9497382924..93469a65d0 100644 --- a/.github/workflows/web-nightly.yml +++ b/.github/workflows/web-deploy-staging.yml @@ -1,17 +1,11 @@ -name: "Nightly (web)" +name: "Deploy staging (web)" on: schedule: - # [Note: Run workflow every 24 hours] + # Run everyday at ~3:00 PM IST # - # Run every 24 hours - First field is minute, second is hour of the day - # This runs 23:15 UTC everyday - 1 and 15 are just arbitrary offset to - # avoid scheduling it on the exact hour, as suggested by GitHub. - # - # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule - # https://crontab.guru/ - # - - cron: "15 23 * * *" + # See: [Note: Run workflow every 24 hours] + - cron: "25 9 * * *" # Also allow manually running the workflow workflow_dispatch: @@ -39,6 +33,21 @@ jobs: - name: Install dependencies run: yarn install + - name: Build photos + run: yarn build:photos + env: + NEXT_PUBLIC_ENTE_ALBUMS_ENDPOINT: https://albums.ente.sh + + - name: Publish photos + uses: cloudflare/pages-action@1 + with: + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + projectName: ente + branch: n-photos + directory: web/apps/photos/out + wranglerVersion: "3" + - name: Build accounts run: yarn build:accounts @@ -90,18 +99,3 @@ jobs: branch: n-payments directory: web/apps/payments/dist wranglerVersion: "3" - - - name: Build photos - run: yarn build:photos - env: - NEXT_PUBLIC_ENTE_ALBUMS_ENDPOINT: https://albums.ente.sh - - - name: Publish photos - uses: cloudflare/pages-action@1 - with: - accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} - apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} - projectName: ente - branch: n-photos - directory: web/apps/photos/out - wranglerVersion: "3" diff --git a/.github/workflows/web-deploy.yml b/.github/workflows/web-deploy.yml new file mode 100644 index 0000000000..7f3ea8fe34 --- /dev/null +++ b/.github/workflows/web-deploy.yml @@ -0,0 +1,109 @@ +name: "Deploy (photos)" + +on: + schedule: + # [Note: Run workflow every 24 hours] + # + # Run everyday at ~8:00 AM IST (except Sundays). + # + # First field is minute, second is hour of the day. Last is day of week, + # 0 being Sunday. + # + # Add a few minutes of offset to avoid scheduling on exact hourly + # boundaries (recommended by GitHub to avoid congestion). + # + # https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#schedule + # https://crontab.guru/ + # + - cron: "25 2 * * 1-6" + # Also allow manually running the workflow + workflow_dispatch: + +jobs: + deploy: + runs-on: ubuntu-latest + + defaults: + run: + working-directory: web + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + submodules: recursive + + - name: Setup node and enable yarn caching + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: "yarn" + cache-dependency-path: "web/yarn.lock" + + - name: Install dependencies + run: yarn install + + - name: Build photos + run: yarn build:photos + + - name: Publish photos + uses: cloudflare/pages-action@1 + with: + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + projectName: ente + branch: deploy/photos + directory: web/apps/photos/out + wranglerVersion: "3" + + - name: Build accounts + run: yarn build:accounts + + - name: Publish accounts + uses: cloudflare/pages-action@1 + with: + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + projectName: ente + branch: deploy/accounts + directory: web/apps/accounts/out + wranglerVersion: "3" + + - name: Build auth + run: yarn build:auth + + - name: Publish auth + uses: cloudflare/pages-action@1 + with: + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + projectName: ente + branch: deploy/auth + directory: web/apps/auth/out + wranglerVersion: "3" + + - name: Build cast + run: yarn build:cast + + - name: Publish cast + uses: cloudflare/pages-action@1 + with: + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + projectName: ente + branch: deploy/cast + directory: web/apps/cast/out + wranglerVersion: "3" + + - name: Build payments + run: yarn build:payments + + - name: Publish payments + uses: cloudflare/pages-action@1 + with: + accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} + apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} + projectName: ente + branch: deploy/payments + directory: web/apps/payments/dist + wranglerVersion: "3" diff --git a/.github/workflows/web-lint.yml b/.github/workflows/web-lint.yml index baf2a98ab0..7f5d270029 100644 --- a/.github/workflows/web-lint.yml +++ b/.github/workflows/web-lint.yml @@ -3,7 +3,7 @@ name: "Lint (web)" on: # Run on every push to a branch other than main that changes web/ push: - branches-ignore: [main, "deploy/**", "deploy-f/**"] + branches-ignore: [main] paths: - "web/**" - ".github/workflows/web-lint.yml" From 10fba07e25143917de40abab79b41351aa581c7d Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Fri, 10 May 2024 20:03:00 +0530 Subject: [PATCH 2/3] Docs --- web/docs/deploy.md | 68 ++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 36 deletions(-) diff --git a/web/docs/deploy.md b/web/docs/deploy.md index 6358cb87f2..75c3106d18 100644 --- a/web/docs/deploy.md +++ b/web/docs/deploy.md @@ -1,50 +1,46 @@ # Deploying The various web apps and static sites in this repository are deployed on -Cloudflare Pages. +Cloudflare Pages using GitHub workflows. -- Production deployments are triggered by pushing to the `deploy/*` branches. +- Automated production deployments of `main` daily 8:00 AM IST. + +- Automated staging deployments `*.ente.sh` of `main` daily 3:00 PM IST. - [help.ente.io](https://help.ente.io) gets deployed whenever a PR that changes anything inside `docs/` gets merged to `main`. -- Every night, all the web apps get automatically deployed to a nightly - preview URLs (`*.ente.sh`) using the current code in main. - -- A preview deployment can be made by triggering the "Preview (web)" workflow. - This allows us to deploy a build of any of the apps from an arbitrary branch - to [preview.ente.sh](https://preview.ente.sh). - -Use the various `yarn deploy:*` commands to help with production deployments. -For example, `yarn deploy:photos` will open a PR to merge the current `main` -onto `deploy/photos`, which'll trigger the deployment workflow, which'll build -and publish to [web.ente.io](https://web.ente.io). +- Production or staging deployments can made manually by triggering the + corresponding workflow. There is variant to deploy a single app to + production using the `web-deploy-one.yml` workflow, and a variant to deploy + any one of the apps to `preview.ente.sh` (see below). -> When merging these deployment PRs, remember to use rebase and merge so that -> their HEAD is a fast forward of `main` instead of diverging from it because of -> the merge commit. +These GitHub workflows use the various `yarn deploy:*` commands. For example, +`yarn deploy:photos` will open a PR to merge the current `main` onto +`deploy/photos`, which'll trigger the deployment workflow, which'll build and +publish to [web.ente.io](https://web.ente.io). ## Deployments Here is a list of all the deployments, whether or not they are production deployments, and the action that triggers them: -| URL | Type | Deployment action | -| -------------------------------------------- | ---------- | -------------------------------------------- | -| [web.ente.io](https://web.ente.io) | Production | Push to `deploy/photos` | -| [photos.ente.io](https://photos.ente.io) | Production | Alias of [web.ente.io](https://web.ente.io) | -| [auth.ente.io](https://auth.ente.io) | Production | Push to `deploy/auth` | -| [accounts.ente.io](https://accounts.ente.io) | Production | Push to `deploy/accounts` | -| [cast.ente.io](https://cast.ente.io) | Production | Push to `deploy/cast` | -| [payments.ente.io](https://payments.ente.io) | Production | Push to `deploy/payments` | -| [help.ente.io](https://help.ente.io) | Production | Push to `main` + changes in `docs/` | -| [staff.ente.sh](https://staff.ente.sh) | Production | Push to `main` + changes in `web/apps/staff` | -| [accounts.ente.sh](https://accounts.ente.sh) | Preview | Nightly deploy of `main` | -| [auth.ente.sh](https://auth.ente.sh) | Preview | Nightly deploy of `main` | -| [cast.ente.sh](https://cast.ente.sh) | Preview | Nightly deploy of `main` | -| [payments.ente.sh](https://payments.ente.sh) | Preview | Nightly deploy of `main` | -| [photos.ente.sh](https://photos.ente.sh) | Preview | Nightly deploy of `main` | -| [preview.ente.sh](https://preview.ente.sh) | Preview | Manually triggered | +| URL | Type | Deployment action | +| -------------------------------------------- | ---------- | --------------------------------------------- | +| [web.ente.io](https://web.ente.io) | Production | Daily deploy of `main` | +| [photos.ente.io](https://photos.ente.io) | Production | Alias of [web.ente.io](https://web.ente.io) | +| [auth.ente.io](https://auth.ente.io) | Production | Daily deploy of `main` | +| [accounts.ente.io](https://accounts.ente.io) | Production | Daily deploy of `main` | +| [cast.ente.io](https://cast.ente.io) | Production | Daily deploy of `main` | +| [payments.ente.io](https://payments.ente.io) | Production | Daily deploy of `main` | +| [help.ente.io](https://help.ente.io) | Production | Changes in `docs/` on push to `main` | +| [staff.ente.sh](https://staff.ente.sh) | Production | Changes in `web/apps/staff` on push to `main` | +| [accounts.ente.sh](https://accounts.ente.sh) | Preview | Daily deploy of `main` | +| [auth.ente.sh](https://auth.ente.sh) | Preview | Daily deploy of `main` | +| [cast.ente.sh](https://cast.ente.sh) | Preview | Daily deploy of `main` | +| [payments.ente.sh](https://payments.ente.sh) | Preview | Daily deploy of `main` | +| [photos.ente.sh](https://photos.ente.sh) | Preview | Daily deploy of `main` | +| [preview.ente.sh](https://preview.ente.sh) | Preview | Manually triggered | ### Other subdomains @@ -60,10 +56,10 @@ Apart from this, there are also some other deployments: ### Preview deployments -To trigger a preview deployment, manually trigger the "Preview (web)" workflow -from the Actions tab on GitHub. You'll need to select the app to build, and the -branch to use. This'll then build the specified app (e.g. "photos") from that -branch, and deploy it to [preview.ente.sh](https://preview.ente.sh). +To trigger a preview deployment, manually trigger the "Deploy preview (web)" +workflow from the Actions tab on GitHub. You'll need to select the app to build, +and the branch to use. This'll then build the specified app (e.g. "photos") from +that branch, and deploy it to [preview.ente.sh](https://preview.ente.sh). The workflow can also be triggered using GitHub's CLI, gh. e.g. From 938cecf2d3e6632a910ef1dbe7f3a287dca41a38 Mon Sep 17 00:00:00 2001 From: Manav Rathi Date: Fri, 10 May 2024 20:11:12 +0530 Subject: [PATCH 3/3] Move from deprecated action Test with first one, will move the rest subsequently Ref: - https://github.com/cloudflare/pages-action/issues/117#issuecomment-2053610761 - https://github.com/cloudflare/wrangler-action --- .github/workflows/docs-deploy.yml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/docs-deploy.yml b/.github/workflows/docs-deploy.yml index 01b0c2254a..df898727d2 100644 --- a/.github/workflows/docs-deploy.yml +++ b/.github/workflows/docs-deploy.yml @@ -37,11 +37,8 @@ jobs: run: yarn build - name: Publish - uses: cloudflare/pages-action@1 + uses: cloudflare/wrangler-action@v3 with: accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} - projectName: ente - branch: help - directory: docs/docs/.vitepress/dist - wranglerVersion: "3" + command: pages deploy --project-name=ente --branch=help docs/docs/.vitepress/dist