Skip to content

Commit

Permalink
ok
Browse files Browse the repository at this point in the history
  • Loading branch information
HUAHUAI23 committed Mar 31, 2024
1 parent db3e471 commit 5f260c9
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
15 changes: 11 additions & 4 deletions runtimes/nodejs/src/handler/docker-file-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,17 +129,23 @@ export async function handleDockerFile(_: IRequest, res: Response) {
'APP_ID',
'APPID',
'RUNTIME_DOMAIN',
'RUNTIME_MAIN_IMAGE',

'OSS_ACCESS_KEY',
'OSS_ACCESS_SECRET',
'OSS_INTERNAL_ENDPOINT',
'OSS_EXTERNAL_ENDPOINT',
'OSS_REGION',

'DEPENDENCIES',

'NODE_MODULES_PUSH_URL',
'NODE_MODULES_PULL_URL',

'NPM_INSTALL_FLAGS',
'CUSTOM_DEPENDENCY_BASE_PATH',
'RESTART_AT',
'SERVER_SECRET',
]

let envVariablesString = 'LOG_LEVEL=debug \\\n FORCE_COLOR=1 \\\n '
Expand Down Expand Up @@ -170,21 +176,23 @@ export async function handleDockerFile(_: IRequest, res: Response) {
// version from env todo
const DOCKER_FILE = `
FROM docker.io/lafyun/runtime-node:pr-1930@sha256:7db630fb7e1ba1c8ccf246dc92261cf8fad86a32df406d327a9313fd828f297f as builder
FROM ${ENV.RUNTIME_MAIN_IMAGE} as builder
USER root
WORKDIR ${ENV.CUSTOM_DEPENDENCY_BASE_PATH}
RUN mkdir -p /app/cloud_functions && chown -R node:node /app/cloud_functions ${ENV.CUSTOM_DEPENDENCY_BASE_PATH}
USER node
RUN npm install ${ENV.DEPENDENCIES} || true
RUN curl -o /tmp/cloud_functions.tar https://${ENV.RUNTIME_DOMAIN}/_/${process.env.SERVER_SECRET}/cloud_functions/tar && tar -xf /tmp/cloud_functions.tar -C /app/cloud_functions && rm /tmp/cloud_functions.tar
FROM node:20.10.0
USER root
EXPOSE 8000
EXPOSE 9000
RUN mkdir -p ${ENV.CUSTOM_DEPENDENCY_BASE_PATH} /app/cloud_functions && chown -R node:node ${ENV.CUSTOM_DEPENDENCY_BASE_PATH} /app/cloud_functions
USER node
COPY --from=builder ${ENV.CUSTOM_DEPENDENCY_BASE_PATH} ${ENV.CUSTOM_DEPENDENCY_BASE_PATH}
Expand All @@ -194,7 +202,6 @@ RUN ln -s ${ENV.CUSTOM_DEPENDENCY_BASE_PATH} /app/functions/node_modules
ENV ${envVariablesString}
RUN curl -o /tmp/cloud_functions.tar https://${ENV.RUNTIME_DOMAIN}/_/cloud_functions/tar && tar -xf /tmp/cloud_functions.tar -C /app/cloud_functions && rm /tmp/cloud_functions.tar
WORKDIR /app
CMD node $FLAGS --experimental-vm-modules --experimental-fetch ./dist/index.js
Expand Down
10 changes: 8 additions & 2 deletions runtimes/nodejs/src/handler/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,14 @@ export const router = Router()

router.post('/proxy/:policy', handleDatabaseProxy)
router.get('/_/typing/package', handlePackageTypings)
router.get('/_/cloud_functions/tar', handleCloudFunctionTarPackage)
router.get('/_/cloud_functions/dockerfile', handleDockerFile)
router.get(
`/_/${process.env.SERVER_SECRET}/cloud_functions/tar`,
handleCloudFunctionTarPackage,
)
router.get(
`/_/${process.env.SERVER_SECRET}/cloud_functions/dockerfile`,
handleDockerFile,
)

router.get('/_/healthz', (_req, res) => {
if (Config.IS_DOCKER_PRODUCT) {
Expand Down
2 changes: 2 additions & 0 deletions server/src/instance/instance.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ export class InstanceService {
{ name: 'APP_ID', value: appid }, // deprecated, use `APPID` instead
{ name: 'APPID', value: appid },
{ name: 'RUNTIME_DOMAIN', value: runtimeDomain.domain },
{ name: 'RUNTIME_INIT_IMAGE', value: app.runtime.image.init },
{ name: 'RUNTIME_MAIN_IMAGE', value: app.runtime.image.main },
{ name: 'OSS_ACCESS_KEY', value: storage.accessKey },
{ name: 'OSS_ACCESS_SECRET', value: storage.secretKey },
{
Expand Down

0 comments on commit 5f260c9

Please sign in to comment.