Skip to content

Commit

Permalink
fix:provisionConfig support defaultTarget and deploy cn-shanghai-fina…
Browse files Browse the repository at this point in the history
…nce-1
  • Loading branch information
mozhou52 committed Dec 12, 2024
1 parent f4d2c7a commit f052302
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 12 deletions.
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"license": "ISC",
"dependencies": {
"@alicloud/fc2": "^2.6.6",
"@alicloud/fc20230330": "^4.1.4",
"@alicloud/fc20230330": "^4.1.5",
"@alicloud/pop-core": "^1.7.13",
"@serverless-cd/srm-aliyun-pop-core": "^0.0.7-beta.16",
"@serverless-cd/srm-aliyun-ram20150501": "^0.0.2-beta.9",
Expand Down
3 changes: 2 additions & 1 deletion src/interface/cli-config/provision.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ export interface IProvision {
alwaysAllocateGPU?: boolean;
scheduledActions?: IProvisionScheduledAction[];
targetTrackingPolicies?: IProvisionTargetTrackingPolicy[];
target: number;
target?: number;
defaultTarget?: number;
}

export interface IProvisionScheduledAction {
Expand Down
1 change: 1 addition & 0 deletions src/interface/region.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ enum Region {
'ap-south-1' = 'ap-south-1',
'cn-heyuan-acdr-1' = 'cn-heyuan-acdr-1',
'cn-wulanchabu' = 'cn-wulanchabu',
'cn-shanghai-finance-1' = 'cn-shanghai-finance-1'
}

export type IRegion = `${Region}`;
Expand Down
8 changes: 7 additions & 1 deletion src/resources/fc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,13 @@ export default class FC extends FC_Client {
if (this.customEndpoint) {
ossEndpoint = `oss-${this.region}.aliyuncs.com`;
}

if (this.region === 'cn-shanghai-finance-1') {
if (process.env.FC_REGION === this.region) {
ossEndpoint = `oss-${this.region}-pub-internal.aliyuncs.com`;
} else {
ossEndpoint = `oss-${this.region}-pub.aliyuncs.com`;
}
}
logger.debug(`Uploading code to ${ossEndpoint}`);

const ossClient = new OSS({
Expand Down
9 changes: 7 additions & 2 deletions src/subCommands/provision/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default class Provision {
private scheduledActions: string;
private targetTrackingPolicies: string;
private target: number;
private defaultTarget: number;
private qualifier: string;

constructor(inputs: IInputs) {
Expand All @@ -35,6 +36,7 @@ export default class Provision {
'function-name',
'region',
'target',
'default-target',
'qualifier',
'scheduled-actions',
'target-tracking-policies',
Expand All @@ -51,6 +53,7 @@ export default class Provision {
'function-name': functionName,
qualifier,
target,
'default-target': defaultTarget,
region,
'assume-yes': yes,
_: subCommands,
Expand Down Expand Up @@ -79,6 +82,7 @@ export default class Provision {
this.scheduledActions = scheduledActions;
this.targetTrackingPolicies = targetTrackingPolicies;
this.target = target ? Number(target) : undefined;
this.defaultTarget = defaultTarget ? Number(defaultTarget) : undefined;

this.fcSdk = new FC(this.region, inputs.credential, {
endpoint: inputs.props.endpoint,
Expand All @@ -105,14 +109,15 @@ export default class Provision {
throw new Error('Qualifier not specified, please specify --qualifier');
}

if (!_.isNumber(this.target)) {
if (!_.isNumber(this.defaultTarget || this.target)) {
throw new Error(
`Target must be a number, got ${this.target}. Please specify a number through --target <number>`,
`Target or defaultTarget must be a number, got ${this.target}. Please specify a number through --target <number>`,
);
}

const config: IProvision = {
target: this.target,
defaultTarget: this.defaultTarget,
alwaysAllocateCPU: _.isBoolean(this.alwaysAllocateCPU) ? this.alwaysAllocateCPU : false,
alwaysAllocateGPU: _.isBoolean(this.alwaysAllocateGPU) ? this.alwaysAllocateGPU : false,
scheduledActions: [],
Expand Down

0 comments on commit f052302

Please sign in to comment.