From e7d5ed2db1d834bf80e8cdbad1f289f0cf3165bb Mon Sep 17 00:00:00 2001
From: lijianguo <lijianguo@zhumengyuan.com>
Date: Thu, 22 Jul 2021 18:17:09 +0800
Subject: [PATCH] chore(imagebuilder): modify build

---
 .../templates/imagebuilder-configmap.yaml     |  6 ++++-
 rootfs/Dockerfile                             |  4 ++-
 rootfs/imagebuilder/build                     | 26 ++++++++++---------
 3 files changed, 22 insertions(+), 14 deletions(-)

diff --git a/charts/imagebuilder/templates/imagebuilder-configmap.yaml b/charts/imagebuilder/templates/imagebuilder-configmap.yaml
index 3699b38..b1ab67c 100644
--- a/charts/imagebuilder/templates/imagebuilder-configmap.yaml
+++ b/charts/imagebuilder/templates/imagebuilder-configmap.yaml
@@ -8,7 +8,11 @@ data:
   images.json: |
     [
         {
-            "name": "imagebuilder",
+            "name": "container",
+            "image": "{{.Values.image_registry}}/{{.Values.org}}/imagebuilder:{{.Values.image_tag}}"
+        },
+        {
+            "name": "buildpack",
             "image": "{{.Values.image_registry}}/{{.Values.org}}/imagebuilder:{{.Values.image_tag}}"
         }
     ]
diff --git a/rootfs/Dockerfile b/rootfs/Dockerfile
index 3376fa8..7b8cad4 100644
--- a/rootfs/Dockerfile
+++ b/rootfs/Dockerfile
@@ -8,6 +8,8 @@ COPY --from=mc /usr/bin/mc /bin/mc
 RUN /imagebuilder/install
 
 WORKDIR /app
-ENV HOME /app
+ENV HOME /tmp
+ENV XDG_DATA_HOME /tmp
+ENV XDG_CONFIG_HOME /tmp/.config
 
 ENTRYPOINT ["/imagebuilder/build"]
\ No newline at end of file
diff --git a/rootfs/imagebuilder/build b/rootfs/imagebuilder/build
index 46f075a..2ad81a6 100755
--- a/rootfs/imagebuilder/build
+++ b/rootfs/imagebuilder/build
@@ -29,7 +29,7 @@ function waiting_process {
 }
 
 # Start podman service
-export DOCKER_HOST="unix:///var/run/podman.sock"
+export DOCKER_HOST=tcp://127.0.0.1:1234
 
 log_level="error"
 if [[ "${DRYCC_DEBUG}" ]]; then
@@ -39,13 +39,12 @@ fi
 
 podman system service \
     --log-level "${log_level}" \
-    --time 0 "${DOCKER_HOST}" &
+    --time 0 tcp:0.0.0.0:1234 &
 
 waiting_process podman
-
 if [[ -n "${TAR_PATH}" ]]; then
     get_object
-    tar -xzf /tmp/app.tgz -C /app/
+    tar -xzf /tmp/app.tgz -C /app/ && \
     unset TAR_PATH
 fi
 
@@ -60,19 +59,22 @@ if [[ "${DRYCC_REGISTRY_LOCATION}" == "off-cluster" ]] ; then
     podman login \
         --username "${DRYCC_REGISTRY_USERNAME}" \
         --password "${DRYCC_REGISTRY_PASSWORD}" \
-        "${DRYCC_REGISTRY_HOSTNAME}" --tls-verify=false
+        "${DRYCC_REGISTRY_HOSTNAME}" --tls-verify=false \
+        > /dev/null
 else
     # Start registry proxy
     registry="${DRYCC_REGISTRY_PROXY_HOST}:${DRYCC_REGISTRY_PROXY_PORT}"
     caddy reverse-proxy \
         --from ":${DRYCC_REGISTRY_PROXY_PORT}" \
-        --to "${DRYCC_REGISTRY_SERVICE_HOST}:${DRYCC_REGISTRY_SERVICE_PORT}" &
+        --to "${DRYCC_REGISTRY_SERVICE_HOST}:${DRYCC_REGISTRY_SERVICE_PORT}" \
+        >"$([ "${log_level}" == "debug" ] && echo "/dev/stdout" || echo "/dev/null")" 2>&1 &
     waiting_process caddy
     podman login \
         --username drycc \
         --password drycc \
         --tls-verify=false \
-        "${registry}"
+        "${registry}" \
+        > /dev/null
 fi
 
 # Get image name and image tag
@@ -83,19 +85,19 @@ image_cache_repo="${registry}/${image_name}:latest"
 
 # Pull latest image as cache
 {
-    echo "---> Reusing cache" 
+    echo "---> Reusing cache"
     podman pull "${image_cache_repo}" --tls-verify=false >/dev/null 2>&1
 } || {
-    echo "---> Cache not found" 
+    echo "---> Cache not found"
 }
-
 # Building
 if [[ "${DRYCC_STACK}" == "container" ]] ; then
     echo "---> Building container"
-    podman build -t "${image_cache_repo}" .
+    podman build -t "${image_cache_repo}" --network host .
 else
     echo "---> Building pack"
-    pack build "${image_cache_repo}" --builder "${pack_builder}" --docker-host "${DOCKER_HOST}"
+    echo "use builder ${pack_builder}"
+    pack build "${image_cache_repo}" --builder "${pack_builder}" --docker-host "${DOCKER_HOST}" --lifecycle-image docker.io/drycc/lifecycle:0.11.3 --trust-builder --network host
 fi
 
 # Publish image
