Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[build] use debian slim docker images #19008

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

k-v1
Copy link
Contributor

@k-v1 k-v1 commented May 19, 2024

Why I did it

To reduce final image size and docker images size.

Almost all SONiC docker images are based on debian image.
But default debian image includes multiple extra files that are normally not necessary within containers:
https://github.com/debuerreotype/debuerreotype/blob/master/scripts/.slimify-excludes

We are trying to remove them from debian image but this solution is incorrect.
It's not possible to remove these files from docker base layer because --squash only works with NEW layers:
https://docs.docker.com/reference/cli/docker/image/build/#squash:
"Once the image is built, this flag squashes the new layers into a new image with a single new layer. Squashing doesn't destroy any existing image, rather it creates a new image with the content of the squashed layers."

Instead we should use debian -slim images.

Work item tracking
  • Microsoft ADO (number only):

How I did it

Use debian slim image as base image for docker-base-bookworm, docker-base-bullseye and docker-base-buster.

How to verify it

default build:

82M docker-base-bookworm.gz
86M docker-base-bullseye.gz
99M docker-config-engine-bookworm.gz
103M docker-config-engine-bullseye.gz
197M docker-dash-engine.gz
102M docker-database.gz
103M docker-dhcp-relay.gz
100M docker-eventd.gz
120M docker-fpm-frr.gz
522M docker-gbsyncd-vs.gz
116M docker-lldp.gz
110M docker-macsec.gz
116M docker-mux.gz
109M docker-nat.gz
112M docker-orchagent.gz
140M docker-platform-monitor.gz
100M docker-router-advertiser.gz
109M docker-sflow.gz
110M docker-snmp.gz
128M docker-sonic-gnmi.gz
126M docker-sonic-mgmt-framework.gz
108M docker-swss-layer-bookworm.gz
112M docker-swss-layer-bullseye.gz
522M docker-syncd-vs.gz
108M docker-teamd.gz
1965594999 target/sonic-vs.img.gz

build based on slim images:

62M docker-base-bookworm.gz
64M docker-base-bullseye.gz
80M docker-config-engine-bookworm.gz
80M docker-config-engine-bullseye.gz
197M docker-dash-engine.gz
82M docker-database.gz
83M docker-dhcp-relay.gz
80M docker-eventd.gz
98M docker-fpm-frr.gz
502M docker-gbsyncd-vs.gz
97M docker-lldp.gz
90M docker-macsec.gz
97M docker-mux.gz
90M docker-nat.gz
92M docker-orchagent.gz
121M docker-platform-monitor.gz
80M docker-router-advertiser.gz
89M docker-sflow.gz
91M docker-snmp.gz
109M docker-sonic-gnmi.gz
107M docker-sonic-mgmt-framework.gz
89M docker-swss-layer-bookworm.gz
89M docker-swss-layer-bullseye.gz
502M docker-syncd-vs.gz
89M docker-teamd.gz
1921280020 sonic-vs.img.gz

Size of final image is reduced by 40M (20M for bookworm-based containers and 20M for bullseye-based).

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106
  • 202111
  • 202205
  • 202211
  • 202305

Tested branch (Please provide the tested image version)

Description for the changelog

Link to config_db schema for YANG module changes

A picture of a cute animal (not mandatory but encouraged)

@k-v1 k-v1 requested a review from qiluo-msft as a code owner May 19, 2024 20:14
@k-v1
Copy link
Contributor Author

k-v1 commented May 19, 2024

For reproducible builds it's probably necessary to generate sha hashes in files/build/versions/default/versions-docker.

@k-v1
Copy link
Contributor Author

k-v1 commented May 19, 2024

@xumia @lguohan

PR builds failed because of this:

Step 1/43 : FROM publicmirror.azurecr.io/amd64/debian:bullseye-slim
manifest for publicmirror.azurecr.io/amd64/debian:bullseye-slim not found: manifest unknown: manifest tagged by "bullseye-slim" is not found

Maybe you can add debian slim images to your mirror?

@lguohan
Copy link
Collaborator

lguohan commented May 22, 2024

@liushilongbuaa , can you help on this?

@lguohan
Copy link
Collaborator

lguohan commented May 22, 2024

@Staphylo , can you check this? the pr looks fine for me.

@liushilongbuaa
Copy link
Contributor

@liushilongbuaa , can you help on this?

I can help fix current error.

@Staphylo
Copy link
Collaborator

Looks good to me, I did test this as well and didn't run into any issues

@k-v1
Copy link
Contributor Author

k-v1 commented May 23, 2024

@liushilongbuaa , can you help on this?

I can help fix current error.

I think it's also necessary to add debian slim images for arm64 and armhf.

2024-05-23T08:40:50.6858568Z Unable to find image 'publicmirror.azurecr.io/arm64v8/debian:bullseye-slim' locally
2024-05-23T08:40:50.6859490Z docker: Error response from daemon: manifest for publicmirror.azurecr.io/arm64v8/debian:bullseye-slim not found: manifest unknown: manifest tagged by "bullseye-slim" is not found.
2024-05-23T08:46:58.0315162Z Unable to find image 'publicmirror.azurecr.io/arm32v7/debian:bullseye-slim' locally
2024-05-23T08:46:58.0315997Z docker: Error response from daemon: manifest for publicmirror.azurecr.io/arm32v7/debian:bullseye-slim not found: manifest unknown: manifest tagged by "bullseye-slim" is not found.

@liushilongbuaa
Copy link
Contributor

@liushilongbuaa , can you help on this?

I can help fix current error.

I think it's also necessary to add debian slim images for arm64 and armhf.

2024-05-23T08:40:50.6858568Z Unable to find image 'publicmirror.azurecr.io/arm64v8/debian:bullseye-slim' locally
2024-05-23T08:40:50.6859490Z docker: Error response from daemon: manifest for publicmirror.azurecr.io/arm64v8/debian:bullseye-slim not found: manifest unknown: manifest tagged by "bullseye-slim" is not found.
2024-05-23T08:46:58.0315162Z Unable to find image 'publicmirror.azurecr.io/arm32v7/debian:bullseye-slim' locally
2024-05-23T08:46:58.0315997Z docker: Error response from daemon: manifest for publicmirror.azurecr.io/arm32v7/debian:bullseye-slim not found: manifest unknown: manifest tagged by "bullseye-slim" is not found.

Added. I will rerun failure jobs.

@k-v1
Copy link
Contributor Author

k-v1 commented May 23, 2024

Added

It's required for bookworm images too.

Also after merging this PR is necessary to update docker versions in https://github.com/sonic-net/sonic-buildimage/blob/master/files/build/versions/default/versions-docker for reproducible builds.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants