Skip to content

Commit 2d5e94e

Browse files
authored
Merge pull request #1010 from wss-git/wss/fix-customContainer-codeuri
Wss/fix custom container codeuri
2 parents 0637391 + 4529f1f commit 2d5e94e

12 files changed

Lines changed: 81 additions & 49 deletions

File tree

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@alicloud/fun",
3-
"version": "3.6.16",
3+
"version": "3.6.17",
44
"description": "(have)Fun with Serverless",
55
"engines": {
66
"node": ">=8.6.0"

src/bin/fun-package.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ program
1717
.option('-b, --oss-bucket <bucket>', 'The name of the oss bucket where Fun uploads local artifacts')
1818
.option('-o, --output-template-file <filename>', 'The output path of the packaged template file')
1919
.option('--use-nas', 'Automatically upload local resources to NAS.')
20+
.option('--push-registry <pushRegistry>', 'Modify the image upload path')
2021
.parse(process.argv);
2122

2223
if (program.args.length > 1) {

src/lib/build/template.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,21 @@ function updateTemplateResources(originTplContent, buildFuncs, skippedBuildFuncs
3737
const absCodeDir = path.resolve(baseDir, functionRes.Properties.CodeUri);
3838
const relativeCodeUri = path.relative(absRootArtifactsDir, absCodeDir);
3939

40-
functionRes.Properties.CodeUri = relativeCodeUri;
41-
40+
if (functionRes.Properties.Runtime === 'custom-container') {
41+
delete functionRes.Properties.CodeUri;
42+
} else {
43+
functionRes.Properties.CodeUri = relativeCodeUri;
44+
}
4245
} else { // refer to artifact dir
4346
const funcArtifactDir = path.join(rootArtifactsDir, serviceName, functionName);
4447
const absFuncArtifactDir = path.resolve(baseDir, funcArtifactDir);
4548
const relativeCodeUri = path.relative(absRootArtifactsDir, absFuncArtifactDir);
4649

47-
functionRes.Properties.CodeUri = relativeCodeUri;
50+
if (functionRes.Properties.Runtime === 'custom-container') {
51+
delete functionRes.Properties.CodeUri;
52+
} else {
53+
functionRes.Properties.CodeUri = relativeCodeUri;
54+
}
4855
}
4956
});
5057

src/lib/commands/package.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ async function pack(options) {
88
const bucket = options.ossBucket;
99
const useNas = options.useNas;
1010
const outputTemplateFile = options.outputTemplateFile;
11+
const pushRegistry = options.pushRegistry;
1112

1213
if (!tplPath) {
1314
tplPath = await detectTplPath();
@@ -19,7 +20,7 @@ async function pack(options) {
1920

2021
validateTplName(tplPath);
2122

22-
await require('../package/package').pack(tplPath, bucket, outputTemplateFile, useNas);
23+
await require('../package/package').pack(tplPath, bucket, outputTemplateFile, useNas, pushRegistry);
2324
}
2425

2526
module.exports = pack;

src/lib/deploy/deploy-by-tpl.js

Lines changed: 2 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const debug = require('debug')('fun:deploy');
1010
const definition = require('../definition');
1111
const date = require('date-and-time');
1212

13-
const { execSync } = require('child_process');
13+
const { getFunctionImage } = require('../package/pushImage');
1414
const { deployByRos } = require('./deploy-support-ros');
1515
const { importService } = require('../import/service');
1616
const { getProfile, mark } = require('../profile');
@@ -939,44 +939,6 @@ async function deployByApi(baseDir, tpl, tplPath, context) {
939939
}
940940
}
941941

942-
async function getpushRegistry(image, pushRegistry, region, configImage) {
943-
const imageArr = image.split('/');
944-
if (pushRegistry === 'acr-internet') {
945-
imageArr[0] = `registry.${region}.aliyuncs.com`;
946-
image = imageArr.join('/');
947-
} else if (pushRegistry === 'acr-vpc') {
948-
imageArr[0] = `registry-vpc.${region}.aliyuncs.com`;
949-
image = imageArr.join('/');
950-
} else if (pushRegistry) {
951-
imageArr[0] = pushRegistry;
952-
image = imageArr.join('/');
953-
}
954-
console.log(`docker tag ${configImage} ${image}`);
955-
execSync(`docker tag ${configImage} ${image}`, {
956-
stdio: 'inherit'
957-
});
958-
console.log(`docker push ${image}`);
959-
execSync(`docker push ${image}`, {
960-
stdio: 'inherit'
961-
});
962-
}
963-
964-
async function getFunctionImage({ tpl, pushRegistry, region }) {
965-
for (const k of _.keys(tpl)) {
966-
const v = tpl[k];
967-
if (_.isObject(v)) {
968-
if (v.Type === 'Aliyun::Serverless::Function') {
969-
const { CustomContainerConfig = {} } = v.Properties || {};
970-
let image = CustomContainerConfig.Image;
971-
if (image) {
972-
await getpushRegistry(image, pushRegistry, region, CustomContainerConfig.Image);
973-
}
974-
} else {
975-
await getFunctionImage({ tpl: v, pushRegistry, region });
976-
}
977-
}
978-
}
979-
}
980942

981943
async function deploy(tplPath, context) {
982944
if (!context.useRos) {
@@ -990,7 +952,7 @@ async function deploy(tplPath, context) {
990952
const profile = await getProfile();
991953

992954
if (context.pushRegistry) {
993-
getFunctionImage({ tpl, region: profile.defaultRegion, pushRegistry: context.pushRegistry });
955+
await getFunctionImage({ tpl, region: profile.defaultRegion, pushRegistry: context.pushRegistry });
994956
}
995957

996958
console.log(`using region: ${profile.defaultRegion}`);

src/lib/deploy/deploy-support-ros.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ async function detectRosHttpTrigger(rosResources) {
495495
continue;
496496
}
497497

498-
await trigger.displayTriggerInfo(serviceName, functionName, triggerName, triggerProp.TriggerType, triggerProperties);
498+
await trigger.displayTriggerInfo(serviceName, functionName, triggerName, triggerProp.TriggerType, triggerProperties, '', rosResources);
499499
}
500500
}
501501
}

src/lib/language-service/schema/rosSchema.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,9 @@ export const rosSchema = {
176176
},
177177
'required': ['Image']
178178
},
179+
"CodeUri": {
180+
"type": "string"
181+
},
179182
"Description": {
180183
"type": "string"
181184
},

src/lib/package/package.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const { showPackageNextTips } = require('../build/tips');
1818
const { ensureFilesModified } = require('../utils/file');
1919
const { parseMountDirPrefix } = require('../fc');
2020
const { getTpl, detectNasBaseDir, getNasYmlPath } = require('../tpl');
21+
const { getFunctionImage } = require('./pushImage');
2122
const { promptForConfirmContinue, promptForInputContinue } = require('../init/prompt');
2223
const { validateNasAndVpcConfig, SERVICE_RESOURCE, iterateResources, isNasAutoConfig, isVpcAutoConfig, getUserIdAndGroupId } = require('../definition');
2324

@@ -268,7 +269,7 @@ async function processOSSBucket(bucket) {
268269
return await generateOssBucket(bucket);
269270
}
270271

271-
async function pack(tplPath, bucket, outputTemplateFile, useNas) {
272+
async function pack(tplPath, bucket, outputTemplateFile, useNas, pushRegistry) {
272273
const tpl = await getTpl(tplPath);
273274
validateNasAndVpcConfig(tpl.Resources);
274275

@@ -281,6 +282,10 @@ async function pack(tplPath, bucket, outputTemplateFile, useNas) {
281282
const ossClient = await getOssClient(bucketName);
282283

283284
const updatedEnvTpl = await processNasPythonPaths(tpl, tplPath);
285+
if (pushRegistry) {
286+
const profile = await getProfile();
287+
await getFunctionImage({ tpl, region: profile.defaultRegion, pushRegistry });
288+
}
284289
const updatedCodeTpl = await uploadAndUpdateFunctionCode({ tpl: updatedEnvTpl, tplPath, baseDir, ossClient, useNas });
285290
const updatedSlsTpl = await transformSlsAuto(updatedCodeTpl);
286291
const updatedFlowTpl = await transformFlowDefinition(baseDir, transformCustomDomain(updatedSlsTpl));

src/lib/package/pushImage.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
const _ = require('lodash');
2+
const { execSync } = require('child_process');
3+
4+
async function getpushRegistry(image, pushRegistry, region, configImage) {
5+
const imageArr = image.split('/');
6+
if (pushRegistry === 'acr-internet') {
7+
imageArr[0] = `registry.${region}.aliyuncs.com`;
8+
image = imageArr.join('/');
9+
} else if (pushRegistry === 'acr-vpc') {
10+
imageArr[0] = `registry-vpc.${region}.aliyuncs.com`;
11+
image = imageArr.join('/');
12+
} else if (pushRegistry) {
13+
imageArr[0] = pushRegistry;
14+
image = imageArr.join('/');
15+
}
16+
console.log(`docker tag ${configImage} ${image}`);
17+
execSync(`docker tag ${configImage} ${image}`, {
18+
stdio: 'inherit'
19+
});
20+
console.log(`docker push ${image}`);
21+
execSync(`docker push ${image}`, {
22+
stdio: 'inherit'
23+
});
24+
}
25+
26+
async function getFunctionImage({ tpl, pushRegistry, region }) {
27+
for (const k of _.keys(tpl)) {
28+
const v = tpl[k];
29+
if (_.isObject(v)) {
30+
if (v.Type === 'Aliyun::Serverless::Function') {
31+
const { CustomContainerConfig = {} } = v.Properties || {};
32+
let image = CustomContainerConfig.Image;
33+
if (image) {
34+
await getpushRegistry(image, pushRegistry, region, CustomContainerConfig.Image);
35+
}
36+
} else {
37+
await getFunctionImage({ tpl: v, pushRegistry, region });
38+
}
39+
}
40+
}
41+
}
42+
43+
module.exports = {
44+
getFunctionImage, getpushRegistry
45+
};

0 commit comments

Comments
 (0)