Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ __tests__/e2e/custom.debian10/python/code/python
__tests__/e2e/custom/python/code/python
__tests__/e2e/python/code/python
__tests__/e2e/python/code/apt-archives
__tests__/e2e/apt/code/package-lock.json

.env_test
51 changes: 0 additions & 51 deletions __tests__/e2e/apt/code/package-lock.json

This file was deleted.

3 changes: 2 additions & 1 deletion __tests__/ut/interface_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
IHttpTriggerConfig,
checkRegion,
IRegion,
RegionList,
} from '../../src/interface';
import log from '../../src/logger';
log._set(console);
Expand Down Expand Up @@ -215,11 +214,13 @@ describe('checkRegion', () => {
);
});

/*
it('should throw an error if region is invalid', () => {
expect(() => checkRegion('invalid-region' as IRegion)).toThrow(
`Invalid region, The allowed regions are ${RegionList}`,
);
});
*/

it('should true when r is cn-hangzhou', () => {
const result = checkRegion('cn-hangzhou');
Expand Down
11 changes: 8 additions & 3 deletions src/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import FC from './resources/fc';
import { ICredentials } from '@serverless-devs/component-interface';
import Role, { RamClient } from './resources/ram';
import { TriggerType } from './interface/base';
import { isAuto } from './utils';
import { isAuto, isAppCenter } from './utils';

export default class Base {
commands: any;
Expand All @@ -28,7 +28,12 @@ export default class Base {

// 在运行方法之前运行
async handlePreRun(inputs: IInputs, needCredential: boolean) {
log.debug(`input: ${JSON.stringify(inputs)}`);
log.info(`userAgent: ${inputs.userAgent}`);
if (isAppCenter()) {
log.info(`input: ${JSON.stringify(inputs)}`);
} else {
log.debug(`input: ${JSON.stringify(inputs)}`);
}
// fc组件镜像 trim 左右空格
const image = _.get(inputs, 'props.customContainerConfig.image');
if (!_.isEmpty(image)) {
Expand Down Expand Up @@ -67,7 +72,7 @@ export default class Base {
FC.isCustomContainerRuntime(inputs.props.runtime) &&
!IMAGE_ACCELERATION_REGION.includes(inputs.props.region)
) {
throw new Error(
log.warn(
`The region ${inputs.props.region} does not support custom container image acceleration, please use another region, details: https://help.aliyun.com/zh/fc/product-overview/region-availability`,
);
}
Expand Down
4 changes: 3 additions & 1 deletion src/interface/region.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import logger from '../logger';

enum Region {
'cn-hangzhou' = 'cn-hangzhou',
'cn-shanghai' = 'cn-shanghai',
Expand Down Expand Up @@ -36,7 +38,7 @@ export function checkRegion(r: IRegion): boolean {
throw new Error('Region not specified, please specify --region');
}
if (!RegionList.includes(r)) {
throw new Error(`Invalid region, The allowed regions are ${RegionList}`);
logger.warn(`Invalid region, The allowed regions are ${RegionList}`);
}
return true;
}
16 changes: 12 additions & 4 deletions src/resources/fc/impl/replace-function-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ export default function (_local: any, _remote: any) {
// 适配钩子函数配置
if (!(_.isEmpty(local?.instanceLifecycleConfig) && _.isEmpty(remote?.instanceLifecycleConfig))) {
const { initializer, preStop } = local.instanceLifecycleConfig || {};
if (initializer?.handler && initializer?.command && !_.isEmpty(initializer?.command)) {
if (initializer?.handler && initializer?.command && !_.isEmpty(initializer?.command)) {
throw new Error(
'fc3 pre check: command and handler can not be set at the same time in lifecycle Lifecycle.Initializer',
);
}
if (preStop?.handler && preStop?.command && !_.isEmpty(preStop?.command)) {
if (preStop?.handler && preStop?.command && !_.isEmpty(preStop?.command)) {
throw new Error(
'fc3 pre check: command and handler can not be set at the same time in lifecycle Lifecycle.PreStop',
);
Expand All @@ -109,7 +109,11 @@ export default function (_local: any, _remote: any) {
remote?.instanceLifecycleConfig?.initializer?.timeout
) {
if (initializer?.handler || (initializer?.command && !_.isEmpty(initializer.command))) {
if (remote?.instanceLifecycleConfig?.initializer?.handler && (initializer?.command && !_.isEmpty(initializer.command))) {
if (
remote?.instanceLifecycleConfig?.initializer?.handler &&
initializer?.command &&
!_.isEmpty(initializer.command)
) {
_.set(local, 'instanceLifecycleConfig.initializer.handler', '');
}
if (remote?.instanceLifecycleConfig?.initializer?.command && initializer?.handler) {
Expand All @@ -134,7 +138,11 @@ export default function (_local: any, _remote: any) {
remote?.instanceLifecycleConfig?.preStop?.timeout
) {
if (preStop?.handler || (preStop?.command && !_.isEmpty(preStop.command))) {
if (remote?.instanceLifecycleConfig?.preStop?.handler && (preStop?.command && !_.isEmpty(preStop.command))) {
if (
remote?.instanceLifecycleConfig?.preStop?.handler &&
preStop?.command &&
!_.isEmpty(preStop.command)
) {
_.set(local, 'instanceLifecycleConfig.preStop.handler', '');
}
if (remote?.instanceLifecycleConfig?.preStop?.command && preStop?.handler) {
Expand Down
3 changes: 3 additions & 0 deletions src/resources/fc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,9 @@ export default class FC extends FC_Client {
if (this.region === 'cn-heyuan-acdr-1') {
ossEndpoint = `oss-${this.region}-internal.aliyuncs.com`;
}
if (process.env.FC_CODE_TEMP_OSS_ENDPOINT) {
ossEndpoint = process.env.FC_CODE_TEMP_OSS_ENDPOINT;
}
logger.debug(`Uploading code to ${ossEndpoint}`);

const ossClient = new OSS({
Expand Down