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 <[email protected]>
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

Reply via email to