Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add fc3-plugin #198

Merged
merged 4 commits into from
Nov 21, 2023
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
3 changes: 3 additions & 0 deletions configs/root-compilation.tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,9 @@
},
{
"path": "../packages/rpc-core/compile.tsconfig.json"
},
{
"path": "../plugins/fc3-plugin/compile.tsconfig.json"
}
]
}
10 changes: 10 additions & 0 deletions plugins/fc3-plugin/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/** @type {import('eslint').Linter.Config} */
module.exports = {
extends: [
require.resolve('@malagu/component/configs/build.eslintrc.json')
],
parserOptions: {
tsconfigRootDir: __dirname,
project: 'compile.tsconfig.json'
}
};
1 change: 1 addition & 0 deletions plugins/fc3-plugin/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Malagu - FC3 Plugin Component
22 changes: 22 additions & 0 deletions plugins/fc3-plugin/compile.tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"extends": "@malagu/component/configs/base.tsconfig.json",
"compilerOptions": {
"composite": true,
"rootDir": "src",
"outDir": "lib"
},
"include": [
"src"
],
"references": [
{
"path": "../cloud-plugin/compile.tsconfig.json"
},
{
"path": "../code-loader-plugin/compile.tsconfig.json"
},
{
"path": "../../dev-packages/cli-common/compile.tsconfig.json"
}
]
}
23 changes: 23 additions & 0 deletions plugins/fc3-plugin/malagu-http-mode.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
malagu:
cloud:
function:
runtime: custom
bootstrap: "${ startCommand ?: 'node backend/index.js'}"
trigger:
name: ${malagu.cloud.function.name}-${malagu.cloud.alias.name}
qualifier: ${malagu.cloud.alias.name}
triggerType: http
triggerConfig:
authType: anonymous
methods: [GET, POST, PUT, DELETE, HEAD, PATCH]
customDomain:
name: ${env.MALAGU_DOMAIN || 'auto'}
protocol: HTTP
certConfig:
# certName: xxx
privateKey: "${ env.SSL_KEY ?: 'ssl/domain.key'}"
certificate: "${ env.SSL_PEM ?: 'ssl/domain.pem'}"
routeConfig:
routes:
- path: '/*'
qualifier: ${malagu.cloud.alias.name}
15 changes: 15 additions & 0 deletions plugins/fc3-plugin/malagu-mns-topic-mode.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
malagu:
cloud:
function:
runtime: nodejs14
trigger:
name: ${malagu.cloud.function.name}-${malagu.cloud.alias.name}-mns_topic
qualifier: ${malagu.cloud.alias.name}
triggerType: mns_topic
# invocationRole: acs:ram::123456:role/app-mns-role
# sourceARN: acs:mns:cn-hangzhou:123456:/topics/test
triggerConfig:
# topicName: test-topic
notifyContentFormat: JSON
notifyStrategy: BACKOFF_RETRY
# filterTag: foo
9 changes: 9 additions & 0 deletions plugins/fc3-plugin/malagu-remote.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
mode: "${currentMode|toObjects[.item in [ 'http', 'api-gateway', 'sample-http', 'timer', 'mns-topic', 'event']]|suffix('-mode') || 'http-mode'}"
malagu:
cloud:
secure: true
internal: false
timeout: 600000
function:
instanceConcurrency: 10
withoutCodeLimit: true
22 changes: 22 additions & 0 deletions plugins/fc3-plugin/malagu-sample-http-mode.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
malagu:
cloud:
function:
runtime: nodejs14
trigger:
name: ${malagu.cloud.function.name}-${malagu.cloud.alias.name}
qualifier: ${malagu.cloud.alias.name}
triggerType: http
triggerConfig:
authType: anonymous
methods: [GET, POST, PUT, DELETE, HEAD, PATCH]
customDomain:
name: ${env.MALAGU_DOMAIN || 'auto'}
protocol: HTTP
certConfig:
# certName: xxx
privateKey: "${ env.SSL_KEY ?: 'ssl/domain.key'}"
certificate: "${ env.SSL_PEM ?: 'ssl/domain.pem'}"
routeConfig:
routes:
- path: '/*'
functionName: ${malagu.cloud.function.name}
13 changes: 13 additions & 0 deletions plugins/fc3-plugin/malagu-timer-mode.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
malagu:
cloud:
function:
runtime: nodejs14
trigger:
name: ${malagu.cloud.function.name}-${malagu.cloud.alias.name}-timer
qualifier: ${malagu.cloud.alias.name}
triggerType: timer
triggerConfig:
payload: malagu-timer
cronExpression: 0 */1 * * * * # every minute
enable: true

20 changes: 20 additions & 0 deletions plugins/fc3-plugin/malagu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
malagu:
cloud:
name: alibaba cloud
profilePath: alibaba/profile.yml
regions:
- cn-qingdao
- cn-beijing
- cn-zhangjiakou
- cn-hangzhou
- cn-shanghai
- cn-shenzhen
- cn-huhehaote
- cn-hongkong
- ap-southeast-1
- ap-southeast-2
- ap-northeast-1
- us-west-1
- us-east-1
- eu-central-1
- ap-south-1
54 changes: 54 additions & 0 deletions plugins/fc3-plugin/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
{
"name": "@malagu/fc3-plugin",
"version": "2.49.12",
"description": "",
"dependencies": {
"@alicloud/fc20230330": "^3.0.2",
"@alicloud/openapi-client": "^0.4.6",
"@alicloud/tea-util": "^1.4.7",
"@malagu/cli-common": "2.49.12",
"@malagu/cloud-plugin": "2.49.12",
"@malagu/code-loader-plugin": "2.49.12",
"axios": "^0.26.1",
"chalk": "^4.1.0",
"fs-extra": "^11.1.1",
"jszip": "^3.7.1"
},
"publishConfig": {
"access": "public"
},
"keywords": [
"malagu-component",
"malagu-plugin"
],
"license": "MIT",
"repository": {
"type": "git",
"url": "https://github.com/cellbang/malagu.git"
},
"bugs": {
"url": "https://github.com/cellbang/malagu/issues"
},
"homepage": "https://github.com/cellbang/malagu",
"files": [
"lib",
"src",
"malagu.yml",
"malagu-remote.yml",
"malagu-http-mode.yml",
"malagu-sample-http-mode.yml",
"malagu-timer-mode.yml",
"malagu-mns-topic-mode.yml"
],
"scripts": {
"lint": "malagu-component lint",
"build": "malagu-component build",
"watch": "malagu-component watch",
"clean": "malagu-component clean",
"test": "malagu-component test:js"
},
"devDependencies": {
"@malagu/component": "2.49.12"
},
"gitHead": "bbf636b21ea1a347affcc05a5f6f58b35bedef6d"
}
49 changes: 49 additions & 0 deletions plugins/fc3-plugin/src/hooks/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import axios from 'axios';
const DOMAIN = 'http://domain.devsapp.net';

export interface Params {
type: string;
user: string;
region: string;
function: string;
token?: string;
}

function checkRs(rs: any) {
if (rs.Status !== 'Success') {
throw new Error(rs.Body);
}
}

function parseParams(params: Params) {
const parsedParams = new URLSearchParams();
parsedParams.append('type', params.type);
parsedParams.append('region', params.region);
parsedParams.append('user', params.user);
parsedParams.append('function', params.function);
if (params.token) {
parsedParams.append('token', params.token);
}
return parsedParams;
}

function getCommonHeaders() {
return { 'Content-Type': 'application/x-www-form-urlencoded' };
}

export async function token(params: Params) {
const { data } = await axios.post(`${DOMAIN}/token`, parseParams(params), { headers: getCommonHeaders() });
checkRs(data.Response);
return data.Response;
}

export async function domain(params: Params) {
const { data } = await axios.post(`${DOMAIN}/domain`, parseParams(params), { headers: getCommonHeaders() });
checkRs(data.Response);
return data.Response;
}

export async function verify(params: Params) {
const { data } = await axios.post(`${DOMAIN}/verify`, parseParams(params), { headers: getCommonHeaders() });
return data.Response;
}
19 changes: 19 additions & 0 deletions plugins/fc3-plugin/src/hooks/build.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { BuildContext, PathUtil } from '@malagu/cli-common';
import { join } from 'path';
import { writeFile, ensureDir } from 'fs-extra';
import { CloudUtils } from '@malagu/cloud-plugin';
import { getCodeRootDir } from '@malagu/code-loader-plugin';

export default async (context: BuildContext) => {
const { cfg } = context;
const config = CloudUtils.getConfiguration(cfg);
const codeRootDir = getCodeRootDir(PathUtil.getProjectDistPath(), config.function.codeUri);
await ensureDir(codeRootDir);
if (config.function?.runtime === 'custom') {
const destDir = join(codeRootDir, 'bootstrap');
const bootstrap = config.function.bootstrap;
await writeFile(destDir, `#!/bin/bash\n${bootstrap}`, { mode: 0o755 });
}
delete config.function.bootstrap;

};
Loading
Loading