Skip to content

Commit

Permalink
feat: deploy action create lambda OK
Browse files Browse the repository at this point in the history
Signed-off-by: seven <[email protected]>
  • Loading branch information
Blankll committed Sep 21, 2024
1 parent cd0a587 commit 533f1c0
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 59 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/coverage/
/.vscode/
.DS_Store
/artifacts/
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,17 @@
.prettierrc
jest.config.js
tsconfig.json
Dockerfile

.idea/
.github/
.husky/
coverage/
src/
tests/
docs/
artifacts/
scripts/
# Ignore all .d.ts files except index.d.ts
*.d.ts
!index.d.ts
Expand Down
4 changes: 2 additions & 2 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
@@ -1,6 +1,6 @@
{
"name": "@geek-fun/serverlessinsight",
"version": "0.0.1",
"version": "0.0.2",
"description": "Full life cycle cross providers serverless application management for your fast-growing business.",
"homepage": "https://serverlessinsight.geekfun.club",
"main": "dist/src/index.js",
Expand Down
1 change: 1 addition & 0 deletions src/common/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './provider';
export * from './logger';
export * from './getVersion';
export * from './rosClient';
export * from './actionContext';
2 changes: 1 addition & 1 deletion src/iac/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { validateYaml } from './iacSchema';

const mapToArr = (obj: Record<string, Record<string, unknown> | string>) => {
return Object.entries(obj).map(([key, value]) =>
typeof value === 'string' ? { [key]: value } : { id: key, ...value },
typeof value === 'string' ? { [key]: value } : { key, ...value },
);
};

Expand Down
28 changes: 0 additions & 28 deletions src/iac/resource.ts

This file was deleted.

57 changes: 37 additions & 20 deletions src/stack/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,49 @@ import * as ros from '@alicloud/ros-cdk-core';
import * as fc from '@alicloud/ros-cdk-fc';
import { ActionContext, ServerlessIac } from '../types';
import { printer, rosStackDeploy } from '../common';
import path from 'node:path';
import * as fs from 'node:fs';

const resolveCode = (location: string): string => {
const filePath = path.resolve(process.cwd(), location);
const fileContent = fs.readFileSync(filePath);

return fileContent.toString('base64');
};

export class IacStack extends ros.Stack {
constructor(scope: ros.Construct, iac: ServerlessIac, props?: ros.StackProps) {
super(scope, iac.service, props);
new ros.RosInfo(this, ros.RosInfo.description, 'This is the simple ros cdk app example.');
iac.functions.map(
(fnc) =>
new fc.RosFunction(
this,
fnc.name,
{
functionName: fnc.name,
serviceName: `${fnc.name}-service`,
handler: fnc.handler,
runtime: fnc.runtime,
memorySize: fnc.memory,
timeout: fnc.timeout,
environmentVariables: fnc.environment,
code: {
zipFile:
'exports.handler = function(event, context, callback) { callback(null, "Hello World"); }',
},
},
false,
),
const service = new fc.RosService(
this,
`${iac.service}-service`,
{
serviceName: `${iac.service}-service`,
},
true,
);

iac.functions.forEach((fnc) => {
const func = new fc.RosFunction(
this,
fnc.key,
{
functionName: fnc.name,
serviceName: service.serviceName,
handler: fnc.handler,
runtime: fnc.runtime,
memorySize: fnc.memory,
timeout: fnc.timeout,
environmentVariables: fnc.environment,
code: {
zipFile: resolveCode(fnc.code),
},
},
true,
);
func.addDependsOn(service);
});
}
}

Expand Down
9 changes: 3 additions & 6 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,17 @@ type Stages = {

export type IacFunction = {
name: string;
key: string;
runtime: string;
handler: string;
zip: string;
code: string;
memory: number;
timeout: number;
environment: {
[key: string]: string;
};
};

type Functions = {
[key: string]: IacFunction;
};

export type Event = {
type: string;
source: string;
Expand All @@ -50,7 +47,7 @@ export type RawServerlessIac = {
stages: Stages;
service: string;
tags: Tags;
functions: Functions;
functions: { [key: string]: IacFunction };
events: Events;
};

Expand Down
2 changes: 1 addition & 1 deletion tests/fixtures/serverless-insignt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ functions:
name: insight-poc-fn
runtime: nodejs14
handler: index.handler
code: artifact.zip
code: artifacts/artifact.zip
memory: 512
timeout: 10
environment:
Expand Down

0 comments on commit 533f1c0

Please sign in to comment.