Skip to content

Commit b96d863

Browse files
committed
fix: code objectkey value issue
Signed-off-by: seven <zilisheng1996@gmail.com>
1 parent 86f240f commit b96d863

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

src/common/iacHelper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export const getFileSource = (
2828

2929
const hash = crypto.createHash('md5').update(fs.readFileSync(filePath)).digest('hex');
3030

31-
const objectKey = `${fcName}/${hash}.${filePath.split('.').pop()}`;
32-
const source = ossDeployment.Source.asset(filePath, {}, objectKey);
31+
const objectKey = `${fcName}/${hash}-${filePath.split('/').pop()}`;
32+
const source = ossDeployment.Source.asset(filePath, {}, `${fcName}/${hash}-`);
3333

3434
return { source, objectKey };
3535
};

src/stack/rosStack/function.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ export const resolveFunctions = (
3131
});
3232

3333
let destinationBucket: oss.Bucket;
34+
let artifactsDeployment: ossDeployment.BucketDeployment;
3435
if (!isEmpty(fileSources)) {
3536
// creat oss to store code
3637
destinationBucket = new oss.Bucket(
@@ -42,7 +43,7 @@ export const resolveFunctions = (
4243
},
4344
true,
4445
);
45-
new ossDeployment.BucketDeployment(
46+
artifactsDeployment = new ossDeployment.BucketDeployment(
4647
scope,
4748
`${service}_artifacts_code_deployment`,
4849
{
@@ -55,18 +56,19 @@ export const resolveFunctions = (
5556
);
5657
}
5758
functions?.forEach((fnc) => {
59+
const storeInBucket = readCodeSize(fnc.code) > CODE_ZIP_SIZE_LIMIT;
5860
let code: RosFunction.CodeProperty = {
5961
zipFile: resolveCode(fnc.code),
6062
};
61-
if (readCodeSize(fnc.code) > CODE_ZIP_SIZE_LIMIT) {
63+
if (storeInBucket) {
6264
code = {
6365
ossBucketName: destinationBucket.attrName,
6466
ossObjectName: fileSources?.find(
6567
({ fcName }) => fcName === replaceReference(fnc.name, context),
6668
)?.objectKey,
6769
};
6870
}
69-
new fc.RosFunction(
71+
const fcn = new fc.RosFunction(
7072
scope,
7173
fnc.key,
7274
{
@@ -80,5 +82,9 @@ export const resolveFunctions = (
8082
},
8183
true,
8284
);
85+
if (storeInBucket) {
86+
fcn.addDependsOn(destinationBucket as unknown as ros.RosResource);
87+
fcn.addDependsOn(artifactsDeployment as unknown as ros.RosResource);
88+
}
8389
});
8490
};

tests/common/iacHelper.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ describe('Unit test for iacHelper', () => {
1919
expect(ossDeployment.Source.asset).toHaveBeenCalledWith(
2020
`${process.cwd()}/${location}`,
2121
{},
22-
`${fcName}/50861cd99a3a678356030f5f189300af.zip`,
22+
`${fcName}/50861cd99a3a678356030f5f189300af-`,
2323
);
2424
});
2525

tests/fixtures/deployFixture.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ export const largeCodeRos = {
641641
OssBucketName: {
642642
'Fn::GetAtt': ['my-demo-service_artifacts_bucket', 'Name'],
643643
},
644-
OssObjectName: 'hello_fn/43cb4c356149762dbe507fc1baede172.zip',
644+
OssObjectName: 'hello_fn/43cb4c356149762dbe507fc1baede172-large-artifact.zip',
645645
},
646646
EnvironmentVariables: {
647647
NODE_ENV: 'production',
@@ -689,7 +689,7 @@ export const largeCodeRos = {
689689
sources: [
690690
{
691691
bucket: { 'Fn::Sub': expect.stringContaining('assets-${ALIYUN::Region}') },
692-
fileName: 'hello_fn/43cb4c356149762dbe507fc1baede172.ziplarge-artifact.zip',
692+
fileName: 'hello_fn/43cb4c356149762dbe507fc1baede172-large-artifact.zip',
693693
objectKey: '2bfeafed8d3df0d44c235271cdf2aa7d908a3c2757af14a67d33d102847f46fd.zip',
694694
},
695695
],

0 commit comments

Comments
 (0)