From 1cd34ea3537a8de03eadcd3cbb18242517851924 Mon Sep 17 00:00:00 2001 From: Artyom Savchenko Date: Mon, 17 Nov 2025 21:50:06 +0700 Subject: [PATCH] Optimise docker build space usage (#10224) * Use BuildKit builder instead of legacy one Signed-off-by: Artem Savchenko * fix: use slim docker image Signed-off-by: Alexander Onnikov * Add dockerignore Signed-off-by: Artem Savchenko * Clean up build artifacts Signed-off-by: Artem Savchenko * Clean up Signed-off-by: Artem Savchenko * Fix flag Signed-off-by: Artem Savchenko --------- Signed-off-by: Artem Savchenko Signed-off-by: Alexander Onnikov Co-authored-by: Alexander Onnikov --- .github/workflows/main.yml | 7 +++++++ common/scripts/docker_build.sh | 27 +++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 1c5edf3d21..bd6150a0d0 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -245,6 +245,7 @@ jobs: run: node common/scripts/install-run-rush.js docker env: DOCKER_CLI_HINTS: false + DOCKER_BUILDKIT: 1 - name: Configure /etc/hosts run: | sudo echo "127.0.0.1 huly.local" | sudo tee -a /etc/hosts @@ -375,6 +376,7 @@ jobs: run: node common/scripts/install-run-rush.js docker env: DOCKER_CLI_HINTS: false + DOCKER_BUILDKIT: 1 - name: Configure /etc/hosts run: | sudo echo "127.0.0.1 huly.local" | sudo tee -a /etc/hosts @@ -469,6 +471,7 @@ jobs: run: node common/scripts/install-run-rush.js docker env: DOCKER_CLI_HINTS: false + DOCKER_BUILDKIT: 1 - name: Configure /etc/hosts run: | sudo echo "127.0.0.1 huly.local" | sudo tee -a /etc/hosts @@ -550,6 +553,7 @@ jobs: run: node common/scripts/install-run-rush.js docker env: DOCKER_CLI_HINTS: false + DOCKER_BUILDKIT: 1 - name: Configure /etc/hosts run: | sudo echo "127.0.0.1 huly.local" | sudo tee -a /etc/hosts @@ -674,6 +678,8 @@ jobs: env: DOCKER_CLI_HINTS: false DOCKER_EXTRA: --platform=linux/amd64,linux/arm64 + DOCKER_BUILDKIT: 1 + DOCKER_BUILD_CLEANUP: true - name: Docker build love-agent run: | cd ./services/ai-bot/love-agent @@ -682,6 +688,7 @@ jobs: env: DOCKER_CLI_HINTS: false DOCKER_EXTRA: --platform=linux/amd64,linux/arm64 + DOCKER_BUILDKIT: 1 - name: Login to Docker Hub if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') || startsWith(github.ref, 'refs/tags/s') }} uses: docker/login-action@v3 diff --git a/common/scripts/docker_build.sh b/common/scripts/docker_build.sh index 586eb01750..2a564dc375 100755 --- a/common/scripts/docker_build.sh +++ b/common/scripts/docker_build.sh @@ -2,6 +2,33 @@ version=$(git rev-parse HEAD) +# Check for cleanup flag from environment +cleanup=false +if [ "$DOCKER_BUILD_CLEANUP" = "true" ]; then + cleanup=true +fi + echo "Building version: $version" docker build -t "$1" -t "$1:$version" ${DOCKER_EXTRA} . + +if [ "$cleanup" = true ]; then + echo "Cleaning up build artifacts..." + + if [ -d "bundle" ]; then + echo " Removing bundle/" + rm -rf bundle + fi + + if [ -d "dist" ]; then + echo " Removing dist/" + rm -rf dist + fi + + if [ -d ".rush" ]; then + echo " Removing .rush/" + rm -rf .rush + fi + + echo " Size after cleanup: $(du -sh . 2>/dev/null | cut -f1)" +fi