Skip to content

Commit 1cd34ea

Browse files
Optimise docker build space usage (#10224)
* Use BuildKit builder instead of legacy one Signed-off-by: Artem Savchenko <[email protected]> * fix: use slim docker image Signed-off-by: Alexander Onnikov <[email protected]> * Add dockerignore Signed-off-by: Artem Savchenko <[email protected]> * Clean up build artifacts Signed-off-by: Artem Savchenko <[email protected]> * Clean up Signed-off-by: Artem Savchenko <[email protected]> * Fix flag Signed-off-by: Artem Savchenko <[email protected]> --------- Signed-off-by: Artem Savchenko <[email protected]> Signed-off-by: Alexander Onnikov <[email protected]> Co-authored-by: Alexander Onnikov <[email protected]>
1 parent 01ebea2 commit 1cd34ea

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

.github/workflows/main.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@ jobs:
245245
run: node common/scripts/install-run-rush.js docker
246246
env:
247247
DOCKER_CLI_HINTS: false
248+
DOCKER_BUILDKIT: 1
248249
- name: Configure /etc/hosts
249250
run: |
250251
sudo echo "127.0.0.1 huly.local" | sudo tee -a /etc/hosts
@@ -375,6 +376,7 @@ jobs:
375376
run: node common/scripts/install-run-rush.js docker
376377
env:
377378
DOCKER_CLI_HINTS: false
379+
DOCKER_BUILDKIT: 1
378380
- name: Configure /etc/hosts
379381
run: |
380382
sudo echo "127.0.0.1 huly.local" | sudo tee -a /etc/hosts
@@ -469,6 +471,7 @@ jobs:
469471
run: node common/scripts/install-run-rush.js docker
470472
env:
471473
DOCKER_CLI_HINTS: false
474+
DOCKER_BUILDKIT: 1
472475
- name: Configure /etc/hosts
473476
run: |
474477
sudo echo "127.0.0.1 huly.local" | sudo tee -a /etc/hosts
@@ -550,6 +553,7 @@ jobs:
550553
run: node common/scripts/install-run-rush.js docker
551554
env:
552555
DOCKER_CLI_HINTS: false
556+
DOCKER_BUILDKIT: 1
553557
- name: Configure /etc/hosts
554558
run: |
555559
sudo echo "127.0.0.1 huly.local" | sudo tee -a /etc/hosts
@@ -674,6 +678,8 @@ jobs:
674678
env:
675679
DOCKER_CLI_HINTS: false
676680
DOCKER_EXTRA: --platform=linux/amd64,linux/arm64
681+
DOCKER_BUILDKIT: 1
682+
DOCKER_BUILD_CLEANUP: true
677683
- name: Docker build love-agent
678684
run: |
679685
cd ./services/ai-bot/love-agent
@@ -682,6 +688,7 @@ jobs:
682688
env:
683689
DOCKER_CLI_HINTS: false
684690
DOCKER_EXTRA: --platform=linux/amd64,linux/arm64
691+
DOCKER_BUILDKIT: 1
685692
- name: Login to Docker Hub
686693
if: ${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v') || startsWith(github.ref, 'refs/tags/s') }}
687694
uses: docker/login-action@v3

common/scripts/docker_build.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,33 @@
22

33
version=$(git rev-parse HEAD)
44

5+
# Check for cleanup flag from environment
6+
cleanup=false
7+
if [ "$DOCKER_BUILD_CLEANUP" = "true" ]; then
8+
cleanup=true
9+
fi
10+
511
echo "Building version: $version"
612

713
docker build -t "$1" -t "$1:$version" ${DOCKER_EXTRA} .
14+
15+
if [ "$cleanup" = true ]; then
16+
echo "Cleaning up build artifacts..."
17+
18+
if [ -d "bundle" ]; then
19+
echo " Removing bundle/"
20+
rm -rf bundle
21+
fi
22+
23+
if [ -d "dist" ]; then
24+
echo " Removing dist/"
25+
rm -rf dist
26+
fi
27+
28+
if [ -d ".rush" ]; then
29+
echo " Removing .rush/"
30+
rm -rf .rush
31+
fi
32+
33+
echo " Size after cleanup: $(du -sh . 2>/dev/null | cut -f1)"
34+
fi

0 commit comments

Comments
 (0)