You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openserverless.apache.org by ms...@apache.org on 2025/08/01 08:22:06 UTC

(openserverless-task) branch image-build created (now e56617b)

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

msciabarra pushed a change to branch image-build
in repository https://gitbox.apache.org/repos/asf/openserverless-task.git


      at e56617b  image build

This branch includes the following new commits:

     new 020afd8  image builder
     new bc0d3f9  image builder
     new e56617b  image build

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(openserverless-task) 03/03: image build

Posted by ms...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit e56617b0159339b66a453a59cd1d799bd85d2229
Author: Michele Sciabarra <ms...@apache.org>
AuthorDate: Fri Aug 1 10:21:48 2025 +0200

    image build
---
 ide/deploy/bun.lockb | Bin
 ide/deploy/deploy.js |  11 +++++++++--
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/ide/deploy/bun.lockb b/ide/deploy/bun.lockb
old mode 100755
new mode 100644
diff --git a/ide/deploy/deploy.js b/ide/deploy/deploy.js
index 0e1423e..b1b015f 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}`);
 
@@ -135,7 +142,7 @@ export function deploy(file) {
   // const file = "packages/deploy/multi.zip";
   // const file = "packages/deploy/multi/__main__.py";
   // const file = "packages/deploy/multi/requirements.txt";
-  if (fs.lstatSync(file).isDirectory()) {
+  if (fs.existsSync(`${file}`) && fs.lstatSync(file).isDirectory()) {
     for (const start of MAINS) {
       const sub = `${file}/${start}`;
       if (fs.existsSync(sub)) {


(openserverless-task) 01/03: image builder

Posted by ms...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit 020afd8a8814a6362b5903cf9a36c7c77b0c8fe6
Author: Michele Sciabarra <ms...@apache.org>
AuthorDate: Thu Jul 31 11:54:12 2025 +0000

    image builder
---
 ide/python/findimg.js | 40 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 40 insertions(+)

diff --git a/ide/python/findimg.js b/ide/python/findimg.js
new file mode 100644
index 0000000..1611d70
--- /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}|${language}_${tag}`);
+}
+
+main();


(openserverless-task) 02/03: image builder

Posted by ms...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

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

commit bc0d3f972d2772664e8c83ab3b4f93aab6c6c0a0
Author: Michele Sciabarra <ms...@apache.org>
AuthorDate: Thu Jul 31 11:54:38 2025 +0000

    image builder
---
 ide/python/build-venv.sh | 37 -----------------------------------
 ide/python/opsfile.yml   | 51 ++++++++++++++++++++++++++++++++++++++++++++----
 2 files changed, 47 insertions(+), 41 deletions(-)

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/opsfile.yml b/ide/python/opsfile.yml
index 0617ed9..61719e5 100644
--- a/ide/python/opsfile.yml
+++ b/ide/python/opsfile.yml
@@ -27,20 +27,63 @@ 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 
+          DIR="{{.DIR}}"
+          SHA="$(sha256sum "$DIR/requirements.txt" | awk '{print substr($1, 0, 12)}')"
+          KIND="$(awk '/--kind/ {print $2}' "$DIR/__main__.py")"
+          FROM_TAG="$(bun findimg.js "$KIND" "$OPS_ROOT/runtimes.json")"
+          FROM="${FROM_TAG%|*}"
+          TAG="${FROM_TAG#*|}.${SHA}"
+          echo FROM=$FROM
+          echo TAG=$TAG
+          if rg "$TAG" "{{.DIR}}/Dockerfile"
+          then echo Image already built
+          else 
+            cat <<EOF >"$DIR/Dockerfile"
+      #--docker "$DOCKER_CUSTOM_RUNTIMES:$TAG"
+      FROM $FROM
+      USER root
+      ADD requirements.txt /tmp/requirements.txt
+      RUN pip3 install --no-cache-dir -r /tmp/requirements.txt
+      EOF
+            export NO_COLOR=1
+            cat "$DIR/requirements.txt" | rg '^#Dockerfile:\s*(.*)' -or '$1' >>"$DIR/Dockerfile"
+            echo "USER nobody" >>"$DIR/Dockerfile"
+            cat "$DIR/Dockerfile"
+            docker buildx build --platform linux/arm64,linux/amd64 --builder "$DOCKER_BUILDER" -t "$DOCKER_CUSTOM_RUNTIMES:$TAG" "$DIR" --push
+            if test $? -eq 0
+            then echo Built "$DOCKER_CUSTOM_RUNTIMES:$TAG"
+            else rm "$DIR/Dockerfile"
+                 die "docker build failed, check the Dockerfile"
+            fi
+          fi
+      else
+        echo "no requirements.txt found, skipping image build"
       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
+    - mkdir -p _empty && zip -q -r "{{.DIR}}".zip _empty
+    - task: img
 
   action:
     silent: true