Skip to content

Abnormal container image size detected #5266

@weichou1229

Description

@weichou1229

🐞 Bug Report

Affected Services [REQUIRED]

The issue is located in all services Image

Is this a regression?

No

Description and Minimal Reproduction [REQUIRED]

  • Run go build to generate binary for checking size for different git tags.
  • Use docker history to inspect the image sizes.

Since all services share the same libraries, I checked the size change using the Core Data service.

Check the binary size

Tag Size
... ...
v3.1.1 16M
v4.0.0 25M
... ...
v4.1.0-dev.41 25M
v4.1.0-dev.42 37M
... ...
v4.1.0-dev.62 37M
v4.1.0-dev.63 37M

The binary size has significantly increased from v3.1.1 to v4.0.0, and v4.1.0-dev.42

Then I use the go-size-analyzer tool to check the different of binary size

Analyze the binary to see the difference between core-data_v3.1.1 and core-data_v4.0.0

PERCENT NAME OLD SIZE NEW SIZE DIFF
+100% github.com/jackc/pgx/v5 3.3 MB +3.3 MB
+100% google.golang.org/protobuf 1.3 MB +1.3 MB
+100% github.com/openziti/edge-api 737 kB +737 kB
+100% go.mongodb.org/mongo-driver 456 kB +456 kB
+100% github.com/openziti/sdk-golang 445 kB +445 kB
+100% github.com/parallaxsecond/parsec-client-go 298 kB +298 kB
+165.26% 167 kB 443 kB +276 kB
+100% github.com/edgexfoundry/go-mod-bootstrap/v4 272 kB +272 kB
+100% encoding/gob 223 kB +223 kB
+100% github.com/edgexfoundry/go-mod-core-contracts/v4 175 kB +175 kB
+100% github.com/go-openapi/strfmt 175 kB +175 kB
+100% gopkg.in/go-jose/go-jose.v2 172 kB +172 kB
+64.13% github.com/edgexfoundry/edgex-go 264 kB 433 kB +169 kB
+100% github.com/orcaman/concurrent-map/v2 133 kB +133 kB
+100% github.com/openziti/channel/v3 115 kB +115 kB
... ... ... ...
-4.78% crypto 1.6 MB 1.5 MB -75 kB
-100% github.com/edgexfoundry/go-mod-core-contracts/v3 96 kB -96 kB
-14.67% runtime 1.1 MB 957 kB -164 kB
-100% github.com/edgexfoundry/go-mod-bootstrap/v3 220 kB -220 kB
-100% github.com/go-redis/redis/v7 232 kB -232 kB
... ... ... ...
+100% .data.rel.ro 3.4 MB +3.4 MB
+12368700.00% .rela 24 B 3.0 MB +3.0 MB
+552.71% .noptrdata 74 kB 484 kB +410 kB
+131.73% .data 68 kB 158 kB +90 kB
... ... ... ...
-100% .debug_line 864 kB -864 kB
-100% .debug_loc 1.1 MB -1.1 MB
-100% .debug_info 1.5 MB -1.5 MB
... ... ... ...
+59.86% core-data_v3.1.1 16 MB 25 MB +9.4 MB
core-data_v4.0.0

Analyze the binary to see the difference between core-data_v4.0.0 and core-data_v4.1.0-dev.42

PERCENT NAME OLD SIZE NEW SIZE DIFF
+617.35% github.com/openziti/edge-api 737 kB 5.3 MB +4.6 MB
+166.35% github.com/edgexfoundry/edgex-go 433 kB 1.2 MB +721 kB
+212.08% github.com/edgexfoundry/go-mod-core-contracts/v4 175 kB 545 kB +371 kB
+540.77% golang.org/x/net 67 kB 431 kB +363 kB
+263.37% github.com/orcaman/concurrent-map/v2 133 kB 483 kB +350 kB
+69.02% github.com/openziti/sdk-golang 445 kB 752 kB +307 kB
+22.06% net 1.3 MB 1.6 MB +287 kB
+16.37% crypto 1.5 MB 1.7 MB +246 kB
+100% github.com/openziti/channel/v4 243 kB +243 kB
+7.31% github.com/jackc/pgx/v5 3.3 MB 3.5 MB +242 kB
+46.62% go.mongodb.org/mongo-driver 456 kB 669 kB +213 kB
+100% github.com/go-jose/go-jose/v4 207 kB +207 kB
+497.00% go.opentelemetry.io/otel 36 kB 213 kB +177 kB
... ... ... ...
-100% github.com/zitadel/oidc/v2 84 kB -84 kB
-100% github.com/openziti/channel/v3 115 kB -115 kB
-100% gopkg.in/go-jose/go-jose.v2 172 kB -172 kB
... ... ... ...
+36.06% .data.rel.ro 3.4 MB 4.6 MB +1.2 MB
+36.95% .rela 3.0 MB 4.1 MB +1.1 MB
+36.62% .rodata 1.4 MB 1.9 MB +521 kB
... ... ... ...
+3.33% .dynstr 691 B 714 B +23 B
+4.44% .got.plt 360 B 376 B +16 B
+3.57% .hash 224 B 232 B +8 B
+4.26% .gnu.version 94 B 98 B +4 B
... ... ... ...
+50.85% core-data_v4.0.0 25 MB 38 MB +13 MB
core-data_v4.1.0-dev.42

Check the Docker image size

Total size and Image layer edgexfoundry/core-data:3.1.1 edgexfoundry/core-data:4.0.0 nexus3.edgexfoundry.org:10004/core-data:4.1.0-dev.42
Total Size 26.9MB 32.4MB 45.1MB
Image layer
CMD ["-cp=consul.http://edgex-core-consul:85… 0B 0B 0B
ENTRYPOINT ["/core-data"] 0B 0B 0B
COPY /edgex-go/cmd/core-data/res/configurati… 1.1kB 1.5kB 1.5kB
COPY /edgex-go/cmd/core-data/core-data / # b… 13.9MB 24.5MB 37.2MB
COPY /edgex-go/security.txt / # buildkit 584B 584B 584B
COPY /edgex-go/Attribution.txt / # buildki 11.7kB 17.4kB 17.4kB
RUN /bin/sh -c apk --no-cache upgrade # buil… 5.55MB 25kB 25kB
RUN /bin/sh -c apk add --update --no-cache d… 81.3kB 84kB 84kB
EXPOSE map[59880/tcp:{} 0B 0B 0B
ENV APP_PORT=59880 0B 0B 0B
LABEL license=SPDX-License-Identifier: Apach… 0B 0B 0B
CMD ["/bin/sh"] 0B 0B 0B
ADD alpine-minirootfs-3.2… 7.34MB 7.8MB 7.79MB

Final thought

The binary size explosion from 16MB → 37MB is due to

  • lib upgrade
  • new feature added into edgex-go,
  • new dependencies in v4, especially OpenZiti, PostgreSQL driver, and Protocol Buffers.

Attached are the full details of the binary size comparison table.

v4.0.0_v4.1.0-dev.42.md
v3.1.1_v4.0.0.md

I thought we need to increase the threshold value to pass the test.

Version Binary Size Docker Image Size Binary Growth Image Growth
v3.1.1 16MB 26.9MB baseline baseline
v4.0.0 25MB 32.4MB +9MB (+56%) +5.5MB (+20%)
v4.1.0-dev.42 37MB 45.1MB +21MB (+131%) +18.2MB (+68%)

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

Status

New Issues

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions