Skip to content

Commit

Permalink
Merge pull request #3168 from responsible-ai-collaborative/staging
Browse files Browse the repository at this point in the history
Deploy to Production
  • Loading branch information
kepae authored Oct 28, 2024
2 parents 3d54779 + 48b7bd5 commit 72364e4
Show file tree
Hide file tree
Showing 76 changed files with 4,891 additions and 7,618 deletions.
7 changes: 7 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ on:
type: string
required: false
default: ""
site-url:
description: The URL of the site to deploy
type: string
default: ""
required: false

jobs:
netlify-deploy:
Expand Down Expand Up @@ -119,6 +124,8 @@ jobs:
REALM_API_PRIVATE_KEY: ${{ secrets.REALM_API_PRIVATE_KEY }}
ROLLBAR_POST_SERVER_ITEM_ACCESS_TOKEN: ${{ secrets.GATSBY_ROLLBAR_TOKEN }}
API_MONGODB_CONNECTION_STRING: ${{ secrets.API_MONGODB_CONNECTION_STRING }}
SITE_URL: ${{ inputs.site-url || vars.SITE_URL }}
PROCESS_NOTIFICATIONS_SECRET: ${{ secrets.PROCESS_NOTIFICATIONS_SECRET }}

- name: Build size
run: |
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
with:
sha: ${{ github.event.pull_request.head.sha }}
environment: staging
netlify-context: deploy-preview
netlify-context: branch-deploy
runner-label: ${{ vars.PREVIEW_RUNNER_LABEL }}

call-test:
Expand Down Expand Up @@ -90,6 +90,7 @@ jobs:
with:
sha: ${{ github.event.pull_request.head.sha }}
environment: staging
netlify-context: deploy-preview
netlify-context: branch-deploy
netlify-alias: pr-${{ github.event.pull_request.number }}
runner-label: ${{ vars.PREVIEW_RUNNER_LABEL }}
site-url: https://pr-${{ github.event.pull_request.number }}--staging-aiid.netlify.app
25 changes: 25 additions & 0 deletions .github/workflows/process-notifications.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Process Notifications

on:
workflow_call:
inputs:
environment:
description: The Github environment to load secrets from
type: string
required: true

jobs:
execute-mutation:
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}

steps:
- name: Call GraphQL API
env:
SITE_URL: ${{ vars.SITE_URL }}
PROCESS_NOTIFICATIONS_SECRET: ${{ secrets.PROCESS_NOTIFICATIONS_SECRET }}
run: |
curl -X POST "$SITE_URL/api/graphql" \
-H "Content-Type: application/json" \
-H "PROCESS_NOTIFICATIONS_SECRET: $PROCESS_NOTIFICATIONS_SECRET" \
-d '{"query":"mutation { processNotifications }"}'
9 changes: 8 additions & 1 deletion .github/workflows/production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ jobs:
call-deploy:
if: (inputs.force-deploy == true || success()) && !cancelled()
uses: ./.github/workflows/deploy.yml
needs: [cache-modifier, call-test, call-test-api, call-test-playwright]
needs: [cache-modifier, call-test, call-test-api, call-test-playwright, call-test-playwright-full]
secrets: inherit
permissions:
pull-requests: write
Expand All @@ -95,3 +95,10 @@ jobs:
netlify-alias:
runner-label: ${{ vars.PRODUCTION_RUNNER_LABEL }}
cache-modifier: ${{ needs.cache-modifier.outputs.cache-modifier }}

call-process-notifications:
needs: call-deploy
uses: ./.github/workflows/process-notifications.yml
secrets: inherit
with:
environment: production
7 changes: 7 additions & 0 deletions .github/workflows/staging.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,3 +94,10 @@ jobs:
netlify-alias:
runner-label: ${{ vars.STAGING_RUNNER_LABEL }}
cache-modifier: ${{ needs.cache-modifier.outputs.cache-modifier }}

call-process-notifications:
needs: call-deploy
uses: ./.github/workflows/process-notifications.yml
secrets: inherit
with:
environment: staging
11 changes: 6 additions & 5 deletions .github/workflows/test-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,12 @@ jobs:
API_MONGODB_CONNECTION_STRING: "" # dinamically set by globalSetup.ts
E2E_ADMIN_USERNAME: ""
E2E_ADMIN_PASSWORD: ""
ROLLBAR_POST_SERVER_ITEM_ACCESS_TOKEN: ${{ secrets.GATSBY_ROLLBAR_TOKEN }}
SENDGRID_API_KEY: something
SENDGRID_SENDER_NAME: Test Preview
SENDGRID_SENDER: [email protected]
PROCESS_NOTIFICATIONS_SECRET: sarasa
ROLLBAR_POST_SERVER_ITEM_ACCESS_TOKEN: sarasa
MAILERSEND_API_KEY: something
NOTIFICATIONS_SENDER_NAME: Test Preview
NOTIFICATIONS_SENDER: [email protected]
PROCESS_NOTIFICATIONS_SECRET: sarasa
SITE_URL: http://localhost:8000

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/test-playwright-full.yml
Original file line number Diff line number Diff line change
Expand Up @@ -134,10 +134,11 @@ jobs:
SHARD_INDEX: ${{ matrix.shardIndex }}
SHARD_TOTAL: ${{ matrix.shardTotal }}
TEST_FOLDER: playwright/e2e-full/
SENDGRID_API_KEY: something
SENDGRID_SENDER_NAME: Test Preview
SENDGRID_SENDER: [email protected]
PROCESS_NOTIFICATIONS_SECRET: sarasa
MAILERSEND_API_KEY: something
NOTIFICATIONS_SENDER_NAME: Test Preview
NOTIFICATIONS_SENDER: [email protected]
PROCESS_NOTIFICATIONS_SECRET: sarasa
SITE_URL: http://localhost:8000

- name: Upload Playwright traces
if: failure()
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/test-playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,11 @@ jobs:
SHARD_INDEX: ${{ matrix.shardIndex }}
SHARD_TOTAL: ${{ matrix.shardTotal }}
TEST_FOLDER: playwright/e2e/
SENDGRID_API_KEY: something
SENDGRID_SENDER_NAME: Test Preview
SENDGRID_SENDER: [email protected]
PROCESS_NOTIFICATIONS_SECRET: sarasa
MAILERSEND_API_KEY: something
NOTIFICATIONS_SENDER_NAME: Test Preview
NOTIFICATIONS_SENDER: [email protected]
PROCESS_NOTIFICATIONS_SECRET: sarasa
SITE_URL: http://localhost:8000

- uses: actions/upload-artifact@v4
if: ${{ !cancelled() }}
Expand Down
115 changes: 0 additions & 115 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -823,121 +823,6 @@ On Facebook Authentication settings, set the "Client ID" with the Facebook App I

About Facebook Authentication instructions: https://www.mongodb.com/docs/realm/web/authenticate/#facebook-authentication

## Email subscriptions

### Subscription types

- **All**: This subscription type is not defined yet.
```
{
"userId": "63320ce63ec803072c9f529c"
"type": "all",
}
```
- **Incident**: Users with this subscription type will be notified when the incident associated is updated. This subscription type needs an incident_id value associated.
```
{
"userId": "63320ce63ec803072c9f529c"
"type": "incident",
"incident_id": 10,
}
```
- **New Incident**: Users with this subscription type will be notified when a new Incident is created. The notification will be sent after finish the next site build when the Incident page is actually created.
```
{
"userId": "63320ce63ec803072c9f529c"
"type": "new-incidents",
}
```
- **Entities**: Users can subscribe to a specific Entity. The user with this subscription type will be notified when a new Incident associated with an specific Entity is created or when an existing Incident is updated to be associated with that Entity.
```
{
"userId": "63320ce63ec803072c9f529c",
"type": "entity"
"entityId": "openai",
}
```
- **Submission Promoted**: Users that submit a new Incident Report are automatically subscribed to its promotion. Once the submission has been approved by an editor, the user will recieve an email informing that the submission is now an incident/issue/report.
```
{
"userId": "63320ce63ec803072c9f529c",
"type": "submission-promoted"
}
```

These subscription types are also documented in [subscriptions.js](site/gatsby-site/src/utils/subscriptions.js) file.

### Email notifications

[Sendgrid](https://sendgrid.com/) is used to send email notifications.

To allow email notifications add these secret values to your Atlas App Service following the instructions in the [Atlas App Services documentation](https://www.mongodb.com/docs/atlas/app-services/values-and-secrets/define-and-manage-secrets/).

To disable all email noticications, fill the following `SendGridApiKey` secret value with an empty string. If this secret value is an empty string, the emails will be ignored.

```
SendGridApiKey = [SendGrid API key from https://app.sendgrid.com/settings/api_keys]
publicApiKey = [Public API key from the Atlas Organization. See comment below for more information]
privateApiKey = [Private API key from the Atlas Organization. See comment below for more information]
groupId = [Atlas Service App group ID, eg: "62cc90978bc4600cafdcf16e"]
appId = [Atlas Service App ID, eg: "62cc98647e6a26c53d5b4b53"]
```

To get your Public and Private API Key, follow these [instructions](https://www.mongodb.com/docs/atlas/configure-api-access/#std-label-create-org-api-key).

To get the group ID and the app ID, the easiest way is to navigate to your Atlas Service App dashboard and copy from the URL.
The URL format is https://services.cloud.mongodb.com/groups/[groupId]/apps/[appId]/dashboard

Email notifications to New Incidents (subscription type **New Incident**), Incident updates (subscription type **Incident**) and Submission Promoted (subscription type **Submission Promoted**) are sent when the next build finishes. This is because we have to wait until the new Incident page is generated and accessible.
When a new Incident is created or updates, a pending notification item is saved into the `notifications` DB collection with `processed=false` field.
And finally, as part of the site build process, we processed all pending notifications (`processed=false`), send the emails to all recipients, and update the items with `processed=true` and `sentDate=[now]`.

### Notifications collection definition

- **Incident Updated**
```
{
"type": "incident-updated",
"incident_id": 374,
"processed": false
}
```
- **New Incident Report**
```
{
"type": "new-report-incident",
"incident_id": 374,
"report_number": 2172,
"processed": false
}
```
- **New Incident**
```
{
"type": 'new-incidents',
"incident_id": incidentId,
"processed": false,
}
```
- **Entities**
```
{
"type": "entity",
"incident_id": 374,
"entity_id": "openai",
"isUpdate": true,
"processed": false
}
```
- **Submission Promoted**
```
{
"type": "submission-promoted",
"incident_id": 374,
"processed": false
}
```

### Error logging

This project uses [Rollbar](https://rollbar.com) for error logging for the whole site, including background processes.
Expand Down
2 changes: 1 addition & 1 deletion site/gatsby-site/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ node_modules
/blob-report/
/playwright/.cache/

/netlify/functions/lookupIndex.json
/netlify/functions/lookupIndex.json
Loading

0 comments on commit 72364e4

Please sign in to comment.