-
Notifications
You must be signed in to change notification settings - Fork 565
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Add Cloudflare Modules E2E test * Try * Try new flag * aaa Co-authored-by: Arda TANRIKULU <ardatanrikulu@gmail.com>
- Loading branch information
Showing
6 changed files
with
108 additions
and
81 deletions.
There are no files selected for viewing
This file contains 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 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 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,6 @@ | ||
import { createCFDeployment } from './create-cf-deployment' | ||
|
||
export const cfModulesDeployment = createCFDeployment( | ||
'cloudflare-modules', | ||
true, | ||
) |
This file contains 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 |
---|---|---|
@@ -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') |
This file contains 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,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) | ||
}, | ||
} | ||
} |
This file contains 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