Skip to content

Commit

Permalink
fix: laravel support no migration
Browse files Browse the repository at this point in the history
  • Loading branch information
yugasun committed Dec 4, 2020
1 parent 9fa6c13 commit 7c92990
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 100 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ jobs:
run: |
npm update --no-save
npm update --save-dev --no-save
- name: Running integration tests
- name: Running tests
run: npm run test
env:
TENCENT_SECRET_ID: ${{ secrets.TENCENT_SECRET_ID }}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Serverless Framework Component

[![Build Status](https://github.com/serverless-plus/tencent-framework/workflows/Release/badge.svg?branch=master)](https://github.com/serverless-plus/tencent-framework/actions?query=workflow:Release+branch:master)
[![Build Status](https://github.com/serverless-plus/tencent-framework/workflows/Test/badge.svg)](https://github.com/serverless-plus/tencent-framework/actions?query=workflow:Test)

> 此组件非腾讯云官方组件,很多特性是实验性的。如果有相关疑问,请提交 issue 或者 pr。
Expand Down
2 changes: 0 additions & 2 deletions examples/laravel/bootstrap/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
$_ENV['APP_BASE_PATH'] ?? dirname(__DIR__)
);

$app->useStoragePath(env('APP_STORAGE', '/tmp'));

/*
|--------------------------------------------------------------------------
| Bind Important Interfaces
Expand Down
Binary file modified examples/laravel/public/favicon.ico
Binary file not shown.
6 changes: 3 additions & 3 deletions examples/laravel/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ inputs:
faas:
name: ${name}
runtime: Php7
environment:
variables:
APP_ENV: production
environments:
- key: APP_ENV
value: production
apigw:
protocols:
- http
Expand Down
30 changes: 22 additions & 8 deletions serverless.component.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: framework
version: 0.1.5
version: 0.1.6
author: Serverless Plus
org: Serverless Plus
description: Deploy a serverless web framework application on Tencent SCF and API Gateway.
Expand Down Expand Up @@ -45,7 +45,7 @@ actions:
type: string
default: ap-guangzhou
description: Region for faas
allow: # The values that are allowed for this
allow:
- ap-guangzhou
- ap-shanghai
- ap-hongkong
Expand Down Expand Up @@ -87,12 +87,26 @@ actions:
type: string
default: 'index.main_handler'
description: The handler of faas
environment:
type: object
description: faas environment
keys:
variables:
type: object
tags:
type: array
description: faas tags
items:
- type: object
keys:
key:
type: string
value:
type: string
environments:
type: array
description: faas environments
items:
- type: object
keys:
key:
type: string
value:
type: string
vpc:
type: object
keys:
Expand Down
41 changes: 39 additions & 2 deletions src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,16 @@ const frameworks = {
runtime: 'Nodejs10.15',
defaultEntryFile: 'sls.js',
defaultStatics: [{ src: 'public', targetDir: '/' }],
EGG_APP_CONFIG: '{"rundir":"/tmp","logger":{"dir":"/tmp"}}'
defaultEnvs: [
{
key: 'SERVERLESS',
value: '1'
},
{
key: 'EGG_APP_CONFIG',
value: '{"rundir":"/tmp","logger":{"dir":"/tmp"}'
}
]
},
nest: {
injectSlsSdk: true,
Expand Down Expand Up @@ -56,7 +65,29 @@ const frameworks = {
injectSlsSdk: false,
templateUrl:
'https://serverless-templates-1300862921.cos.ap-beijing.myqcloud.com/laravel-demo.zip',
runtime: 'Php7'
runtime: 'Php7',
defaultEnvs: [
{
key: 'SERVERLESS',
value: '1'
},
{
key: 'VIEW_COMPILED_PATH',
value: '/tmp/storage/framework/views'
},
{
key: 'SESSION_DRIVER',
value: 'array'
},
{
key: 'LOG_CHANNEL',
value: 'stderr'
},
{
key: 'APP_STORAGE',
value: '/tmp'
}
]
},
thinkphp: {
injectSlsSdk: false,
Expand Down Expand Up @@ -88,6 +119,12 @@ const CONFIGS = {
timeout: 10,
memorySize: 128,
namespace: 'default',
defaultEnvs: [
{
key: 'SERVERLESS',
value: '1'
}
],
cos: {
lifecycle: [
{
Expand Down
2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"adm-zip": "^0.4.16",
"download": "^8.0.0",
"fs-extra": "^9.0.1",
"tencent-component-toolkit": "^1.18.7",
"tencent-component-toolkit": "^1.19.4",
"type": "^2.0.0"
}
}
113 changes: 31 additions & 82 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,89 +347,51 @@ const initializeStaticCdnInputs = async (instance, inputs, origin) => {

// compatible code for old configs
// transfer yaml config to sdk inputs
const yamlToSdkInputs = ({ instance, sourceInputs, faasConfig, apigwConfig }) => {
const yamlToSdkInputs = ({ instance, faasConfig, apigwConfig }) => {
const { framework, state, CONFIGS } = instance
// chenck state function name
const stateFaasName = state.faas && state.faas.name
const { functionConf = {}, apigatewayConf = {} } = sourceInputs
// transfer faas config
faasConfig.name =
faasConfig.name ||
sourceInputs.functionName ||
stateFaasName ||
getDefaultFunctionName(framework)

if (faasConfig.environments) {
if (framework === 'egg') {
faasConfig.environments.push({
envKey: 'EGG_APP_CONFIG',
envVal: CONFIGS.EGG_APP_CONFIG
})
}
// this is new config array to object
const environment = deepClone(faasConfig.environments)
if (getType(environment) === 'Array') {
faasConfig.environment = {
variables: {
SERVERLESS: '1',
SLS_ENTRY_FILE: instance.slsEntryFile
}
}
environment.forEach((item) => {
faasConfig.environment.variables[item.envKey] = item.envVal
})
} else {
faasConfig.environment = {
variables: environment.variables || {}
}
faasConfig.environment.variables.SERVERLESS = '1'
faasConfig.environment.variables.SLS_ENTRY_FILE = instance.slsEntryFile
}
} else {
faasConfig.environment = {
variables: {
SERVERLESS: '1',
SLS_ENTRY_FILE: instance.slsEntryFile,
EGG_APP_CONFIG: CONFIGS.EGG_APP_CONFIG
}
}
faasConfig.name = faasConfig.name || stateFaasName || getDefaultFunctionName(framework)

const { defaultEnvs } = CONFIGS
faasConfig.environments = (faasConfig.environments || [])
.concat(defaultEnvs)
.concat([{ key: 'SLS_ENTRY_FILE', value: instance.slsEntryFile }])
const environments = deepClone(faasConfig.environments)

faasConfig.environment = {
variables: {}
}
environments.forEach((item) => {
faasConfig.environment.variables[item.key] = item.value
})

if (faasConfig.vpc || functionConf.vpcConfig) {
faasConfig.vpcConfig = faasConfig.vpc || functionConf.vpcConfig
if (faasConfig.vpc) {
faasConfig.vpcConfig = faasConfig.vpc
}

if (faasConfig.tags) {
const tags = deepClone(faasConfig.tags)
if (getType(tags) === 'Array') {
faasConfig.tags = {}
tags.forEach((item) => {
faasConfig.tags[item.tagKey] = item.tagVal
})
}
faasConfig.tags = {}
tags.forEach((item) => {
faasConfig.tags[item.key] = item.value
})
}

faasConfig.layers = faasConfig.layers || sourceInputs.layers || []

// transfer apigw config
const stateApigwId = state.apigw && state.apigw.id
apigwConfig.serviceId =
apigwConfig.serviceId || apigatewayConf.serviceId || sourceInputs.serviceId || stateApigwId
apigwConfig.serviceName =
apigwConfig.serviceName ||
apigatewayConf.serviceName ||
sourceInputs.serviceName ||
getDefaultServiceName(instance)
apigwConfig.serviceDesc =
apigwConfig.serviceDesc || apigatewayConf.serviceDesc || getDefaultServiceDescription(instance)
apigwConfig.serviceId = apigwConfig.id || stateApigwId
apigwConfig.serviceName = apigwConfig.name || getDefaultServiceName(instance)
apigwConfig.serviceDesc = apigwConfig.description || getDefaultServiceDescription(instance)

apigwConfig.endpoints = [
{
path: '/',
apiName: 'index',
method: 'ANY',
enableCORS: apigwConfig.cors || apigatewayConf.enableCORS,
serviceTimeout: apigwConfig.timeout || apigatewayConf.serviceTimeout,
enableCORS: apigwConfig.cors,
serviceTimeout: apigwConfig.timeout,
function: {
isIntegratedResponse: true,
functionQualifier: apigwConfig.qualifier || '$DEFAULT',
Expand All @@ -441,10 +403,6 @@ const yamlToSdkInputs = ({ instance, sourceInputs, faasConfig, apigwConfig }) =>

if (apigwConfig.customDomains && apigwConfig.customDomains.length > 0) {
apigwConfig.customDomains = apigwConfig.customDomains.map((item) => {
if (item.certificateId) {
// old config, directly return
return item
}
return {
domain: item.domain,
certificateId: item.certId,
Expand All @@ -462,28 +420,23 @@ const initializeInputs = async (instance, inputs = {}) => {
const { CONFIGS, framework } = instance
const region = inputs.region || CONFIGS.region

const tempFaasConfig = inputs.faas || inputs.functionConf || {}
const tempFaasConfig = inputs.faas || {}
const faasConfig = Object.assign(tempFaasConfig, {
region: region,
code: {
src: inputs.src,
bucket: inputs.srcOriginal && inputs.srcOriginal.bucket,
object: inputs.srcOriginal && inputs.srcOriginal.object
},
name: tempFaasConfig.name,
role: tempFaasConfig.role || '',
handler: tempFaasConfig.handler || CONFIGS.handler,
runtime: tempFaasConfig.runtime || CONFIGS.runtime,
namespace: tempFaasConfig.namespace || CONFIGS.namespace,
description: tempFaasConfig.description || CONFIGS.description,
layers: tempFaasConfig.layers,
cfs: tempFaasConfig.cfs || [],
timeout: tempFaasConfig.timeout || CONFIGS.timeout,
memorySize: tempFaasConfig.memorySize || CONFIGS.memorySize,
environments: tempFaasConfig.environments || tempFaasConfig.environment,
tags: tempFaasConfig.tags || inputs.tags,
publish: inputs.publish,
traffic: inputs.traffic
layers: tempFaasConfig.layers || [],
cfs: tempFaasConfig.cfs || []
})

// validate traffic
Expand All @@ -495,21 +448,17 @@ const initializeInputs = async (instance, inputs = {}) => {
const slsEntryFile = inputs.entryFile || CONFIGS.defaultEntryFile
instance.slsEntryFile = slsEntryFile

const tempApigwConfig = inputs.apigw || inputs.apigatewayConf || {}
const tempApigwConfig = inputs.apigw || {}
const apigwConfig = Object.assign(tempApigwConfig, {
region,
isDisabled: tempApigwConfig.isDisabled === true,
serviceId: tempApigwConfig.id,
serviceName: tempApigwConfig.name,
serviceDesc: tempApigwConfig.description,
protocols: tempApigwConfig.protocols || ['http'],
environment: tempApigwConfig.environment || 'release',
customDomains: tempApigwConfig.customDomains
environment: tempApigwConfig.environment || 'release'
})

return {
region,
...yamlToSdkInputs({ instance, sourceInputs: inputs, faasConfig, apigwConfig })
...yamlToSdkInputs({ instance, faasConfig, apigwConfig })
}
}

Expand Down

0 comments on commit 7c92990

Please sign in to comment.