From b2d8d5fdfbf2c90cc4c335b641e51f69c8ab7450 Mon Sep 17 00:00:00 2001 From: Betim Shahini Date: Fri, 19 Jan 2024 19:03:14 -0500 Subject: [PATCH] Fixes and GHA workflows --- .github/workflows/main-relaydistributor.yaml | 51 +++++++++++++++++ .github/workflows/main-relayprocessor.yaml | 53 ++++++++++++++++++ .github/workflows/next-relayprocessor.yaml | 55 +++++++++++++++++++ .github/workflows/release-core.yaml | 2 +- .github/workflows/release-relayprocessor.yaml | 54 ++++++++++++++++++ platform/relaydistributor/src/index.ts | 8 +-- platform/relaydistributor/src/types.ts | 2 +- platform/relayprocessor/src/index.ts | 12 ---- platform/relayprocessor/wrangler.current.toml | 4 +- platform/relayprocessor/wrangler.next.toml | 4 +- 10 files changed, 222 insertions(+), 23 deletions(-) create mode 100644 .github/workflows/main-relaydistributor.yaml create mode 100644 .github/workflows/main-relayprocessor.yaml create mode 100644 .github/workflows/next-relayprocessor.yaml create mode 100644 .github/workflows/release-relayprocessor.yaml diff --git a/.github/workflows/main-relaydistributor.yaml b/.github/workflows/main-relaydistributor.yaml new file mode 100644 index 0000000000..28df5a38ad --- /dev/null +++ b/.github/workflows/main-relaydistributor.yaml @@ -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/wrangler-action@2.0.0 + 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 }} diff --git a/.github/workflows/main-relayprocessor.yaml b/.github/workflows/main-relayprocessor.yaml new file mode 100644 index 0000000000..f977c76265 --- /dev/null +++ b/.github/workflows/main-relayprocessor.yaml @@ -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/wrangler-action@2.0.0 + 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 }} diff --git a/.github/workflows/next-relayprocessor.yaml b/.github/workflows/next-relayprocessor.yaml new file mode 100644 index 0000000000..5ad6414e9d --- /dev/null +++ b/.github/workflows/next-relayprocessor.yaml @@ -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/wrangler-action@2.0.0 + 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 }} diff --git a/.github/workflows/release-core.yaml b/.github/workflows/release-core.yaml index 6bd409c597..c76ccf27a1 100644 --- a/.github/workflows/release-core.yaml +++ b/.github/workflows/release-core.yaml @@ -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 }} diff --git a/.github/workflows/release-relayprocessor.yaml b/.github/workflows/release-relayprocessor.yaml new file mode 100644 index 0000000000..8bdf96a79d --- /dev/null +++ b/.github/workflows/release-relayprocessor.yaml @@ -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/wrangler-action@2.0.0 + 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 }} diff --git a/platform/relaydistributor/src/index.ts b/platform/relaydistributor/src/index.ts index 7a7087c066..53399dafae 100644 --- a/platform/relaydistributor/src/index.ts +++ b/platform/relaydistributor/src/index.ts @@ -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 diff --git a/platform/relaydistributor/src/types.ts b/platform/relaydistributor/src/types.ts index 4581432d17..5e38b4d0dc 100644 --- a/platform/relaydistributor/src/types.ts +++ b/platform/relaydistributor/src/types.ts @@ -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 */ diff --git a/platform/relayprocessor/src/index.ts b/platform/relayprocessor/src/index.ts index 54d496e6ab..5526243f31 100644 --- a/platform/relayprocessor/src/index.ts +++ b/platform/relayprocessor/src/index.ts @@ -23,18 +23,6 @@ export default { }, } -const getSourceEmailAddress = async ( - alias: string, - env: Environment -): Promise => { - 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()) diff --git a/platform/relayprocessor/wrangler.current.toml b/platform/relayprocessor/wrangler.current.toml index 8cb8147bfd..208cde4605 100644 --- a/platform/relayprocessor/wrangler.current.toml +++ b/platform/relayprocessor/wrangler.current.toml @@ -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" diff --git a/platform/relayprocessor/wrangler.next.toml b/platform/relayprocessor/wrangler.next.toml index 2c92d1f950..1d0cd3c6be 100644 --- a/platform/relayprocessor/wrangler.next.toml +++ b/platform/relayprocessor/wrangler.next.toml @@ -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"