Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/deployment-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@ jobs:
strategy:
fail-fast: false
matrix:
plan: ['cf-worker', 'azure-function', 'aws-lambda', 'vercel-function']
plan:
[
'cf-worker',
'cf-modules',
'azure-function',
'aws-lambda',
'vercel-function',
]
name: e2e / ${{ matrix.plan }}

runs-on: ubuntu-latest
if: github.event.pull_request.head.repo.full_name == github.repository
steps:
Expand Down
2 changes: 2 additions & 0 deletions e2e/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { LocalWorkspace } from '@pulumi/pulumi/automation'
import { awsLambdaDeployment } from './tests/aws-lambda'
import { azureFunctionDeployment } from './tests/azure-function'
import { cloudFlareDeployment } from './tests/cf-worker'
import { cfModulesDeployment } from './tests/cf-modules'
import { dockerDeployment } from './tests/docker'
import { DeploymentConfiguration } from './types'
import { env, getCommitId } from './utils'
import { vercelDeployment } from './tests/vercel'

const AVAILABLE_TEST_PLANS = {
'cf-worker': cloudFlareDeployment,
'cf-modules': cfModulesDeployment,
'azure-function': azureFunctionDeployment,
'aws-lambda': awsLambdaDeployment,
'vercel-function': vercelDeployment,
Expand Down
6 changes: 6 additions & 0 deletions e2e/tests/cf-modules.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createCFDeployment } from './create-cf-deployment'

export const cfModulesDeployment = createCFDeployment(
'cloudflare-modules',
true,
)
81 changes: 2 additions & 79 deletions e2e/tests/cf-worker.ts
Original file line number Diff line number Diff line change
@@ -1,80 +1,3 @@
import { Stack } from '@pulumi/pulumi/automation'
import { DeploymentConfiguration } from '../types'
import * as cf from '@pulumi/cloudflare'
import {
assertGraphiQL,
assertQuery,
env,
execPromise,
fsPromises,
waitForEndpoint,
} from '../utils'
import * as pulumi from '@pulumi/pulumi'
import { version } from '@pulumi/cloudflare/package.json'
import { createCFDeployment } from './create-cf-deployment'

export const cloudFlareDeployment: DeploymentConfiguration<{
workerUrl: string
}> = {
prerequisites: async (stack: Stack) => {
console.info('\t\tℹ️ Installing Pulumi CF plugin...')
// Intall Pulumi CF Plugin
await stack.workspace.installPlugin('cloudflare', version, 'resource')

// Build and bundle the worker
console.info('\t\tℹ️ Bundling the CF Worker....')
await execPromise('yarn build', {
cwd: '../examples/service-worker',
})
},
config: async (stack: Stack) => {
// Configure the Pulumi environment with the CloudFlare credentials
// This will allow Pulummi program to just run without caring about secrets/configs.
// See: https://www.pulumi.com/registry/packages/cloudflare/installation-configuration/
await stack.setConfig('cloudflare:apiToken', {
value: env('CLOUDFLARE_API_TOKEN'),
})
await stack.setConfig('cloudflare:accountId', {
value: env('CLOUDFLARE_ACCOUNT_ID'),
})
},
program: async () => {
const stackName = pulumi.getStack()
const workerUrl = `e2e.graphql-yoga.com/${stackName}`

// Deploy CF script as Worker
const workerScript = new cf.WorkerScript('worker', {
content: await fsPromises.readFile(
'../examples/service-worker/dist/index.js',
'utf-8',
),
secretTextBindings: [
{
name: 'GRAPHQL_ROUTE',
text: `/${stackName}`,
},
{
name: 'DEBUG',
text: 'true',
},
],
name: stackName,
})

// Create a nice route for easy testing
new cf.WorkerRoute('worker-route', {
scriptName: workerScript.name,
pattern: workerUrl,
zoneId: env('CLOUDFLARE_ZONE_ID'),
})

return {
workerUrl: `https://${workerUrl}`,
}
},
test: async ({ workerUrl }) => {
console.log(`ℹ️ CloudFlare Worker deployed to URL: ${workerUrl.value}`)
await waitForEndpoint(workerUrl.value, 5, 10000)
await assertGraphiQL(workerUrl.value)
await assertQuery(workerUrl.value)
},
}
export const cloudFlareDeployment = createCFDeployment('service-worker')
86 changes: 86 additions & 0 deletions e2e/tests/create-cf-deployment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import { Stack } from '@pulumi/pulumi/automation'
import { DeploymentConfiguration } from '../types'
import * as cf from '@pulumi/cloudflare'
import {
assertGraphiQL,
assertQuery,
env,
execPromise,
fsPromises,
waitForEndpoint,
} from '../utils'
import * as pulumi from '@pulumi/pulumi'
import { version } from '@pulumi/cloudflare/package.json'

export function createCFDeployment(
projectName: string,
isModule = false,
): DeploymentConfiguration<{
workerUrl: string
}> {
return {
prerequisites: async (stack: Stack) => {
console.info('\t\tℹ️ Installing Pulumi CF plugin...')
// Intall Pulumi CF Plugin
await stack.workspace.installPlugin('cloudflare', version, 'resource')

// Build and bundle the worker
console.info('\t\tℹ️ Bundling the CF Worker....')
await execPromise('yarn build', {
cwd: '../examples/' + projectName,
})
},
config: async (stack: Stack) => {
// Configure the Pulumi environment with the CloudFlare credentials
// This will allow Pulummi program to just run without caring about secrets/configs.
// See: https://www.pulumi.com/registry/packages/cloudflare/installation-configuration/
await stack.setConfig('cloudflare:apiToken', {
value: env('CLOUDFLARE_API_TOKEN'),
})
await stack.setConfig('cloudflare:accountId', {
value: env('CLOUDFLARE_ACCOUNT_ID'),
})
},
program: async () => {
const stackName = pulumi.getStack()
const workerUrl = `e2e.graphql-yoga.com/${stackName}`

// Deploy CF script as Worker
const workerScript = new cf.WorkerScript('worker', {
content: await fsPromises.readFile(
`../examples/${projectName}/dist/index.js`,
'utf-8',
),
module: isModule,
secretTextBindings: [
{
name: 'GRAPHQL_ROUTE',
text: `/${stackName}`,
},
{
name: 'DEBUG',
text: 'true',
},
],
name: stackName,
})

// Create a nice route for easy testing
new cf.WorkerRoute('worker-route', {
scriptName: workerScript.name,
pattern: workerUrl,
zoneId: env('CLOUDFLARE_ZONE_ID'),
})

return {
workerUrl: `https://${workerUrl}`,
}
},
test: async ({ workerUrl }) => {
console.log(`ℹ️ CloudFlare Worker deployed to URL: ${workerUrl.value}`)
await waitForEndpoint(workerUrl.value, 5, 10000)
await assertGraphiQL(workerUrl.value)
await assertQuery(workerUrl.value)
},
}
}
4 changes: 3 additions & 1 deletion examples/cloudflare-modules/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// src/index.mjs
import { createYoga, createSchema } from 'graphql-yoga'

export default createYoga({
const { fetch } = createYoga({
graphqlEndpoint: '/graphql',
landingPage: false,
schema: createSchema({
Expand All @@ -18,3 +18,5 @@ export default createYoga({
},
}),
})

export default { fetch }