|
1 |
| -import { Stack } from '@pulumi/pulumi/automation' |
2 |
| -import { DeploymentConfiguration } from '../types' |
3 |
| -import * as cf from '@pulumi/cloudflare' |
4 |
| -import { |
5 |
| - assertGraphiQL, |
6 |
| - assertQuery, |
7 |
| - env, |
8 |
| - execPromise, |
9 |
| - fsPromises, |
10 |
| - waitForEndpoint, |
11 |
| -} from '../utils' |
12 |
| -import * as pulumi from '@pulumi/pulumi' |
13 |
| -import { version } from '@pulumi/cloudflare/package.json' |
| 1 | +import { createCFDeployment } from './create-cf-deployment' |
14 | 2 |
|
15 |
| -export const cloudFlareDeployment: DeploymentConfiguration<{ |
16 |
| - workerUrl: string |
17 |
| -}> = { |
18 |
| - prerequisites: async (stack: Stack) => { |
19 |
| - console.info('\t\tℹ️ Installing Pulumi CF plugin...') |
20 |
| - // Intall Pulumi CF Plugin |
21 |
| - await stack.workspace.installPlugin('cloudflare', version, 'resource') |
22 |
| - |
23 |
| - // Build and bundle the worker |
24 |
| - console.info('\t\tℹ️ Bundling the CF Worker....') |
25 |
| - await execPromise('yarn build', { |
26 |
| - cwd: '../examples/service-worker', |
27 |
| - }) |
28 |
| - }, |
29 |
| - config: async (stack: Stack) => { |
30 |
| - // Configure the Pulumi environment with the CloudFlare credentials |
31 |
| - // This will allow Pulummi program to just run without caring about secrets/configs. |
32 |
| - // See: https://www.pulumi.com/registry/packages/cloudflare/installation-configuration/ |
33 |
| - await stack.setConfig('cloudflare:apiToken', { |
34 |
| - value: env('CLOUDFLARE_API_TOKEN'), |
35 |
| - }) |
36 |
| - await stack.setConfig('cloudflare:accountId', { |
37 |
| - value: env('CLOUDFLARE_ACCOUNT_ID'), |
38 |
| - }) |
39 |
| - }, |
40 |
| - program: async () => { |
41 |
| - const stackName = pulumi.getStack() |
42 |
| - const workerUrl = `e2e.graphql-yoga.com/${stackName}` |
43 |
| - |
44 |
| - // Deploy CF script as Worker |
45 |
| - const workerScript = new cf.WorkerScript('worker', { |
46 |
| - content: await fsPromises.readFile( |
47 |
| - '../examples/service-worker/dist/index.js', |
48 |
| - 'utf-8', |
49 |
| - ), |
50 |
| - secretTextBindings: [ |
51 |
| - { |
52 |
| - name: 'GRAPHQL_ROUTE', |
53 |
| - text: `/${stackName}`, |
54 |
| - }, |
55 |
| - { |
56 |
| - name: 'DEBUG', |
57 |
| - text: 'true', |
58 |
| - }, |
59 |
| - ], |
60 |
| - name: stackName, |
61 |
| - }) |
62 |
| - |
63 |
| - // Create a nice route for easy testing |
64 |
| - new cf.WorkerRoute('worker-route', { |
65 |
| - scriptName: workerScript.name, |
66 |
| - pattern: workerUrl, |
67 |
| - zoneId: env('CLOUDFLARE_ZONE_ID'), |
68 |
| - }) |
69 |
| - |
70 |
| - return { |
71 |
| - workerUrl: `https://${workerUrl}`, |
72 |
| - } |
73 |
| - }, |
74 |
| - test: async ({ workerUrl }) => { |
75 |
| - console.log(`ℹ️ CloudFlare Worker deployed to URL: ${workerUrl.value}`) |
76 |
| - await waitForEndpoint(workerUrl.value, 5, 10000) |
77 |
| - await assertGraphiQL(workerUrl.value) |
78 |
| - await assertQuery(workerUrl.value) |
79 |
| - }, |
80 |
| -} |
| 3 | +export const cloudFlareDeployment = createCFDeployment('service-worker') |
0 commit comments