Skip to content

Commit

Permalink
Fixes and GHA workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
betimshahini committed Jan 20, 2024
1 parent 88c8890 commit b2d8d5f
Show file tree
Hide file tree
Showing 10 changed files with 222 additions and 23 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/main-relaydistributor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Relay distributor

on:
push:
branches:
- main

defaults:
run:
working-directory: platform/relaydistributor

jobs:
deploy:
runs-on: ubuntu-latest
environment: dev
steps:
- uses: actions/checkout@v3

- uses: cachix/install-nix-action@v18
with:
nix_path: nixpkgs=channel:nixos-unstable

- run: nix-build ../platform.nix

- name: Cache Dependencies
id: cache-modules
uses: actions/cache@v3
with:
path: |
node_modules
.yarn
key: ${{ runner.os }}-node_modules-${{ hashFiles('yarn.lock') }}

- name: Install Dependencies
run: yarn install

- name: Test
run: yarn run test

- name: Deploy
uses: cloudflare/[email protected]
with:
wranglerVersion: '3.19.0'
apiToken: ${{ secrets.TOKEN_CLOUDFLARE_API }}
accountId: ${{ secrets.INTERNAL_CLOUDFLARE_ACCOUNT_ID }}
workingDirectory: platform/relaydistributor
command: publish
secrets: |
SECRET_RELAY_DISTRIBUTION_MAP
env:
SECRET_RELAY_DISTRIBUTION_MAP: ${{ secrets.SECRET_RELAY_DISTRIBUTION_MAP }}
53 changes: 53 additions & 0 deletions .github/workflows/main-relayprocessor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Relay processor

on:
push:
branches:
- main

defaults:
run:
working-directory: platform/relayprocessor

jobs:
deploy:
runs-on: ubuntu-latest
environment: dev
steps:
- uses: actions/checkout@v3

- uses: cachix/install-nix-action@v18
with:
nix_path: nixpkgs=channel:nixos-unstable

- run: nix-build ../platform.nix

- name: Cache Dependencies
id: cache-modules
uses: actions/cache@v3
with:
path: |
node_modules
.yarn
key: ${{ runner.os }}-node_modules-${{ hashFiles('yarn.lock') }}

- name: Install Dependencies
run: yarn install

- name: Test
run: yarn run test

- name: Deploy
uses: cloudflare/[email protected]
with:
wranglerVersion: '3.19.0'
apiToken: ${{ secrets.TOKEN_CLOUDFLARE_API }}
accountId: ${{ secrets.INTERNAL_CLOUDFLARE_ACCOUNT_ID }}
workingDirectory: platform/relayprocessor
command: publish
secrets: |
SECRET_RELAY_DISTRIBUTION_MAP
INTERNAL_RELAY_DISTRIBUTION_KEY
env:
SECRET_RELAY_DISTRIBUTION_MAP: ${{ secrets.SECRET_RELAY_DISTRIBUTION_MAP }}
INTERNAL_RELAY_DISTRIBUTION_KEY: ${{secrets.INTERNAL_RELAY_DISTRIBUTION_KEY_DEV }}
55 changes: 55 additions & 0 deletions .github/workflows/next-relayprocessor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
name: Next Relay Processor

on:
push:
tags:
- '*'

defaults:
run:
working-directory: platform/relayprocessor

jobs:
deploy:
runs-on: ubuntu-latest
environment: next
steps:
- uses: actions/checkout@v3

- uses: cachix/install-nix-action@v18
with:
nix_path: nixpkgs=channel:nixos-unstable

- run: nix-build ../platform.nix

- name: Cache Dependencies
id: cache-modules
uses: actions/cache@v3
with:
path: |
node_modules
.yarn
key: ${{ runner.os }}-node_modules-${{ hashFiles('yarn.lock') }}

- name: Install Dependencies
run: yarn install

- name: Test
run: yarn run test

- name: Deploy
uses: cloudflare/[email protected]
with:
wranglerVersion: '3.19.0'
apiToken: ${{ secrets.TOKEN_CLOUDFLARE_API }}
accountId: ${{ secrets.INTERNAL_CLOUDFLARE_ACCOUNT_ID }}
workingDirectory: platform/relayprocessor
command: publish --config wrangler.next.toml --env next
environment: 'next'
secrets: |
SECRET_RELAY_DISTRIBUTION_MAP
INTERNAL_RELAY_DISTRIBUTION_KEY
env:
SECRET_RELAY_DISTRIBUTION_MAP: ${{ secrets.SECRET_RELAY_DISTRIBUTION_MAP }}
INTERNAL_RELAY_DISTRIBUTION_KEY: ${{secrets.INTERNAL_RELAY_DISTRIBUTION_KEY_TEST }}
2 changes: 1 addition & 1 deletion .github/workflows/release-core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
SECRET_JWKS: ${{ secrets.SECRET_JWKS_PROD }}

INTERNAL_DKIM_SELECTOR: ${{ secrets.INTERNAL_DKIM_SELECTOR }}
INTERNAL_RELAY_DISTRIBUTION_KEY: ${{secrets.INTERNAL_RELAY_DISTRIBUTION_KEY_DEV }}
INTERNAL_RELAY_DISTRIBUTION_KEY: ${{secrets.INTERNAL_RELAY_DISTRIBUTION_KEY_PROD }}

SECRET_RELAY_DKIM_PRIVATE_KEY: ${{ secrets.SECRET_RELAY_DKIM_PRIVATE_KEY }}

Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/release-relayprocessor.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Release Relay Processor

on:
release:
types: [published]

defaults:
run:
working-directory: platform/relayprocessor

jobs:
deploy:
runs-on: ubuntu-latest
environment: prod
steps:
- uses: actions/checkout@v3

- uses: cachix/install-nix-action@v18
with:
nix_path: nixpkgs=channel:nixos-unstable

- run: nix-build ../platform.nix

- name: Cache Dependencies
id: cache-modules
uses: actions/cache@v3
with:
path: |
node_modules
.yarn
key: ${{ runner.os }}-node_modules-${{ hashFiles('yarn.lock') }}

- name: Install Dependencies
run: yarn install

- name: Test
run: yarn run test

- name: Deploy
uses: cloudflare/[email protected]
with:
wranglerVersion: '3.19.0'
apiToken: ${{ secrets.TOKEN_CLOUDFLARE_API }}
accountId: ${{ secrets.INTERNAL_CLOUDFLARE_ACCOUNT_ID }}
workingDirectory: platform/relayprocessor
command: publish --config wrangler.current.toml --env current
environment: 'current'
secrets: |
SECRET_RELAY_DISTRIBUTION_MAP
INTERNAL_RELAY_DISTRIBUTION_KEY
env:
SECRET_RELAY_DISTRIBUTION_MAP: ${{ secrets.SECRET_RELAY_DISTRIBUTION_MAP }}
INTERNAL_RELAY_DISTRIBUTION_KEY: ${{secrets.INTERNAL_RELAY_DISTRIBUTION_KEY_PROD }}
8 changes: 3 additions & 5 deletions platform/relaydistributor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ export default {
}
const envPrefix = userParts[1]

const distEmailEntries = Object.entries(env.SECRET_RELAY_DISTRIBUTION_MAP)

const distEnvEmailsList = distEmailEntries.map(
([key, targetEmail]) => targetEmail
)
const distEmailEntries = Object.entries(
JSON.parse(env.SECRET_RELAY_DISTRIBUTION_MAP)
) as [string, string][]

const envKeyPair = distEmailEntries.filter(
([distributorEnvPrefix, _]) => distributorEnvPrefix === envPrefix
Expand Down
2 changes: 1 addition & 1 deletion platform/relaydistributor/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export interface Environment {
SECRET_RELAY_DISTRIBUTION_MAP: { [addressEnvSuffix: string]: string }
SECRET_RELAY_DISTRIBUTION_MAP: string //containing JSON
}

/** CF EmailMessage type; not provided in CF types lib */
Expand Down
12 changes: 0 additions & 12 deletions platform/relayprocessor/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,6 @@ export default {
},
}

const getSourceEmailAddress = async (
alias: string,
env: Environment
): Promise<string> => {
const coreClient = getCoreClient(env)
const sourceAccountFromMaskedEmail =
await coreClient.account.getSourceFromMaskedAddress.query({
maskedEmail: alias,
})
return sourceAccountFromMaskedEmail.sourceEmail
}

const getCoreClient = (env: Environment) => {
//New trace as entrypoint is the email trigger and not an HTTP request
const headers = generateTraceContextHeaders(generateTraceSpan())
Expand Down
4 changes: 2 additions & 2 deletions platform/relayprocessor/wrangler.current.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ compatibility_date = "2022-10-05"
logpush = true
workers_dev = false

[env.dev]
[env.current]
port = 10146
inspector_port = 11146
local_protocol = "http"

services = [{ binding = "Core", service = "core-current" }]

[env.dev.vars]
[env.current.vars]
INTERNAL_RELAY_DKIM_DOMAIN = "rollup.email"
INTERNAL_RELAY_DKIM_SELECTOR = "mailchannels"
4 changes: 2 additions & 2 deletions platform/relayprocessor/wrangler.next.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ compatibility_date = "2022-10-05"
logpush = true
workers_dev = false

[env.dev]
[env.next]
port = 10146
inspector_port = 11146
local_protocol = "http"

services = [{ binding = "Core", service = "core-next" }]

[env.dev.vars]
[env.next.vars]
INTERNAL_RELAY_DKIM_DOMAIN = "rollup.email"
INTERNAL_RELAY_DKIM_SELECTOR = "mailchannels"

0 comments on commit b2d8d5f

Please sign in to comment.