From 2be3c50455251b2a4762e26283e84cc0d3294d80 Mon Sep 17 00:00:00 2001 From: keyhan Date: Mon, 6 Apr 2026 00:50:20 +0330 Subject: [PATCH] fix: auto-flatten single subfolder in uploaded ZIP files for build context GitHub-downloaded ZIPs contain files inside a subfolder (e.g., repo-main/). The build init container now detects this pattern and flattens the contents to the workspace root so Kaniko can find package.json and other files. --- backend/src/build/build.service.ts | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/backend/src/build/build.service.ts b/backend/src/build/build.service.ts index 13b6b00..94f3d3f 100644 --- a/backend/src/build/build.service.ts +++ b/backend/src/build/build.service.ts @@ -137,9 +137,23 @@ export class BuildService { command: ['sh', '-c', ` apk add --no-cache unzip && cp /workspace/Dockerfile /workspace-out/Dockerfile && - mkdir -p /workspace-out/source && - cd /workspace-out/source && + mkdir -p /tmp/extract && + cd /tmp/extract && unzip /source/source.zip && + echo "--- Extracted contents ---" && + ls -la /tmp/extract/ && + mkdir -p /workspace-out/source && + ITEMS=$(ls -1 /tmp/extract/ | head -5) && + COUNT=$(ls -1 /tmp/extract/ | wc -l) && + if [ "$COUNT" -eq 1 ] && [ -d "/tmp/extract/$ITEMS" ]; then + echo ">>> Single subfolder detected: $ITEMS — flattening to root" && + cp -a /tmp/extract/$ITEMS/. /workspace-out/source/ + else + echo ">>> Multiple items or files — copying as-is" && + cp -a /tmp/extract/. /workspace-out/source/ + fi && + rm -rf /tmp/extract && + echo "--- Final workspace contents ---" && ls -la /workspace-out/source/ `], volumeMounts: [