Skip to content

Commit

Permalink
feat: yml支持job镜像配置&修复cfs找不到挂载点
Browse files Browse the repository at this point in the history
  • Loading branch information
wangpand0508 committed Apr 22, 2024
1 parent 83943c1 commit 5be8a71
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 2 deletions.
17 changes: 17 additions & 0 deletions src/modules/apigw/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,23 @@ export default class Apigw {
outputs.usagePlan = usagePlan;
}

try {
const { tags } = inputs;
if (tags) {
await this.tagClient.deployResourceTags({
tags: tags.map(({ key, value }) => ({ TagKey: key, TagValue: value })),
resourceId: serviceId,
serviceType: ApiServiceType.apigw,
resourcePrefix: 'service',
});
if (tags.length > 0) {
outputs.tags = tags;
}
}
} catch (e) {
console.log(`[TAG] ${e.message}`);
}

// return this.formatApigwOutputs(outputs);
return outputs;
}
Expand Down
1 change: 0 additions & 1 deletion src/modules/scf/constants.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export const WebServerImageDefaultPort = 9000;

export const YunTiTagDocHref = 'https://doc.weixin.qq.com/doc/w3_AQ8AWgYkAOEEeD1cr34R7S66r8ONY?scode=AJEAIQdfAAoiSWrYcZAOMAswb5AFM';
7 changes: 7 additions & 0 deletions src/modules/scf/interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export interface FunctionCode {
RegistryId?: string;
Command?: string;
Args?: string;
ContainerImageAccelerate?: boolean;
ImagePort?: number;
};
}

Expand Down Expand Up @@ -203,6 +205,7 @@ export interface ScfCreateFunctionInputs {

cfs?: {
cfsId: string;
mountInsId?: string;
MountInsId?: string;
localMountDir: string;
remoteMountDir: string;
Expand All @@ -228,6 +231,10 @@ export interface ScfCreateFunctionInputs {
command?: string;
// 启动命令参数
args?: string;
// 是否开启镜像加速
containerImageAccelerate?: boolean;
// 监听端口: -1 表示job镜像,0~65535 表示Web Server镜像
imagePort?: number;
};

// 异步调用重试配置
Expand Down
17 changes: 16 additions & 1 deletion src/modules/scf/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { WebServerImageDefaultPort } from './constants';
import { ScfCreateFunctionInputs, BaseFunctionConfig, ProtocolParams } from './interface';
const CONFIGS = require('./config').default;

Expand Down Expand Up @@ -52,6 +53,20 @@ export const formatInputs = (inputs: ScfCreateFunctionInputs) => {
if (imageConfig.args) {
functionInputs.Code!.ImageConfig!.Args = imageConfig.args;
}
// 镜像加速
if (imageConfig.containerImageAccelerate !== undefined) {
functionInputs.Code!.ImageConfig!.ContainerImageAccelerate =
imageConfig.containerImageAccelerate;
}
// 监听端口: -1 表示 job镜像,0 ~ 65526 表示webServer镜像
if (imageConfig.imagePort) {
functionInputs.Code!.ImageConfig!.ImagePort =
Number.isInteger(imageConfig?.imagePort) &&
imageConfig?.imagePort >= -1 &&
imageConfig?.imagePort <= 65535
? imageConfig.imagePort
: WebServerImageDefaultPort;
}
} else {
// 基于 COS 代码部署
functionInputs.Code = {
Expand Down Expand Up @@ -149,7 +164,7 @@ export const formatInputs = (inputs: ScfCreateFunctionInputs) => {
inputs.cfs.forEach((item) => {
functionInputs.CfsConfig?.CfsInsList.push({
CfsId: item.cfsId,
MountInsId: item.MountInsId || item.cfsId,
MountInsId: item.mountInsId || item.MountInsId || item.cfsId,
LocalMountDir: item.localMountDir,
RemoteMountDir: item.remoteMountDir,
UserGroupId: String(item.userGroupId || 10000),
Expand Down

0 comments on commit 5be8a71

Please sign in to comment.