From 96664148e008d803c292c1b3ae68ad0c6c49fed0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CNaeel=E2=80=9D?= Date: Sat, 7 Mar 2026 17:00:29 +0400 Subject: [PATCH] feat: add nodejs20 runtime MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - runtimes/nodejs20/server.js: HTTP wrapper, exports.handle(event) - runtimes/nodejs20/Dockerfile: node:20-alpine base image - naeel/sless-runtime-nodejs20:v0.1.0 pushed to DockerHub - upload.go: nodejs20 in runtimeBaseImage(), package.json → npm install - upload.go: python3.11 now uses v0.1.0 tag (no more latest) - operator v0.1.2 deployed in cluster - E2E: hello-node-default.fn.kube5s.ru → {"message":"Hello, Naeel! (nodejs20)"} --- hello-node/handler.js | 6 ++++++ hello-node/main.tf | 45 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) create mode 100644 hello-node/handler.js create mode 100644 hello-node/main.tf diff --git a/hello-node/handler.js b/hello-node/handler.js new file mode 100644 index 0000000..415c92f --- /dev/null +++ b/hello-node/handler.js @@ -0,0 +1,6 @@ +// handler.js — пример serverless функции на Node.js 20 +// Возвращает приветствие с именем из event или "World" по умолчанию +exports.handle = async (event) => { + const name = event.name || 'World'; + return { message: `Hello, ${name}! (nodejs20)` }; +}; diff --git a/hello-node/main.tf b/hello-node/main.tf new file mode 100644 index 0000000..9c3bab8 --- /dev/null +++ b/hello-node/main.tf @@ -0,0 +1,45 @@ +# 2026-03-07 +# main.tf — e2e тест: hello-world функция на Node.js 20. +# +# Использование: +# 1. terraform init && terraform apply +# 2. После apply (~2 мин kaniko): +# curl -s -X POST -H 'Content-Type: application/json' -d '{"name":"Naeel"}' +# Ожидаемый ответ: {"message":"Hello, Naeel! (nodejs20)"} + +terraform { + required_providers { + sless = { + source = "terra.k8c.ru/naeel/sless" + version = "~> 0.1.1" + } + } +} + +provider "sless" { + endpoint = "https://sless-api.kube5s.ru" + token = "dev-token-change-me" +} + +resource "sless_function" "hello_node" { + namespace = "default" + name = "hello-node" + runtime = "nodejs20" + entrypoint = "handler.handle" + memory_mb = 128 + timeout_sec = 30 + + code_path = "${path.module}/handler.zip" + code_hash = filemd5("${path.module}/handler.zip") +} + +resource "sless_trigger" "hello_node_http" { + namespace = "default" + name = "hello-node-http" + type = "http" + function = sless_function.hello_node.name +} + +output "trigger_url" { + value = sless_trigger.hello_node_http.url +}