@gradientedge/cdk-utils 8.144.0 → 8.146.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/lib/cloudflare/common/constants.d.ts +4 -0
- package/dist/src/lib/cloudflare/common/constants.js +8 -0
- package/dist/src/lib/cloudflare/common/construct.d.ts +9 -0
- package/dist/src/lib/cloudflare/common/construct.js +51 -2
- package/dist/src/lib/cloudflare/common/index.d.ts +1 -0
- package/dist/src/lib/cloudflare/common/index.js +1 -0
- package/dist/src/lib/cloudflare/common/stack.d.ts +1 -0
- package/dist/src/lib/cloudflare/common/stack.js +3 -4
- package/dist/src/lib/cloudflare/common/types.d.ts +10 -0
- package/dist/src/lib/cloudflare/construct/index.d.ts +1 -0
- package/dist/src/lib/cloudflare/construct/index.js +17 -0
- package/dist/src/lib/cloudflare/construct/pages-static-site/index.d.ts +2 -0
- package/dist/src/lib/cloudflare/construct/pages-static-site/index.js +18 -0
- package/dist/src/lib/cloudflare/construct/pages-static-site/main.d.ts +55 -0
- package/dist/src/lib/cloudflare/construct/pages-static-site/main.js +90 -0
- package/dist/src/lib/cloudflare/construct/pages-static-site/types.d.ts +11 -0
- package/dist/src/lib/cloudflare/construct/pages-static-site/types.js +2 -0
- package/dist/src/lib/cloudflare/index.d.ts +1 -0
- package/dist/src/lib/cloudflare/index.js +1 -0
- package/dist/src/lib/cloudflare/services/page/main.d.ts +4 -2
- package/dist/src/lib/cloudflare/services/page/main.js +14 -1
- package/dist/src/lib/cloudflare/services/page/types.d.ts +6 -0
- package/dist/src/lib/cloudflare/services/zone/main.d.ts +1 -1
- package/dist/src/lib/cloudflare/services/zone/main.js +2 -4
- package/dist/src/lib/common/types.d.ts +1 -1
- package/package.json +14 -12
- package/src/lib/cloudflare/common/constants.ts +4 -0
- package/src/lib/cloudflare/common/construct.ts +54 -2
- package/src/lib/cloudflare/common/index.ts +1 -0
- package/src/lib/cloudflare/common/stack.ts +4 -4
- package/src/lib/cloudflare/common/types.ts +11 -0
- package/src/lib/cloudflare/construct/index.ts +1 -0
- package/src/lib/cloudflare/construct/pages-static-site/index.ts +2 -0
- package/src/lib/cloudflare/construct/pages-static-site/main.ts +106 -0
- package/src/lib/cloudflare/construct/pages-static-site/types.ts +12 -0
- package/src/lib/cloudflare/index.ts +1 -0
- package/src/lib/cloudflare/services/page/main.ts +17 -2
- package/src/lib/cloudflare/services/page/types.ts +6 -0
- package/src/lib/cloudflare/services/zone/main.ts +3 -5
- package/src/lib/common/types.ts +1 -1
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RemoteBackend = void 0;
|
|
4
|
+
var RemoteBackend;
|
|
5
|
+
(function (RemoteBackend) {
|
|
6
|
+
RemoteBackend["local"] = "local";
|
|
7
|
+
RemoteBackend["s3"] = "s3";
|
|
8
|
+
})(RemoteBackend || (exports.RemoteBackend = RemoteBackend = {}));
|
|
@@ -20,6 +20,15 @@ export declare class CommonCloudflareConstruct extends TerraformStack {
|
|
|
20
20
|
* @summary Determine the fully qualified domain name based on domainName & subDomain
|
|
21
21
|
*/
|
|
22
22
|
protected determineFullyQualifiedDomain(): void;
|
|
23
|
+
/**
|
|
24
|
+
* @summary Determine the account id based on the cdktf.json context
|
|
25
|
+
*/
|
|
26
|
+
protected determineAccountId(): void;
|
|
27
|
+
/**
|
|
28
|
+
* @summary Determine the api token based on the cdktf.json context
|
|
29
|
+
*/
|
|
30
|
+
protected determineApiToken(): void;
|
|
31
|
+
protected determineRemoteBackend(): void;
|
|
23
32
|
/**
|
|
24
33
|
* @summary Utility method to determine if the initialisation is in development (dev) stage
|
|
25
34
|
* This is determined by the stage property injected via cdk context
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CommonCloudflareConstruct = void 0;
|
|
4
|
-
const provider_1 = require("@cdktf/provider-
|
|
4
|
+
const provider_1 = require("@cdktf/provider-aws/lib/provider");
|
|
5
|
+
const provider_2 = require("@cdktf/provider-cloudflare/lib/provider");
|
|
5
6
|
const cdktf_1 = require("cdktf");
|
|
6
7
|
const common_1 = require("../../common");
|
|
7
8
|
const services_1 = require("../services");
|
|
9
|
+
const constants_1 = require("./constants");
|
|
10
|
+
const data_aws_s3_bucket_object_1 = require("@cdktf/provider-aws/lib/data-aws-s3-bucket-object");
|
|
8
11
|
class CommonCloudflareConstruct extends cdktf_1.TerraformStack {
|
|
9
12
|
id;
|
|
10
13
|
fullyQualifiedDomainName;
|
|
@@ -31,7 +34,10 @@ class CommonCloudflareConstruct extends cdktf_1.TerraformStack {
|
|
|
31
34
|
this.workerManager = new services_1.CloudflareWorkerManager();
|
|
32
35
|
this.zoneManager = new services_1.CloudflareZoneManager();
|
|
33
36
|
this.determineFullyQualifiedDomain();
|
|
34
|
-
|
|
37
|
+
this.determineAccountId();
|
|
38
|
+
this.determineApiToken();
|
|
39
|
+
this.determineRemoteBackend();
|
|
40
|
+
new provider_2.CloudflareProvider(this, `${this.id}-provider`, this.props);
|
|
35
41
|
}
|
|
36
42
|
/**
|
|
37
43
|
* @summary Determine the fully qualified domain name based on domainName & subDomain
|
|
@@ -41,6 +47,49 @@ class CommonCloudflareConstruct extends cdktf_1.TerraformStack {
|
|
|
41
47
|
? `${this.props.subDomain}.${this.props.domainName}`
|
|
42
48
|
: this.props.domainName;
|
|
43
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* @summary Determine the account id based on the cdktf.json context
|
|
52
|
+
*/
|
|
53
|
+
determineAccountId() {
|
|
54
|
+
this.props.accountId = new cdktf_1.TerraformVariable(this, `accountId`, {}).stringValue;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* @summary Determine the api token based on the cdktf.json context
|
|
58
|
+
*/
|
|
59
|
+
determineApiToken() {
|
|
60
|
+
this.props.apiToken = new cdktf_1.TerraformVariable(this, `apiToken`, {}).stringValue;
|
|
61
|
+
}
|
|
62
|
+
determineRemoteBackend() {
|
|
63
|
+
const debug = this.node.tryGetContext('debug');
|
|
64
|
+
switch (this.props.remoteBackend?.type) {
|
|
65
|
+
case constants_1.RemoteBackend.s3:
|
|
66
|
+
new provider_1.AwsProvider(this, `${this.id}-aws-provider`, {
|
|
67
|
+
profile: process.env.AWS_PROFILE ?? 'default',
|
|
68
|
+
region: this.props.remoteBackend.region,
|
|
69
|
+
});
|
|
70
|
+
new cdktf_1.S3Backend(this, {
|
|
71
|
+
bucket: this.props.remoteBackend.bucketName,
|
|
72
|
+
dynamodbTable: this.props.remoteBackend.tableName,
|
|
73
|
+
key: `${this.id}`,
|
|
74
|
+
profile: process.env.AWS_PROFILE ?? 'default',
|
|
75
|
+
region: this.props.remoteBackend.region,
|
|
76
|
+
});
|
|
77
|
+
new data_aws_s3_bucket_object_1.DataAwsS3BucketObject(this, `${this.id}-remote-state-ref`, {
|
|
78
|
+
bucket: this.props.remoteBackend.bucketName,
|
|
79
|
+
key: new cdktf_1.DataTerraformRemoteStateS3(this, `${this.id}-remote-state`, {
|
|
80
|
+
bucket: this.props.remoteBackend.bucketName,
|
|
81
|
+
key: `${this.id}`,
|
|
82
|
+
}).getString('bucket_key'),
|
|
83
|
+
});
|
|
84
|
+
break;
|
|
85
|
+
case constants_1.RemoteBackend.local:
|
|
86
|
+
if (debug)
|
|
87
|
+
console.debug(`Using local backend for ${this.id}`);
|
|
88
|
+
break;
|
|
89
|
+
default:
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
44
93
|
/**
|
|
45
94
|
* @summary Utility method to determine if the initialisation is in development (dev) stage
|
|
46
95
|
* This is determined by the stage property injected via cdk context
|
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./constants"), exports);
|
|
17
18
|
__exportStar(require("./construct"), exports);
|
|
18
19
|
__exportStar(require("./stack"), exports);
|
|
19
20
|
__exportStar(require("./types"), exports);
|
|
@@ -5,7 +5,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.CommonCloudflareStack = void 0;
|
|
7
7
|
const fs_1 = __importDefault(require("fs"));
|
|
8
|
-
const construct_1 = require("./construct");
|
|
9
8
|
const app_root_path_1 = __importDefault(require("app-root-path"));
|
|
10
9
|
const cdktf_1 = require("cdktf");
|
|
11
10
|
const lodash_1 = __importDefault(require("lodash"));
|
|
@@ -32,8 +31,6 @@ class CommonCloudflareStack extends cdktf_1.TerraformStack {
|
|
|
32
31
|
/* determine extra cdk stage contexts */
|
|
33
32
|
this.determineStageContexts();
|
|
34
33
|
this.props = this.determineConstructProps(props);
|
|
35
|
-
/* initialise the construct */
|
|
36
|
-
this.construct = new construct_1.CommonCloudflareConstruct(this, 'cdk-utils', this.props);
|
|
37
34
|
}
|
|
38
35
|
/**
|
|
39
36
|
* @summary Method to determine the core CDK construct properties injected via context cdktf.json
|
|
@@ -41,14 +38,16 @@ class CommonCloudflareStack extends cdktf_1.TerraformStack {
|
|
|
41
38
|
* @returns The stack properties
|
|
42
39
|
*/
|
|
43
40
|
determineConstructProps(props) {
|
|
41
|
+
const stage = this.node.tryGetContext('stage');
|
|
44
42
|
return {
|
|
45
43
|
accountId: this.node.tryGetContext('accountId'),
|
|
44
|
+
apiToken: this.node.tryGetContext('apiToken'),
|
|
46
45
|
domainName: this.node.tryGetContext('domainName'),
|
|
47
46
|
extraContexts: this.node.tryGetContext('extraContexts'),
|
|
48
47
|
features: this.node.tryGetContext('features'),
|
|
49
48
|
name: this.node.tryGetContext('resourceGroupName'),
|
|
50
49
|
skipStageForARecords: this.node.tryGetContext('skipStageForARecords'),
|
|
51
|
-
stage:
|
|
50
|
+
stage: stage,
|
|
52
51
|
subDomain: this.node.tryGetContext('subDomain'),
|
|
53
52
|
};
|
|
54
53
|
}
|
|
@@ -1,7 +1,17 @@
|
|
|
1
1
|
import { CloudflareProviderConfig } from '@cdktf/provider-cloudflare/lib/provider';
|
|
2
2
|
import { BaseProps } from '../../common';
|
|
3
|
+
import { RemoteBackend } from './constants';
|
|
4
|
+
export interface RemoteBackendProps {
|
|
5
|
+
bucketName: string;
|
|
6
|
+
region: string;
|
|
7
|
+
tableName: string;
|
|
8
|
+
type: RemoteBackend;
|
|
9
|
+
}
|
|
3
10
|
/**
|
|
4
11
|
*/
|
|
5
12
|
export interface CommonCloudflareStackProps extends BaseProps, CloudflareProviderConfig {
|
|
6
13
|
accountId: string;
|
|
14
|
+
apiToken: string;
|
|
15
|
+
remoteBackend?: RemoteBackendProps;
|
|
16
|
+
useExistingZone?: boolean;
|
|
7
17
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './pages-static-site';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./pages-static-site"), exports);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./main"), exports);
|
|
18
|
+
__exportStar(require("./types"), exports);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { DataCloudflareZone } from '@cdktf/provider-cloudflare/lib/data-cloudflare-zone';
|
|
2
|
+
import { PagesDomain } from '@cdktf/provider-cloudflare/lib/pages-domain';
|
|
3
|
+
import { PagesProject } from '@cdktf/provider-cloudflare/lib/pages-project';
|
|
4
|
+
import { Record } from '@cdktf/provider-cloudflare/lib/record';
|
|
5
|
+
import { Zone } from '@cdktf/provider-cloudflare/lib/zone';
|
|
6
|
+
import { Construct } from 'constructs';
|
|
7
|
+
import { CommonCloudflareConstruct } from '../../common';
|
|
8
|
+
import { CloudflarePagesStaticSiteProps } from './types';
|
|
9
|
+
/**
|
|
10
|
+
* @classdesc Provides a construct to create and deploy a cloudflare pages static site
|
|
11
|
+
* @example
|
|
12
|
+
* import { CloudflarePagesStaticSite, CloudflareStaticSiteProps } '@gradientedge/cdk-utils'
|
|
13
|
+
* import { Construct } from 'constructs'
|
|
14
|
+
*
|
|
15
|
+
* class CustomConstruct extends CloudflarePagesStaticSite {
|
|
16
|
+
* constructor(parent: Construct, id: string, props: CloudflareStaticSiteProps) {
|
|
17
|
+
* super(parent, id, props)
|
|
18
|
+
* this.props = props
|
|
19
|
+
* this.id = id
|
|
20
|
+
* this.initResources()
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
*/
|
|
24
|
+
export declare class CloudflarePagesStaticSite extends CommonCloudflareConstruct {
|
|
25
|
+
props: CloudflarePagesStaticSiteProps;
|
|
26
|
+
sitePagesCnameRecord: Record;
|
|
27
|
+
sitePagesDomain: PagesDomain;
|
|
28
|
+
sitePagesProject: PagesProject;
|
|
29
|
+
siteZone: DataCloudflareZone | Zone;
|
|
30
|
+
constructor(parent: Construct, id: string, props: CloudflarePagesStaticSiteProps);
|
|
31
|
+
/**
|
|
32
|
+
* @summary Initialise and provision resources
|
|
33
|
+
*/
|
|
34
|
+
protected initResources(): void;
|
|
35
|
+
/**
|
|
36
|
+
* @summary Resolve the zone to use for the static site
|
|
37
|
+
*/
|
|
38
|
+
protected resolveZone(): void;
|
|
39
|
+
/**
|
|
40
|
+
* @summary Create the pages project
|
|
41
|
+
*/
|
|
42
|
+
protected createProject(): void;
|
|
43
|
+
/**
|
|
44
|
+
* @summary Create the pages domain
|
|
45
|
+
*/
|
|
46
|
+
protected createDomain(): void;
|
|
47
|
+
/**
|
|
48
|
+
* @summary Create the pages cname record
|
|
49
|
+
*/
|
|
50
|
+
protected createRecord(): void;
|
|
51
|
+
/**
|
|
52
|
+
* @summary Deploy the pages project
|
|
53
|
+
*/
|
|
54
|
+
protected deploySite(): void;
|
|
55
|
+
}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CloudflarePagesStaticSite = void 0;
|
|
4
|
+
const common_1 = require("../../common");
|
|
5
|
+
/**
|
|
6
|
+
* @classdesc Provides a construct to create and deploy a cloudflare pages static site
|
|
7
|
+
* @example
|
|
8
|
+
* import { CloudflarePagesStaticSite, CloudflareStaticSiteProps } '@gradientedge/cdk-utils'
|
|
9
|
+
* import { Construct } from 'constructs'
|
|
10
|
+
*
|
|
11
|
+
* class CustomConstruct extends CloudflarePagesStaticSite {
|
|
12
|
+
* constructor(parent: Construct, id: string, props: CloudflareStaticSiteProps) {
|
|
13
|
+
* super(parent, id, props)
|
|
14
|
+
* this.props = props
|
|
15
|
+
* this.id = id
|
|
16
|
+
* this.initResources()
|
|
17
|
+
* }
|
|
18
|
+
* }
|
|
19
|
+
*/
|
|
20
|
+
class CloudflarePagesStaticSite extends common_1.CommonCloudflareConstruct {
|
|
21
|
+
/* static site resources */
|
|
22
|
+
sitePagesCnameRecord;
|
|
23
|
+
sitePagesDomain;
|
|
24
|
+
sitePagesProject;
|
|
25
|
+
siteZone;
|
|
26
|
+
constructor(parent, id, props) {
|
|
27
|
+
super(parent, id, props);
|
|
28
|
+
this.props = props;
|
|
29
|
+
this.id = id;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* @summary Initialise and provision resources
|
|
33
|
+
*/
|
|
34
|
+
initResources() {
|
|
35
|
+
this.resolveZone();
|
|
36
|
+
this.createProject();
|
|
37
|
+
this.createDomain();
|
|
38
|
+
this.createRecord();
|
|
39
|
+
this.deploySite();
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* @summary Resolve the zone to use for the static site
|
|
43
|
+
*/
|
|
44
|
+
resolveZone() {
|
|
45
|
+
if (this.props.useExistingZone) {
|
|
46
|
+
this.siteZone = this.zoneManager.resolveZone(`${this.id}-zone`, this);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
this.siteZone = this.zoneManager.createZone(`${this.id}-zone`, this, this.props.siteZone);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* @summary Create the pages project
|
|
54
|
+
*/
|
|
55
|
+
createProject() {
|
|
56
|
+
this.sitePagesProject = this.pageManager.createPagesProject(`${this.id}-site-project`, this, this.props.sitePagesProject);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* @summary Create the pages domain
|
|
60
|
+
*/
|
|
61
|
+
createDomain() {
|
|
62
|
+
this.sitePagesDomain = this.pageManager.createPagesDomain(`${this.id}-site-domain`, this, {
|
|
63
|
+
accountId: this.props.accountId,
|
|
64
|
+
domain: `${this.props.siteSubDomain}.${this.props.domainName}`,
|
|
65
|
+
projectName: this.sitePagesProject.name,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @summary Create the pages cname record
|
|
70
|
+
*/
|
|
71
|
+
createRecord() {
|
|
72
|
+
this.sitePagesCnameRecord = this.recordManager.createRecord(`${this.id}-site-record`, this, {
|
|
73
|
+
...this.props.siteCnameRecord,
|
|
74
|
+
name: this.props.siteSubDomain,
|
|
75
|
+
value: `${this.sitePagesProject.name}.pages.dev`,
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* @summary Deploy the pages project
|
|
80
|
+
*/
|
|
81
|
+
deploySite() {
|
|
82
|
+
this.pageManager.deployPagesProject(`${this.id}-deploy`, this, {
|
|
83
|
+
branch: this.props.siteBranch ?? 'main',
|
|
84
|
+
directory: this.props.siteAssetDir,
|
|
85
|
+
message: this.props.siteDeployMessage,
|
|
86
|
+
projectName: this.sitePagesProject.name,
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.CloudflarePagesStaticSite = CloudflarePagesStaticSite;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { CommonCloudflareStackProps } from '../../common';
|
|
2
|
+
import { PagesProjectProps, RecordProps, ZoneProps } from '../../services';
|
|
3
|
+
export interface CloudflarePagesStaticSiteProps extends CommonCloudflareStackProps {
|
|
4
|
+
siteAssetDir: string;
|
|
5
|
+
siteBranch?: string;
|
|
6
|
+
siteCnameRecord: RecordProps;
|
|
7
|
+
siteDeployMessage: string;
|
|
8
|
+
sitePagesProject: PagesProjectProps;
|
|
9
|
+
siteSubDomain: string;
|
|
10
|
+
siteZone: ZoneProps;
|
|
11
|
+
}
|
|
@@ -15,6 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
17
|
__exportStar(require("./common"), exports);
|
|
18
|
+
__exportStar(require("./construct"), exports);
|
|
18
19
|
__exportStar(require("./services"), exports);
|
|
19
20
|
__exportStar(require("./types"), exports);
|
|
20
21
|
__exportStar(require("./utils"), exports);
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { PageRule } from '@cdktf/provider-cloudflare/lib/page-rule';
|
|
1
2
|
import { PagesDomain } from '@cdktf/provider-cloudflare/lib/pages-domain';
|
|
2
3
|
import { PagesProject } from '@cdktf/provider-cloudflare/lib/pages-project';
|
|
4
|
+
import { LocalExec } from 'cdktf-local-exec';
|
|
3
5
|
import { CommonCloudflareConstruct } from '../../common';
|
|
4
|
-
import { PageRuleProps, PagesDomainProps, PagesProjectProps } from './types';
|
|
5
|
-
import { PageRule } from '@cdktf/provider-cloudflare/lib/page-rule';
|
|
6
|
+
import { PageRuleProps, PagesDomainProps, PagesProjectDeployProps, PagesProjectProps } from './types';
|
|
6
7
|
/**
|
|
7
8
|
* @classdesc Provides operations on Cloudflare Pages
|
|
8
9
|
* - A new instance of this class is injected into {@link CommonCloudflareConstruct} constructor.
|
|
@@ -45,4 +46,5 @@ export declare class CloudflarePageManager {
|
|
|
45
46
|
* @see [CDKTF Page Rule Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/pageRule.typescript.md}
|
|
46
47
|
*/
|
|
47
48
|
createPageRule(id: string, scope: CommonCloudflareConstruct, props: PageRuleProps): PageRule;
|
|
49
|
+
deployPagesProject(id: string, scope: CommonCloudflareConstruct, props: PagesProjectDeployProps): LocalExec;
|
|
48
50
|
}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CloudflarePageManager = void 0;
|
|
4
|
+
const page_rule_1 = require("@cdktf/provider-cloudflare/lib/page-rule");
|
|
4
5
|
const pages_domain_1 = require("@cdktf/provider-cloudflare/lib/pages-domain");
|
|
5
6
|
const pages_project_1 = require("@cdktf/provider-cloudflare/lib/pages-project");
|
|
7
|
+
const cdktf_local_exec_1 = require("cdktf-local-exec");
|
|
6
8
|
const utils_1 = require("../../utils");
|
|
7
|
-
const page_rule_1 = require("@cdktf/provider-cloudflare/lib/page-rule");
|
|
8
9
|
/**
|
|
9
10
|
* @classdesc Provides operations on Cloudflare Pages
|
|
10
11
|
* - A new instance of this class is injected into {@link CommonCloudflareConstruct} constructor.
|
|
@@ -82,5 +83,17 @@ class CloudflarePageManager {
|
|
|
82
83
|
(0, utils_1.createCloudflareTfOutput)(`${id}-pageRuleId`, scope, pageRule.id);
|
|
83
84
|
return pageRule;
|
|
84
85
|
}
|
|
86
|
+
deployPagesProject(id, scope, props) {
|
|
87
|
+
if (!props)
|
|
88
|
+
throw `Props undefined for ${id}`;
|
|
89
|
+
const localExecProvider = new cdktf_local_exec_1.Provider(scope, `${id}`);
|
|
90
|
+
const branch = scope.isProductionStage() ? 'main' : props.branch;
|
|
91
|
+
const message = process.env.BUILD_NUMBER ?? props.message;
|
|
92
|
+
const deployment = new cdktf_local_exec_1.LocalExec(scope, `${id}-deploy-${new Date().toISOString()}`, {
|
|
93
|
+
command: `CLOUDFLARE_ACCOUNT_ID=${scope.props.accountId} CLOUDFLARE_API_TOKEN=${scope.props.apiToken} npx wrangler pages deploy ${props.directory} --project-name=${props.projectName} --branch=${props.branch} --commit-message=${message}`,
|
|
94
|
+
cwd: '',
|
|
95
|
+
});
|
|
96
|
+
return deployment;
|
|
97
|
+
}
|
|
85
98
|
}
|
|
86
99
|
exports.CloudflarePageManager = CloudflarePageManager;
|
|
@@ -34,7 +34,7 @@ export declare class CloudflareZoneManager {
|
|
|
34
34
|
* @see [CDKTF Zone Module]{@link https://github.com/cdktf/cdktf-provider-cloudflare/blob/main/docs/zone.typescript.md}
|
|
35
35
|
*/
|
|
36
36
|
createZone(id: string, scope: CommonCloudflareConstruct, props: ZoneProps): Zone;
|
|
37
|
-
resolveZone(id: string, scope: CommonCloudflareConstruct, options
|
|
37
|
+
resolveZone(id: string, scope: CommonCloudflareConstruct, options?: ZoneOptions): DataCloudflareZone;
|
|
38
38
|
/**
|
|
39
39
|
* @summary Method to create a new zone cache reserve
|
|
40
40
|
* @param id scoped id of the resource
|
|
@@ -49,12 +49,10 @@ class CloudflareZoneManager {
|
|
|
49
49
|
return zone;
|
|
50
50
|
}
|
|
51
51
|
resolveZone(id, scope, options) {
|
|
52
|
-
if (!options)
|
|
53
|
-
throw `Options undefined for ${id}`;
|
|
54
52
|
const zone = new data_cloudflare_zone_1.DataCloudflareZone(scope, `${id}-data-zone`, {
|
|
55
53
|
accountId: scope.props.accountId,
|
|
56
|
-
name: options
|
|
57
|
-
zoneId: options
|
|
54
|
+
name: options?.name ?? scope.props.domainName,
|
|
55
|
+
zoneId: options?.id,
|
|
58
56
|
});
|
|
59
57
|
return zone;
|
|
60
58
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gradientedge/cdk-utils",
|
|
3
|
-
"version": "8.
|
|
3
|
+
"version": "8.146.0",
|
|
4
4
|
"description": "Utilities for AWS CDK provisioning",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"engines": {
|
|
@@ -47,17 +47,19 @@
|
|
|
47
47
|
}
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@aws-sdk/client-secrets-manager": "^3.
|
|
51
|
-
"@aws-sdk/credential-providers": "^3.
|
|
50
|
+
"@aws-sdk/client-secrets-manager": "^3.458.0",
|
|
51
|
+
"@aws-sdk/credential-providers": "^3.458.0",
|
|
52
52
|
"@aws-sdk/types": "^3.451.0",
|
|
53
|
-
"@cdktf/provider-
|
|
53
|
+
"@cdktf/provider-aws": "^18.0.6",
|
|
54
|
+
"@cdktf/provider-azurerm": "^11.0.6",
|
|
54
55
|
"@cdktf/provider-cloudflare": "^10.0.3",
|
|
55
|
-
"@types/lodash": "^4.14.
|
|
56
|
-
"@types/node": "^20.
|
|
56
|
+
"@types/lodash": "^4.14.202",
|
|
57
|
+
"@types/node": "^20.10.0",
|
|
57
58
|
"@types/uuid": "^9.0.7",
|
|
58
59
|
"app-root-path": "^3.1.0",
|
|
59
|
-
"aws-cdk-lib": "^2.110.
|
|
60
|
+
"aws-cdk-lib": "^2.110.1",
|
|
60
61
|
"cdktf": "^0.19.1",
|
|
62
|
+
"cdktf-local-exec": "^0.4.8",
|
|
61
63
|
"constructs": "^10.3.0",
|
|
62
64
|
"lodash": "^4.17.21",
|
|
63
65
|
"moment": "^2.29.4",
|
|
@@ -70,10 +72,10 @@
|
|
|
70
72
|
"@babel/core": "^7.23.3",
|
|
71
73
|
"@babel/eslint-parser": "^7.23.3",
|
|
72
74
|
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
73
|
-
"@types/jest": "^29.5.
|
|
74
|
-
"@typescript-eslint/eslint-plugin": "^6.
|
|
75
|
-
"@typescript-eslint/parser": "^6.
|
|
76
|
-
"aws-cdk": "^2.110.
|
|
75
|
+
"@types/jest": "^29.5.10",
|
|
76
|
+
"@typescript-eslint/eslint-plugin": "^6.12.0",
|
|
77
|
+
"@typescript-eslint/parser": "^6.12.0",
|
|
78
|
+
"aws-cdk": "^2.110.1",
|
|
77
79
|
"better-docs": "^2.7.2",
|
|
78
80
|
"codecov": "^3.8.3",
|
|
79
81
|
"commitizen": "^4.3.0",
|
|
@@ -99,7 +101,7 @@
|
|
|
99
101
|
"taffydb": "^2.7.3",
|
|
100
102
|
"ts-jest": "^29.1.1",
|
|
101
103
|
"ts-node": "^10.9.1",
|
|
102
|
-
"typescript": "5.
|
|
104
|
+
"typescript": "5.3.2"
|
|
103
105
|
},
|
|
104
106
|
"optionalDependencies": {
|
|
105
107
|
"prop-types": "^15.8.1",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { AwsProvider } from '@cdktf/provider-aws/lib/provider'
|
|
1
2
|
import { CloudflareProvider } from '@cdktf/provider-cloudflare/lib/provider'
|
|
2
|
-
import { TerraformStack } from 'cdktf'
|
|
3
|
+
import { DataTerraformRemoteStateS3, S3Backend, TerraformStack, TerraformVariable } from 'cdktf'
|
|
3
4
|
import { Construct } from 'constructs'
|
|
4
5
|
import { isDevStage, isPrdStage, isTestStage, isUatStage } from '../../common'
|
|
5
6
|
import {
|
|
@@ -13,7 +14,9 @@ import {
|
|
|
13
14
|
CloudflareWorkerManager,
|
|
14
15
|
CloudflareZoneManager,
|
|
15
16
|
} from '../services'
|
|
17
|
+
import { RemoteBackend } from './constants'
|
|
16
18
|
import { CommonCloudflareStackProps } from './types'
|
|
19
|
+
import { DataAwsS3BucketObject } from '@cdktf/provider-aws/lib/data-aws-s3-bucket-object'
|
|
17
20
|
|
|
18
21
|
export class CommonCloudflareConstruct extends TerraformStack {
|
|
19
22
|
declare props: CommonCloudflareStackProps
|
|
@@ -45,18 +48,67 @@ export class CommonCloudflareConstruct extends TerraformStack {
|
|
|
45
48
|
this.zoneManager = new CloudflareZoneManager()
|
|
46
49
|
|
|
47
50
|
this.determineFullyQualifiedDomain()
|
|
51
|
+
this.determineAccountId()
|
|
52
|
+
this.determineApiToken()
|
|
53
|
+
this.determineRemoteBackend()
|
|
48
54
|
new CloudflareProvider(this, `${this.id}-provider`, this.props)
|
|
49
55
|
}
|
|
50
56
|
|
|
51
57
|
/**
|
|
52
58
|
* @summary Determine the fully qualified domain name based on domainName & subDomain
|
|
53
59
|
*/
|
|
54
|
-
protected determineFullyQualifiedDomain()
|
|
60
|
+
protected determineFullyQualifiedDomain() {
|
|
55
61
|
this.fullyQualifiedDomainName = this.props.subDomain
|
|
56
62
|
? `${this.props.subDomain}.${this.props.domainName}`
|
|
57
63
|
: this.props.domainName
|
|
58
64
|
}
|
|
59
65
|
|
|
66
|
+
/**
|
|
67
|
+
* @summary Determine the account id based on the cdktf.json context
|
|
68
|
+
*/
|
|
69
|
+
protected determineAccountId() {
|
|
70
|
+
this.props.accountId = new TerraformVariable(this, `accountId`, {}).stringValue
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @summary Determine the api token based on the cdktf.json context
|
|
75
|
+
*/
|
|
76
|
+
protected determineApiToken() {
|
|
77
|
+
this.props.apiToken = new TerraformVariable(this, `apiToken`, {}).stringValue
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
protected determineRemoteBackend() {
|
|
81
|
+
const debug = this.node.tryGetContext('debug')
|
|
82
|
+
switch (this.props.remoteBackend?.type) {
|
|
83
|
+
case RemoteBackend.s3:
|
|
84
|
+
new AwsProvider(this, `${this.id}-aws-provider`, {
|
|
85
|
+
profile: process.env.AWS_PROFILE ?? 'default',
|
|
86
|
+
region: this.props.remoteBackend.region,
|
|
87
|
+
})
|
|
88
|
+
new S3Backend(this, {
|
|
89
|
+
bucket: this.props.remoteBackend.bucketName,
|
|
90
|
+
dynamodbTable: this.props.remoteBackend.tableName,
|
|
91
|
+
key: `${this.id}`,
|
|
92
|
+
profile: process.env.AWS_PROFILE ?? 'default',
|
|
93
|
+
region: this.props.remoteBackend.region,
|
|
94
|
+
})
|
|
95
|
+
new DataAwsS3BucketObject(this, `${this.id}-remote-state-ref`, {
|
|
96
|
+
bucket: this.props.remoteBackend.bucketName,
|
|
97
|
+
key: new DataTerraformRemoteStateS3(this, `${this.id}-remote-state`, {
|
|
98
|
+
bucket: this.props.remoteBackend.bucketName,
|
|
99
|
+
key: `${this.id}`,
|
|
100
|
+
}).getString('bucket_key'),
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
break
|
|
104
|
+
case RemoteBackend.local:
|
|
105
|
+
if (debug) console.debug(`Using local backend for ${this.id}`)
|
|
106
|
+
break
|
|
107
|
+
default:
|
|
108
|
+
break
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
60
112
|
/**
|
|
61
113
|
* @summary Utility method to determine if the initialisation is in development (dev) stage
|
|
62
114
|
* This is determined by the stage property injected via cdk context
|
|
@@ -7,6 +7,7 @@ import { TerraformStack } from 'cdktf'
|
|
|
7
7
|
import { Construct } from 'constructs'
|
|
8
8
|
import _ from 'lodash'
|
|
9
9
|
import { isDevStage } from '../../common'
|
|
10
|
+
import { RemoteBackend } from './constants'
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* @classdesc Common stack to use as a base for all higher level constructs.
|
|
@@ -34,9 +35,6 @@ export class CommonCloudflareStack extends TerraformStack {
|
|
|
34
35
|
this.determineStageContexts()
|
|
35
36
|
|
|
36
37
|
this.props = this.determineConstructProps(props)
|
|
37
|
-
|
|
38
|
-
/* initialise the construct */
|
|
39
|
-
this.construct = new CommonCloudflareConstruct(this, 'cdk-utils', this.props)
|
|
40
38
|
}
|
|
41
39
|
|
|
42
40
|
/**
|
|
@@ -45,14 +43,16 @@ export class CommonCloudflareStack extends TerraformStack {
|
|
|
45
43
|
* @returns The stack properties
|
|
46
44
|
*/
|
|
47
45
|
protected determineConstructProps(props: CommonCloudflareStackProps) {
|
|
46
|
+
const stage = this.node.tryGetContext('stage')
|
|
48
47
|
return {
|
|
49
48
|
accountId: this.node.tryGetContext('accountId'),
|
|
49
|
+
apiToken: this.node.tryGetContext('apiToken'),
|
|
50
50
|
domainName: this.node.tryGetContext('domainName'),
|
|
51
51
|
extraContexts: this.node.tryGetContext('extraContexts'),
|
|
52
52
|
features: this.node.tryGetContext('features'),
|
|
53
53
|
name: this.node.tryGetContext('resourceGroupName'),
|
|
54
54
|
skipStageForARecords: this.node.tryGetContext('skipStageForARecords'),
|
|
55
|
-
stage:
|
|
55
|
+
stage: stage,
|
|
56
56
|
subDomain: this.node.tryGetContext('subDomain'),
|
|
57
57
|
}
|
|
58
58
|
}
|
|
@@ -1,8 +1,19 @@
|
|
|
1
1
|
import { CloudflareProviderConfig } from '@cdktf/provider-cloudflare/lib/provider'
|
|
2
2
|
import { BaseProps } from '../../common'
|
|
3
|
+
import { RemoteBackend } from './constants'
|
|
4
|
+
|
|
5
|
+
export interface RemoteBackendProps {
|
|
6
|
+
bucketName: string
|
|
7
|
+
region: string
|
|
8
|
+
tableName: string
|
|
9
|
+
type: RemoteBackend
|
|
10
|
+
}
|
|
3
11
|
|
|
4
12
|
/**
|
|
5
13
|
*/
|
|
6
14
|
export interface CommonCloudflareStackProps extends BaseProps, CloudflareProviderConfig {
|
|
7
15
|
accountId: string
|
|
16
|
+
apiToken: string
|
|
17
|
+
remoteBackend?: RemoteBackendProps
|
|
18
|
+
useExistingZone?: boolean
|
|
8
19
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './pages-static-site'
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { DataCloudflareZone } from '@cdktf/provider-cloudflare/lib/data-cloudflare-zone'
|
|
2
|
+
import { PagesDomain } from '@cdktf/provider-cloudflare/lib/pages-domain'
|
|
3
|
+
import { PagesProject } from '@cdktf/provider-cloudflare/lib/pages-project'
|
|
4
|
+
import { Record } from '@cdktf/provider-cloudflare/lib/record'
|
|
5
|
+
import { Zone } from '@cdktf/provider-cloudflare/lib/zone'
|
|
6
|
+
import { Construct } from 'constructs'
|
|
7
|
+
import { CommonCloudflareConstruct } from '../../common'
|
|
8
|
+
import { CloudflarePagesStaticSiteProps } from './types'
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* @classdesc Provides a construct to create and deploy a cloudflare pages static site
|
|
12
|
+
* @example
|
|
13
|
+
* import { CloudflarePagesStaticSite, CloudflareStaticSiteProps } '@gradientedge/cdk-utils'
|
|
14
|
+
* import { Construct } from 'constructs'
|
|
15
|
+
*
|
|
16
|
+
* class CustomConstruct extends CloudflarePagesStaticSite {
|
|
17
|
+
* constructor(parent: Construct, id: string, props: CloudflareStaticSiteProps) {
|
|
18
|
+
* super(parent, id, props)
|
|
19
|
+
* this.props = props
|
|
20
|
+
* this.id = id
|
|
21
|
+
* this.initResources()
|
|
22
|
+
* }
|
|
23
|
+
* }
|
|
24
|
+
*/
|
|
25
|
+
export class CloudflarePagesStaticSite extends CommonCloudflareConstruct {
|
|
26
|
+
declare props: CloudflarePagesStaticSiteProps
|
|
27
|
+
|
|
28
|
+
/* static site resources */
|
|
29
|
+
sitePagesCnameRecord: Record
|
|
30
|
+
sitePagesDomain: PagesDomain
|
|
31
|
+
sitePagesProject: PagesProject
|
|
32
|
+
siteZone: DataCloudflareZone | Zone
|
|
33
|
+
|
|
34
|
+
constructor(parent: Construct, id: string, props: CloudflarePagesStaticSiteProps) {
|
|
35
|
+
super(parent, id, props)
|
|
36
|
+
this.props = props
|
|
37
|
+
this.id = id
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* @summary Initialise and provision resources
|
|
42
|
+
*/
|
|
43
|
+
protected initResources() {
|
|
44
|
+
this.resolveZone()
|
|
45
|
+
this.createProject()
|
|
46
|
+
this.createDomain()
|
|
47
|
+
this.createRecord()
|
|
48
|
+
this.deploySite()
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* @summary Resolve the zone to use for the static site
|
|
53
|
+
*/
|
|
54
|
+
protected resolveZone() {
|
|
55
|
+
if (this.props.useExistingZone) {
|
|
56
|
+
this.siteZone = this.zoneManager.resolveZone(`${this.id}-zone`, this)
|
|
57
|
+
} else {
|
|
58
|
+
this.siteZone = this.zoneManager.createZone(`${this.id}-zone`, this, this.props.siteZone)
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* @summary Create the pages project
|
|
64
|
+
*/
|
|
65
|
+
protected createProject() {
|
|
66
|
+
this.sitePagesProject = this.pageManager.createPagesProject(
|
|
67
|
+
`${this.id}-site-project`,
|
|
68
|
+
this,
|
|
69
|
+
this.props.sitePagesProject
|
|
70
|
+
)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @summary Create the pages domain
|
|
75
|
+
*/
|
|
76
|
+
protected createDomain() {
|
|
77
|
+
this.sitePagesDomain = this.pageManager.createPagesDomain(`${this.id}-site-domain`, this, {
|
|
78
|
+
accountId: this.props.accountId,
|
|
79
|
+
domain: `${this.props.siteSubDomain}.${this.props.domainName}`,
|
|
80
|
+
projectName: this.sitePagesProject.name,
|
|
81
|
+
})
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* @summary Create the pages cname record
|
|
86
|
+
*/
|
|
87
|
+
protected createRecord() {
|
|
88
|
+
this.sitePagesCnameRecord = this.recordManager.createRecord(`${this.id}-site-record`, this, {
|
|
89
|
+
...this.props.siteCnameRecord,
|
|
90
|
+
name: this.props.siteSubDomain,
|
|
91
|
+
value: `${this.sitePagesProject.name}.pages.dev`,
|
|
92
|
+
})
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @summary Deploy the pages project
|
|
97
|
+
*/
|
|
98
|
+
protected deploySite() {
|
|
99
|
+
this.pageManager.deployPagesProject(`${this.id}-deploy`, this, {
|
|
100
|
+
branch: this.props.siteBranch ?? 'main',
|
|
101
|
+
directory: this.props.siteAssetDir,
|
|
102
|
+
message: this.props.siteDeployMessage,
|
|
103
|
+
projectName: this.sitePagesProject.name,
|
|
104
|
+
})
|
|
105
|
+
}
|
|
106
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { CommonCloudflareStackProps } from '../../common'
|
|
2
|
+
import { PagesProjectProps, RecordProps, ZoneProps } from '../../services'
|
|
3
|
+
|
|
4
|
+
export interface CloudflarePagesStaticSiteProps extends CommonCloudflareStackProps {
|
|
5
|
+
siteAssetDir: string
|
|
6
|
+
siteBranch?: string
|
|
7
|
+
siteCnameRecord: RecordProps
|
|
8
|
+
siteDeployMessage: string
|
|
9
|
+
sitePagesProject: PagesProjectProps
|
|
10
|
+
siteSubDomain: string
|
|
11
|
+
siteZone: ZoneProps
|
|
12
|
+
}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
+
import { PageRule } from '@cdktf/provider-cloudflare/lib/page-rule'
|
|
1
2
|
import { PagesDomain } from '@cdktf/provider-cloudflare/lib/pages-domain'
|
|
2
3
|
import { PagesProject } from '@cdktf/provider-cloudflare/lib/pages-project'
|
|
4
|
+
import { LocalExec, Provider } from 'cdktf-local-exec'
|
|
3
5
|
import { CommonCloudflareConstruct } from '../../common'
|
|
4
6
|
import { createCloudflareTfOutput } from '../../utils'
|
|
5
|
-
import { PageRuleProps, PagesDomainProps, PagesProjectProps } from './types'
|
|
6
|
-
import { PageRule } from '@cdktf/provider-cloudflare/lib/page-rule'
|
|
7
|
+
import { PageRuleProps, PagesDomainProps, PagesProjectDeployProps, PagesProjectProps } from './types'
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
10
|
* @classdesc Provides operations on Cloudflare Pages
|
|
@@ -91,4 +92,18 @@ export class CloudflarePageManager {
|
|
|
91
92
|
|
|
92
93
|
return pageRule
|
|
93
94
|
}
|
|
95
|
+
|
|
96
|
+
public deployPagesProject(id: string, scope: CommonCloudflareConstruct, props: PagesProjectDeployProps) {
|
|
97
|
+
if (!props) throw `Props undefined for ${id}`
|
|
98
|
+
|
|
99
|
+
const localExecProvider = new Provider(scope, `${id}`)
|
|
100
|
+
const branch = scope.isProductionStage() ? 'main' : props.branch
|
|
101
|
+
const message = process.env.BUILD_NUMBER ?? props.message
|
|
102
|
+
const deployment = new LocalExec(scope, `${id}-deploy-${new Date().toISOString()}`, {
|
|
103
|
+
command: `CLOUDFLARE_ACCOUNT_ID=${scope.props.accountId} CLOUDFLARE_API_TOKEN=${scope.props.apiToken} npx wrangler pages deploy ${props.directory} --project-name=${props.projectName} --branch=${props.branch} --commit-message=${message}`,
|
|
104
|
+
cwd: '',
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
return deployment
|
|
108
|
+
}
|
|
94
109
|
}
|
|
@@ -5,3 +5,9 @@ import { PagesProjectConfig } from '@cdktf/provider-cloudflare/lib/pages-project
|
|
|
5
5
|
export interface PagesProjectProps extends PagesProjectConfig {}
|
|
6
6
|
export interface PagesDomainProps extends PagesDomainConfig {}
|
|
7
7
|
export interface PageRuleProps extends PageRuleConfig {}
|
|
8
|
+
export interface PagesProjectDeployProps {
|
|
9
|
+
branch: string
|
|
10
|
+
directory: string
|
|
11
|
+
message: string
|
|
12
|
+
projectName: string
|
|
13
|
+
}
|
|
@@ -60,13 +60,11 @@ export class CloudflareZoneManager {
|
|
|
60
60
|
return zone
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
public resolveZone(id: string, scope: CommonCloudflareConstruct, options
|
|
64
|
-
if (!options) throw `Options undefined for ${id}`
|
|
65
|
-
|
|
63
|
+
public resolveZone(id: string, scope: CommonCloudflareConstruct, options?: ZoneOptions) {
|
|
66
64
|
const zone = new DataCloudflareZone(scope, `${id}-data-zone`, {
|
|
67
65
|
accountId: scope.props.accountId,
|
|
68
|
-
name: options
|
|
69
|
-
zoneId: options
|
|
66
|
+
name: options?.name ?? scope.props.domainName,
|
|
67
|
+
zoneId: options?.id,
|
|
70
68
|
})
|
|
71
69
|
|
|
72
70
|
return zone
|