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.
This commit is contained in:
@@ -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: [
|
||||
|
||||
Reference in New Issue
Block a user