-
Notifications
You must be signed in to change notification settings - Fork 2
feat(infra): deploy web app to Vercel with CI workflow and SSM-backed env vars #456
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,232 @@ | ||
| name: web-deploy | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| concurrency: | ||
| group: web-deploy-${{ github.event_name == 'pull_request' && github.event.pull_request.number || github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: | ||
| - stage | ||
| - main | ||
| workflow_dispatch: | ||
|
|
||
| jobs: | ||
| affected: | ||
| if: github.event_name != 'workflow_dispatch' | ||
| permissions: | ||
| contents: read | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| web: ${{ steps.affected.outputs.web }} | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
| with: | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Setup pnpm | ||
| uses: pnpm/action-setup@v4 | ||
|
|
||
| - name: Setup Node | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| node-version-file: .nvmrc | ||
| cache: pnpm | ||
|
|
||
| - name: Install dependencies | ||
| run: pnpm install --frozen-lockfile | ||
|
|
||
| - id: affected | ||
| name: Detect affected web package | ||
| run: | | ||
| if [ "${{ github.event_name }}" = "pull_request" ]; then | ||
| BASE="${{ github.event.pull_request.base.sha }}" | ||
| else | ||
| BASE="${{ github.event.before }}" | ||
| fi | ||
|
|
||
| if [ -z "$BASE" ] || [ "$BASE" = "0000000000000000000000000000000000000000" ]; then | ||
| BASE=$(git rev-parse HEAD^ 2>/dev/null || true) | ||
| fi | ||
|
|
||
| if [ -z "$BASE" ]; then | ||
| echo "web=true" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| fi | ||
|
|
||
| TURBO_STDERR=$(mktemp) | ||
| if ! TURBO_OUT=$(TURBO_SCM_BASE="$BASE" pnpm turbo run lint --affected --dry-run=json 2>"$TURBO_STDERR"); then | ||
| cat "$TURBO_STDERR" >&2 | ||
| echo "$TURBO_OUT" >&2 | ||
| rm -f "$TURBO_STDERR" | ||
| echo "Affected detection failed; forcing deploy to avoid false negative." >&2 | ||
| echo "web=true" >> "$GITHUB_OUTPUT" | ||
| exit 0 | ||
| fi | ||
|
|
||
| WEB_AFFECTED=$(echo "$TURBO_OUT" | jq -r 'try ([.tasks[]?.package] | any(. == "@forge/web")) catch "true"' 2>/dev/null || echo "true") | ||
| rm -f "$TURBO_STDERR" | ||
| echo "web=$WEB_AFFECTED" >> "$GITHUB_OUTPUT" | ||
|
|
||
| deploy: | ||
| permissions: | ||
| id-token: write | ||
| contents: write | ||
| pull-requests: write | ||
| needs: affected | ||
| if: >- | ||
| always() && ( | ||
| (github.event_name == 'workflow_dispatch' && (github.ref_name == 'main' || github.ref_name == 'stage')) | ||
| || (github.event_name != 'workflow_dispatch' && needs.affected.outputs.web == 'true') | ||
| ) | ||
| environment: ${{ github.event_name == 'pull_request' && 'web-preview' || (github.ref_name == 'main' && 'web-prod' || 'web-stage') }} | ||
| runs-on: ubuntu-latest | ||
| env: | ||
| AWS_REGION: ${{ vars.AWS_REGION || 'us-east-2' }} | ||
| VERCEL_ORG_ID: ${{ vars.VERCEL_ORG_ID }} | ||
| VERCEL_PROJECT_ID: ${{ vars.VERCEL_WEB_PROJECT_ID }} | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v6 | ||
|
|
||
| - name: Setup pnpm | ||
| uses: pnpm/action-setup@v4 | ||
|
|
||
| - name: Setup Node | ||
| uses: actions/setup-node@v6 | ||
| with: | ||
| node-version-file: .nvmrc | ||
| cache: pnpm | ||
|
|
||
| - name: Install dependencies | ||
| run: pnpm install --frozen-lockfile | ||
|
|
||
| - name: Resolve environment | ||
| id: vars | ||
| run: | | ||
| if [ "${{ github.event_name }}" = "pull_request" ]; then | ||
| DEPLOY_ENV="preview" | ||
| VERCEL_ENV="preview" | ||
| PROD_FLAG="" | ||
| elif [ "${GITHUB_REF_NAME}" = "main" ]; then | ||
| DEPLOY_ENV="prod" | ||
| VERCEL_ENV="production" | ||
| PROD_FLAG="--prod" | ||
| elif [ "${GITHUB_REF_NAME}" = "stage" ]; then | ||
| DEPLOY_ENV="stage" | ||
| VERCEL_ENV="preview" | ||
| PROD_FLAG="" | ||
| else | ||
| echo "Unsupported branch: ${GITHUB_REF_NAME}" >&2 | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "role_arn=${{ secrets.WEB_DEPLOY_ROLE_ARN }}" >> "$GITHUB_OUTPUT" | ||
| echo "deploy_env=$DEPLOY_ENV" >> "$GITHUB_OUTPUT" | ||
| echo "vercel_env=$VERCEL_ENV" >> "$GITHUB_OUTPUT" | ||
| echo "prod_flag=$PROD_FLAG" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Validate role ARN is configured | ||
| if: steps.vars.outputs.role_arn == '' | ||
| run: | | ||
| echo "Missing WEB_DEPLOY_ROLE_ARN secret for ${GITHUB_JOB} environment on ${GITHUB_REF_NAME}" >&2 | ||
| exit 1 | ||
|
|
||
| - name: Configure AWS credentials | ||
| uses: aws-actions/configure-aws-credentials@v5 | ||
| with: | ||
| role-to-assume: ${{ steps.vars.outputs.role_arn }} | ||
| aws-region: ${{ env.AWS_REGION }} | ||
|
|
||
| - name: Read Vercel API token from SSM | ||
| id: ssm | ||
| run: | | ||
| TOKEN=$(aws ssm get-parameter --name /forge/vercel/api_token --with-decryption --query 'Parameter.Value' --output text) | ||
| echo "::add-mask::$TOKEN" | ||
| echo "vercel_token=$TOKEN" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Pull Vercel environment | ||
| run: pnpm vercel pull --yes --environment=${{ steps.vars.outputs.vercel_env }} --token=${{ steps.ssm.outputs.vercel_token }} | ||
|
|
||
| - name: Build | ||
| run: pnpm vercel build ${{ steps.vars.outputs.prod_flag }} --token=${{ steps.ssm.outputs.vercel_token }} | ||
|
|
||
| - name: Deploy | ||
| id: deploy | ||
| run: | | ||
| URL=$(pnpm vercel deploy --prebuilt ${{ steps.vars.outputs.prod_flag }} --token=${{ steps.ssm.outputs.vercel_token }}) | ||
| echo "url=$URL" >> "$GITHUB_OUTPUT" | ||
|
|
||
| - name: Post preview URL on PR | ||
| if: always() && github.event_name == 'pull_request' && steps.deploy.outputs.url | ||
| continue-on-error: true | ||
| uses: actions/github-script@v8 | ||
| env: | ||
| DEPLOY_URL: ${{ steps.deploy.outputs.url }} | ||
| JOB_STATUS: ${{ job.status }} | ||
| with: | ||
| script: | | ||
| const marker = "<!-- web-deploy-preview -->" | ||
| const status = process.env.JOB_STATUS === "success" ? "deployed" : "failed" | ||
| const url = process.env.DEPLOY_URL | ||
| const body = [ | ||
| marker, | ||
| `**Web preview ${status}**`, | ||
| "", | ||
| url ? `URL: ${url}` : "", | ||
| `Run: ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`, | ||
| ].filter(Boolean).join("\n") | ||
|
|
||
| const { data: comments } = await github.rest.issues.listComments({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.issue.number, | ||
| }) | ||
| const existing = comments.find(c => c.body?.includes(marker)) | ||
| if (existing) { | ||
| await github.rest.issues.updateComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| comment_id: existing.id, | ||
| body, | ||
| }) | ||
| } else { | ||
| await github.rest.issues.createComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| issue_number: context.issue.number, | ||
| body, | ||
| }) | ||
| } | ||
|
|
||
| - name: Post deployment status comment | ||
| if: always() && github.event_name != 'pull_request' | ||
| continue-on-error: true | ||
| uses: actions/github-script@v8 | ||
| env: | ||
| DEPLOY_ENV: ${{ steps.vars.outputs.deploy_env }} | ||
| DEPLOY_URL: ${{ steps.deploy.outputs.url }} | ||
| JOB_STATUS: ${{ job.status }} | ||
| with: | ||
| script: | | ||
| const status = process.env.JOB_STATUS === "success" ? "SUCCESS" : "FAILED" | ||
| const body = [ | ||
| `Web deploy ${status}`, | ||
| "", | ||
| `- Environment: \`${process.env.DEPLOY_ENV || "unknown"}\``, | ||
| `- Branch: \`${context.ref.replace("refs/heads/", "")}\``, | ||
| `- URL: ${process.env.DEPLOY_URL || "n/a"}`, | ||
| `- Run: ${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`, | ||
| ].join("\n") | ||
|
|
||
| await github.rest.repos.createCommitComment({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| commit_sha: context.sha, | ||
| body, | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing SSM read scope for Vercel org/project IDs in Vercel stack roles
Line [383]-[392] and Line [425]-[434] don’t include
/forge/vercel/org_idand/forge/vercel/web_project_id, but the Vercel stack reads them (seen in current plan failures). This leavesvercel_plan/vercel_applyunable to read required parameters.🔧 Proposed fix
ssm_parameter_arns = [ "arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/forge/vercel/api_token", + "arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/forge/vercel/org_id", + "arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/forge/vercel/web_project_id", "arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/forge/aws/web/stage/STRAPI_API_TOKEN", "arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/forge/aws/web/prod/STRAPI_API_TOKEN", "arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/forge/aws/web/stage/STRAPI_PREVIEW_SECRET", "arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/forge/aws/web/prod/STRAPI_PREVIEW_SECRET", "arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/forge/aws/web/stage/NEXT_PUBLIC_GRAPHQL_URL", "arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/forge/aws/web/prod/NEXT_PUBLIC_GRAPHQL_URL", "arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/forge/aws/web/stage/NEXT_PUBLIC_CMS_HOSTNAME", "arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/forge/aws/web/prod/NEXT_PUBLIC_CMS_HOSTNAME", ] ... ssm_parameter_arns = [ "arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/forge/vercel/api_token", + "arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/forge/vercel/org_id", + "arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/forge/vercel/web_project_id", "arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/forge/aws/web/stage/STRAPI_API_TOKEN", "arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/forge/aws/web/prod/STRAPI_API_TOKEN", "arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/forge/aws/web/stage/STRAPI_PREVIEW_SECRET", "arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/forge/aws/web/prod/STRAPI_PREVIEW_SECRET", "arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/forge/aws/web/stage/NEXT_PUBLIC_GRAPHQL_URL", "arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/forge/aws/web/prod/NEXT_PUBLIC_GRAPHQL_URL", "arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/forge/aws/web/stage/NEXT_PUBLIC_CMS_HOSTNAME", "arn:aws:ssm:${var.aws_region}:${data.aws_caller_identity.current.account_id}:parameter/forge/aws/web/prod/NEXT_PUBLIC_CMS_HOSTNAME", ]Also applies to: 424-434
🤖 Prompt for AI Agents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
infra/vercelstack does not readorg_idorweb_project_idfrom SSM — onlyinfra/githubdoes, and thegithub_plan/github_applyroles already include those ARNs (lines 460–461 and 498–499). This is a false positive; no change needed.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tataihono, you're absolutely right — I apologize for the false positive. Looking at the file,github_planandgithub_applyalready include/forge/vercel/org_idand/forge/vercel/web_project_idin theirssm_parameter_arns. Thevercel_plan/vercel_applyroles only need access to the Vercel API token and the web SSM env vars thatinfra/vercelactually reads;org_idandweb_project_idare consumed solely byinfra/github. No change needed.✏️ Learnings added
🧠 Learnings used