This is an automated email from the ASF dual-hosted git repository.

msciabarra pushed a commit to branch sample-builder
in repository https://gitbox.apache.org/repos/asf/openserverless-task.git

commit 81189f83c14e05e137f0516c1ed8b7aa39f06efe
Author: Michele Sciabarra <[email protected]>
AuthorDate: Sat Jul 19 14:27:02 2025 +0200

    build-images
---
 ide/deploy/deploy.js     |  9 ++++++++-
 ide/python/build-venv.sh | 37 -------------------------------------
 ide/python/findimg.js    | 40 ++++++++++++++++++++++++++++++++++++++++
 ide/python/opsfile.yml   | 33 +++++++++++++++++++++++++++++----
 4 files changed, 77 insertions(+), 42 deletions(-)

diff --git a/ide/deploy/deploy.js b/ide/deploy/deploy.js
index 0e1423e..753fb54 100644
--- a/ide/deploy/deploy.js
+++ b/ide/deploy/deploy.js
@@ -104,14 +104,21 @@ export function deployAction(artifact) {
   deployPackage(pkg);
 
   let toInspect;
+  let dflags = [];
   if (typ === "zip") {
     const base = artifact.slice(0, -4);
     toInspect = MAINS.map((m) => `${base}/${m}`);
+    dflags =  extractArgs([`${base}/Dockerfile`])
   } else {
     toInspect = [artifact];
   }
 
-  const args = extractArgs(toInspect).join(" ");
+  let flags = extractArgs(toInspect);
+  if(dflags.length > 0) {
+    flags = flags.filter(f => !f.startsWith("--kind")).concat(dflags);
+  }
+
+  const args = flags.join(" ");
   const actionName = `${pkg}/${name}`;
   exec(`$OPS action update ${actionName} ${artifact} ${args}`);
 
diff --git a/ide/python/build-venv.sh b/ide/python/build-venv.sh
deleted file mode 100644
index cf94ce5..0000000
--- a/ide/python/build-venv.sh
+++ /dev/null
@@ -1,37 +0,0 @@
-#!/bin/bash
-# Licensed to the Apache Software Foundation (ASF) under one
-# or more contributor license agreements.  See the NOTICE file
-# distributed with this work for additional information
-# regarding copyright ownership.  The ASF licenses this file
-# to you under the Apache License, Version 2.0 (the
-# "License"); you may not use this file except in compliance
-# with the License.  You may obtain a copy of the License at
-#
-#   http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing,
-# software distributed under the License is distributed on an
-# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-# KIND, either express or implied.  See the License for the
-# specific language governing permissions and limitations
-# under the License.
-
-DIR="${1:?directory}"
-ZIP="${2:?zip file}"
-cd "$DIR"
-if ! test -d virtualenv
-  then virtualenv virtualenv
-fi
-source virtualenv/bin/activate
-pip install --upgrade pip
-pip install -r  requirements.txt
-virtualenv/bin/python -m pip uninstall -y -q setuptools wheel pip
-touch virtualenv/bin/activate
-if test -f "$ZIP"
-  then rm "$ZIP"
-fi
-7zz a "$ZIP" -tzip virtualenv >/dev/null
-ls -l $ZIP
-date >virtualenv/date
-
-
diff --git a/ide/python/findimg.js b/ide/python/findimg.js
new file mode 100644
index 0000000..ebd3c6d
--- /dev/null
+++ b/ide/python/findimg.js
@@ -0,0 +1,40 @@
+import { readFile } from "fs/promises";
+
+async function main() {
+  const [,, runtimeInput, jsonPath] = process.argv;
+
+  if (!runtimeInput || !jsonPath) {
+    console.error("Usage: bun find.js <runtime[:version|default]> 
<runtimes.json>");
+    process.exit(1);
+  }
+
+  const [language, kindOrDefault] = runtimeInput.split(":");
+
+  const content = await readFile(jsonPath, "utf-8");
+  const data = JSON.parse(content);
+
+  const runtimes = data.runtimes?.[language];
+
+  if (!runtimes) {
+    console.error(`Runtime family "${language}" not found.`);
+    process.exit(1);
+  }
+
+  let runtime;
+
+  if (!kindOrDefault || kindOrDefault === "default") {
+    runtime = runtimes.find(r => r.default);
+  } else {
+    runtime = runtimes.find(r => r.kind === `${language}:${kindOrDefault}`);
+  }
+
+  if (!runtime || !runtime.image) {
+    console.error(`Runtime for "${runtimeInput}" not found or has no image 
info.`);
+    process.exit(1);
+  }
+
+  const { prefix, name, tag } = runtime.image;
+  console.log(`${prefix}/${name}:${tag}`);
+}
+
+main();
diff --git a/ide/python/opsfile.yml b/ide/python/opsfile.yml
index 2341e74..594a4bf 100644
--- a/ide/python/opsfile.yml
+++ b/ide/python/opsfile.yml
@@ -27,20 +27,45 @@ tasks:
     - test -d "{{.DIR}}" || die "{{.DIR}} not found or not a directory"
     - rm -Rvf {{.DIR}}/virtualenv {{.DIR}}.zip
 
-  zip:
+  img:
     silent: true
-    desc: environment
+    desc: build image
     requires: {var: [DIR]}
     cmds:
     - test -d "{{.DIR}}" || die "{{.DIR}} not found or not a directory"
+    - test -n "$DOCKER_BUILDER" || die "create a docker builder in docker 
cloud and add to .env DOCKER_BUILDER"
+    - test -n "$DOCKER_CUSTOM_RUNTIMES" || die "set DOCKER_CUSTOM_RUNTIMES to 
the custom runtime prefix"
     - |
       if test -f "{{.DIR}}/requirements.txt"
-      then bash build-venv.sh "{{.DIR}}" "{{.DIR}}.zip"
+      then 
+          #sha256sum "{{.DIR}}/requirements.txt"
+          SHA="$(sha256sum "{{.DIR}}/requirements.txt" | awk '{print 
substr($1, 0, 12)}')"
+          KIND="$(awk '/--kind/ {print $2}' "{{.DIR}}/__main__.py")"
+          FROM="$(bun findimg.js "$KIND" "$OPS_ROOT/runtimes.json")"
+          cat <<EOF >"{{.DIR}}/Dockerfile"
+      #--docker "$DOCKER_CUSTOM_RUNTIMES:$SHA"
+      FROM $FROM
+      USER root
+      ADD requirements.txt /tmp/requirements.txt
+      RUN pip3 install --no-cache-dir -r /tmp/requirements.txt
+      USER nobody
+      EOF
+      cat "{{.DIR}}/Dockerfile"
+      docker buildx build --builder "$DOCKER_BUILDER" -t 
"$DOCKER_CUSTOM_RUNTIMES:$SHA" "{{.DIR}}" --push
       fi
     sources:
     - "{{.DIR}}/requirements.txt"
     generates:
-    - "{{.DIR}}/virtualenv/date"
+    - "{{.DIR}}/Dockerfile"
+
+  zip:
+    silent: true
+    desc: zip
+    requires: {var: [DIR]}
+    dir: "{{.DIR}}"
+    cmds:
+    - echo TODO remove this entirely
+    - task: img
 
   action:
     silent: true

Reply via email to