Skip to content

Commit 01a422a

Browse files
authored
Implemented squash layer for SDK container image (#27)
* Added squash layer to decrease number of image layers, * Modified regex to only remove the first appearance of `FROM` in a Dockerfile * Provide current base layer `as base_container_name` inside Dockerfiles
1 parent dd42984 commit 01a422a

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

builder/build_container.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,9 @@ def _build_container(self, name: str, path: str) -> None:
6464
gid = self.gid
6565

6666

67-
# Replace FROM with layer before.
68-
command = f'echo "FROM {self.base_container_name}" > Dockerfile.tmp; ' \
69-
'sed \'/FROM /d\' Dockerfile >> Dockerfile.tmp'
67+
# Replace first FROM with previous layer.
68+
command = f'echo "FROM {self.base_container_name} as base_container_name" > Dockerfile.tmp; ' \
69+
'sed \'0,/FROM /{/FROM /d;}\' Dockerfile >> Dockerfile.tmp'
7070
subprocess.run(command, shell=True, check=True, cwd=path)
7171

7272
# Build the container.

configuration/build_config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ Layers:
1010
- ../layers/appdev
1111
- ../layers/embdgen
1212
- ../layers/vscode
13+
- ../layers/squash

layers/squash/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
FROM ubuntu:latest as base_container_name
2+
3+
FROM scratch
4+
COPY --from=base_container_name / /

layers/squash/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# EBcL SDK: Squash layer

0 commit comments

Comments
 (0)