diff --git a/packages/cloud-sdk/package-lock.json b/packages/cloud-sdk/package-lock.json index fd5ed97975..2154613fb0 100644 --- a/packages/cloud-sdk/package-lock.json +++ b/packages/cloud-sdk/package-lock.json @@ -1,12 +1,12 @@ { "name": "@lafjs/cloud", - "version": "1.0.0-beta.13", + "version": "1.0.0-beta.13-fix", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@lafjs/cloud", - "version": "1.0.0-beta.13", + "version": "1.0.0-beta.13-fix", "license": "ISC", "dependencies": { "@types/express": "^4.17.15", diff --git a/packages/cloud-sdk/package.json b/packages/cloud-sdk/package.json index 0b465369a8..addd654131 100644 --- a/packages/cloud-sdk/package.json +++ b/packages/cloud-sdk/package.json @@ -1,6 +1,6 @@ { "name": "@lafjs/cloud", - "version": "1.0.0-beta.13", + "version": "1.0.0-beta.13-fix", "description": "The cloud sdk for laf cloud function", "main": "dist/index.js", "scripts": { diff --git a/packages/cloud-sdk/src/cloud.ts b/packages/cloud-sdk/src/cloud.ts index d11b4cd07b..815d013e93 100644 --- a/packages/cloud-sdk/src/cloud.ts +++ b/packages/cloud-sdk/src/cloud.ts @@ -19,6 +19,10 @@ export class Cloud implements CloudSdkInterface { private _cloud: CloudSdkInterface private get cloud(): CloudSdkInterface { + if (globalThis.createCloudSdk && !Cloud.create) { + Cloud.create = globalThis.createCloudSdk + } + if (!this._cloud) { this._cloud = Cloud.create() } diff --git a/runtimes/nodejs/Dockerfile b/runtimes/nodejs/Dockerfile index 196cff79c0..f899bf8014 100644 --- a/runtimes/nodejs/Dockerfile +++ b/runtimes/nodejs/Dockerfile @@ -1,4 +1,4 @@ -FROM node:20 +FROM node:20.10.0 RUN apt update && apt-get install build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev git -y diff --git a/runtimes/nodejs/Dockerfile.init b/runtimes/nodejs/Dockerfile.init index 3c42370b1d..2955ab2412 100644 --- a/runtimes/nodejs/Dockerfile.init +++ b/runtimes/nodejs/Dockerfile.init @@ -1,4 +1,4 @@ -FROM node:20 +FROM node:20.10.0 WORKDIR /app diff --git a/runtimes/nodejs/init.sh b/runtimes/nodejs/init.sh index b1ad0c9ea5..1b3ba77ee5 100644 --- a/runtimes/nodejs/init.sh +++ b/runtimes/nodejs/init.sh @@ -29,20 +29,21 @@ if [ -n "$NODE_MODULES_PULL_URL" ]; then else elapsed_time=$(expr $end_time - $start_time) echo "Downloaded node_modules.tar in $elapsed_time seconds." - fi - - # untar node_modules.tar - tar -xf node_modules.tar -C . - # check tar exit code - if [ $? -ne 0 ]; then - echo "Failed to extract node_modules cache." - else - end_time_2=$(date +%s) - elapsed_time_2=$(expr $end_time_2 - $end_time) - echo "Extracted node_modules cache in $elapsed_time_2 seconds." + # untar node_modules.tar + tar -xf node_modules.tar -C . + + # check tar exit code + if [ $? -ne 0 ]; then + echo "Failed to extract node_modules cache." + else + end_time_2=$(date +%s) + elapsed_time_2=$(expr $end_time_2 - $end_time) + echo "Extracted node_modules cache in $elapsed_time_2 seconds." + fi fi + # re-enable set -e set -e else diff --git a/runtimes/nodejs/src/index.ts b/runtimes/nodejs/src/index.ts index 5c2a7d57d1..d6a79e9e87 100644 --- a/runtimes/nodejs/src/index.ts +++ b/runtimes/nodejs/src/index.ts @@ -21,6 +21,10 @@ import xmlparser from 'express-xml-bodyparser' import './support/cloud-sdk' import storageServer from './storage-server' import { DatabaseChangeStream } from './support/database-change-stream' +import { createCloudSdk } from './support/cloud-sdk' + +// hack: set createCloudSdk to global object to make it available in @lafjs/cloud package +globalThis.createCloudSdk = createCloudSdk const app = express() diff --git a/runtimes/nodejs/src/support/cloud-sdk.ts b/runtimes/nodejs/src/support/cloud-sdk.ts index 99461d40c6..e4d8b455a6 100644 --- a/runtimes/nodejs/src/support/cloud-sdk.ts +++ b/runtimes/nodejs/src/support/cloud-sdk.ts @@ -7,7 +7,9 @@ import Config from '../config' import { FunctionContext } from './engine' import { FunctionModule } from './engine/module' -Cloud.create = createCloudSdk +if (!Cloud.create) { + Cloud.create = createCloudSdk +} /** * object shared cross all functions & requests @@ -19,7 +21,7 @@ const _shared_preference = new Map() * * @returns */ -function createCloudSdk() { +export function createCloudSdk() { const cloud: CloudSdkInterface = { database: () => getDb(DatabaseAgent.accessor), invoke: invokeInFunction,