Skip to content

Commit acb7771

Browse files
authored
Use slim variant for running image (#228)
- build tools removed - dev libs removed - binarys from cpan builds removed
2 parents 33eca29 + 2107b9c commit acb7771

File tree

4 files changed

+181
-113
lines changed

4 files changed

+181
-113
lines changed

.github/workflows/build.yml

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ jobs:
130130
cache-to: type=gha,mode=max,scope=base_linux/${{ matrix.platform }}-${{ matrix.dockerfile }}
131131
tags: baseonly
132132

133-
base_cpan_build:
133+
cpan_build:
134134
needs: [get_dependencies, base_build]
135135
runs-on: ubuntu-latest
136136
strategy:
@@ -175,7 +175,7 @@ jobs:
175175
GHCR_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
176176
DOCKERFILE: ${{ matrix.dockerfile }}
177177

178-
- name: Build base cpan layer for ${{ matrix.platform }}
178+
- name: Build cpan packages for ${{ matrix.platform }}
179179
uses: docker/build-push-action@v5
180180
with:
181181
context: .
@@ -188,7 +188,7 @@ jobs:
188188
type=gha,scope=base_linux/${{ matrix.platform }}-${{ matrix.dockerfile }}
189189
type=gha,scope=base-cpan_linux/${{ matrix.platform }}-${{ matrix.dockerfile }}
190190
cache-to: type=gha,mode=max,scope=base-cpan_linux/${{ matrix.platform }}-${{ matrix.dockerfile }}
191-
tags: basecpanonly
191+
tags: buildcpanonly
192192

193193

194194
test_build:
@@ -254,6 +254,30 @@ jobs:
254254
type=ref,event=branch,suffix=${{ matrix.dockerfile }}
255255
type=ref,event=pr,suffix=${{ matrix.dockerfile }}
256256
257+
- name: Build and cache fhem base layer
258+
uses: docker/build-push-action@v5
259+
id: docker_build_fhem
260+
with:
261+
context: .
262+
load: true
263+
file: ./Dockerfile${{ matrix.dockerfile }}
264+
platforms: linux/amd64
265+
push: false
266+
target: with-fhem-bats
267+
cache-from: |
268+
type=gha,scope=fhem_linux/amd64-${{ matrix.dockerfile }}
269+
type=gha,scope=base_linux/amd64-${{ matrix.dockerfile }}
270+
cache-to: type=gha,mode=max,scope=fhem_linux/amd64-${{ matrix.dockerfile }}
271+
tags: with-fhem
272+
labels: ${{ steps.meta.outputs.labels }}
273+
build-args: |
274+
BUILD_DATE=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
275+
IMAGE_VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
276+
IMAGE_VCS_REF=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
277+
L_USAGE=${{ github.server_url }}/${{ github.repository }}/blob/${{ github.sha }}/README.md
278+
L_VCS_URL=${{ github.server_url }}/${{ github.repository }}/
279+
L_AUTHORS=${{ github.server_url }}/${{ github.repository }}/graphs/contributors
280+
257281
- name: Build for bats with fhem base layer
258282
uses: docker/build-push-action@v5
259283
id: docker_build_bats
@@ -265,9 +289,7 @@ jobs:
265289
push: false
266290
target: with-fhem-bats
267291
cache-from: |
268-
type=gha,scope=base_linux/amd64-${{ matrix.dockerfile }}
269-
type=gha,scope=full_linux/amd64-${{ matrix.dockerfile }}
270-
cache-to: type=gha,mode=max,scope=full_linux/amd64-${{ matrix.dockerfile }}
292+
type=gha,scope=fhem_linux/amd64-${{ matrix.dockerfile }}
271293
tags: bats-withfhem
272294
labels: ${{ steps.meta.outputs.labels }}
273295
build-args: |
@@ -301,8 +323,8 @@ jobs:
301323
push: false
302324
target: with-fhem-extended-python-nodejs
303325
cache-from: |
304-
type=gha,scope=base_linux/amd64-${{ matrix.dockerfile }}
305-
type=gha,scope=full_linux/amd64-${{ matrix.dockerfile }}
326+
type=gha,scope=full_linux/amd64-${{ matrix.dockerfile }}
327+
type=gha,scope=fhem_linux/amd64-${{ matrix.dockerfile }}
306328
cache-to: type=gha,mode=max,scope=full_linux/amd64-${{ matrix.dockerfile }}
307329
tags: ${{ steps.meta.outputs.tags }}
308330
labels: ${{ steps.meta.outputs.labels }}
@@ -333,7 +355,7 @@ jobs:
333355
334356
published_build:
335357
runs-on: ubuntu-latest
336-
needs: [test_build, base_cpan_build]
358+
needs: [test_build, cpan_build]
337359
strategy:
338360
matrix:
339361
dockerfile: [-bullseye, -threaded-bullseye]
@@ -397,10 +419,11 @@ jobs:
397419
context: .
398420
load: false
399421
file: ./Dockerfile${{ matrix.dockerfile }}
400-
platforms: linux/amd64,linux/arm/v7,linux/arm64
422+
platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/386
401423
push: ${{ github.event_name != 'pull_request' }}
402424
target: with-fhem-extended-python-nodejs
403425
cache-from: |
426+
type=gha,scope=base-cpan_linux/386-${{ matrix.dockerfile }}
404427
type=gha,scope=base-cpan_linux/arm64-${{ matrix.dockerfile }}
405428
type=gha,scope=base-cpan_linux/arm/v7-${{ matrix.dockerfile }}
406429
type=gha,scope=full_linux/amd64-${{ matrix.dockerfile }}
@@ -440,17 +463,16 @@ jobs:
440463
context: .
441464
load: false
442465
file: ./Dockerfile${{ matrix.dockerfile }}
443-
platforms: linux/386,linux/amd64,linux/arm/v7,linux/arm64
466+
platforms: linux/386,linux/amd64,linux/arm/v7,linux/arm64,386
444467
push: ${{ github.event_name != 'pull_request' }}
445468
target: with-fhem
446469
cache-from: |
447470
type=gha,scope=base_linux/arm64-${{ matrix.dockerfile }}
448471
type=gha,scope=base_linux/amd64-${{ matrix.dockerfile }}
449472
type=gha,scope=base_linux/arm/v7-${{ matrix.dockerfile }}
473+
type=gha,scope=base_linux/386-${{ matrix.dockerfile }}
450474
type=gha,scope=full_linux/amd64-${{ matrix.dockerfile }}
451475
type=gha,scope=full_linux/cross-${{ matrix.dockerfile }}
452-
type=gha,scope=base_linux/cross-${{ matrix.dockerfile }}
453-
cache-to: type=gha,mode=max,scope=base_linux/cross-${{ matrix.dockerfile }}
454476
tags: ${{ steps.meta_base.outputs.tags }}
455477
labels: ${{ steps.meta_base.outputs.labels }}
456478
build-args: |

Dockerfile-bullseye

Lines changed: 71 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#
33
# base layer with perl and some general preparations
44
#
5-
FROM perl:5.36.3-bullseye@sha256:e341d89b87dbf8caf8a3e33e8d606e1cb4f975d43553a083040fae3402d078c3 as base
5+
FROM perl:5.36.3-slim-bullseye as base
66

77
ARG TARGETPLATFORM
88

@@ -28,9 +28,7 @@ RUN <<EOF
2828
LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install -qqy --no-install-recommends \
2929
ca-certificates \
3030
gnupg \
31-
locales \
32-
libusb-dev \
33-
python3-dev
31+
locales
3432
LC_ALL=C c_rehash
3533
LC_ALL=C DEBIAN_FRONTEND=noninteractive dpkg-reconfigure locales
3634
echo 'de_DE@euro ISO-8859-15\nde_DE ISO-8859-1\nde_DE.UTF-8 UTF-8\nen_DK ISO-8859-1\nen_DK.ISO-8859-15 ISO-8859-15\nen_DK.UTF-8 UTF-8\nen_GB ISO-8859-1\nen_GB.ISO-8859-15 ISO-8859-15\nen_GB.UTF-8 UTF-8\nen_IE ISO-8859-1\nen_IE.ISO-8859-15 ISO-8859-15\nen_IE.UTF-8 UTF-8\nen_US ISO-8859-1\nen_US.ISO-8859-15 ISO-8859-15\nen_US.UTF-8 UTF-8\nes_ES@euro ISO-8859-15\nes_ES ISO-8859-1\nes_ES.UTF-8 UTF-8\nfr_FR@euro ISO-8859-15\nfr_FR ISO-8859-1\nfr_FR.UTF-8 UTF-8\nit_IT@euro ISO-8859-15\nit_IT ISO-8859-1\nit_IT.UTF-8 UTF-8\nnl_NL@euro ISO-8859-15\nnl_NL ISO-8859-1\nnl_NL.UTF-8 UTF-8\npl_PL ISO-8859-2\npl_PL.UTF-8 UTF-8' >/etc/locale.gen
@@ -48,9 +46,70 @@ EOF
4846
# Install all CPAN Modules, needed from FHEM and standard modules
4947
#
5048

51-
FROM base as base-cpan
49+
FROM perl:5.36.3-bullseye as build-cpan
50+
51+
COPY cpanfile /usr/src/app/core/cpanfile
52+
53+
# Install Packages used for building cpan modules:
54+
RUN <<EOF
55+
LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get update
56+
LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install -qqy --no-install-recommends \
57+
libusb-dev \
58+
python3-dev
59+
LC_ALL=C apt-get autoremove -qqy && LC_ALL=C apt-get clean
60+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* ~/.[^.] ~/.??* ~/*
61+
EOF
62+
63+
#
64+
# Fixup modules which do not work on all platforms and install afterwards
65+
# Install Modules from CPAN
66+
#
67+
68+
# JSON::XS isn't marked as compatible with Perl 5.36, we prevent some output
69+
ENV PERL_CANARY_STABILITY_NOPROMPT=1
70+
RUN <<EOF
71+
if [ "${TARGETPLATFORM}" != "linux/amd64" ] && [ "${TARGETPLATFORM}" != "linux/i386" ]; then
72+
sed -i '/Device::Firmata::Constants/d' /usr/src/app/core/cpanfile
73+
fi
74+
75+
cpm install --without-test --with-suggests --with-recommends --cpanfile /usr/src/app/core/cpanfile --show-build-log-on-failure --configure-timeout=360 --workers=$(nproc) --local-lib-contained core/
76+
rm -rf /root/.cpanm
77+
rm -rf /root/.perl-cpm/
78+
rm -rf /tmp/* /var/tmp/* ~/.[^.] ~/.??* ~/*
79+
EOF
80+
81+
82+
# Install Packages used for building 3rdparty cpan modules:
83+
RUN <<EOF
84+
LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get update
85+
LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install -qqy --no-install-recommends \
86+
libsox-fmt-all \
87+
libbluetooth-dev \
88+
libi2c-dev \
89+
libgd-dev \
90+
libdbus-1-dev \
91+
libimlib2-dev \
92+
libsodium-dev
93+
LC_ALL=C apt-get autoremove -qqy && LC_ALL=C apt-get clean
94+
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* ~/.[^.] ~/.??* ~/*
95+
EOF
96+
97+
98+
# Install all CPAN Modules, needed from 3rd party module repositorys
99+
COPY 3rdParty/cpanfile /usr/src/app/3rdparty/cpanfile
100+
# Fixup modules which do not work on all platforms and install afterwards
101+
RUN <<EOF
102+
if [ "${TARGETPLATFORM}" != "linux/amd64" ] && [ "${TARGETPLATFORM}" != "linux/i386" ]; then
103+
sed -i '/Device::Firmata::Constants/d' /usr/src/app/3rdparty/cpanfile
104+
fi
105+
106+
cpm install --cpanfile /usr/src/app/3rdparty/cpanfile --without-test --with-recommends --with-suggests --show-build-log-on-failure --configure-timeout=360 --workers=$(nproc) --local-lib-contained 3rdparty/
107+
rm -rf /root/.cpanm
108+
rm -rf /root/.perl-cpm
109+
EOF
52110

53-
COPY cpanfile /usr/src/app/core-cpanfile
111+
112+
FROM base as base-cpan
54113

55114
RUN <<EOF
56115
LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get update
@@ -84,40 +143,21 @@ RUN <<EOF
84143
usbutils \
85144
wget \
86145
libarchive-dev \
87-
libimlib2-dev \
88146
bash \
89147
iproute2
90-
# Install Packages used for building cpan modules:
91-
LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install -qqy --no-install-recommends \
92-
libusb-dev \
93-
python3-dev
94148
LC_ALL=C apt-get autoremove -qqy && LC_ALL=C apt-get clean
95149
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* ~/.[^.] ~/.??* ~/*
96150
EOF
97151

98-
#
99-
# Fixup modules which do not work on all platforms and install afterwards
100-
# Install Modules from CPAN
101-
#
102-
103-
# JSON::XS isn't marked as compatible with Persl 5.36, we prevent some output
104-
ENV PERL_CANARY_STABILITY_NOPROMPT=1
105-
RUN <<EOF
106-
if [ "${TARGETPLATFORM}" != "linux/amd64" ] && [ "${TARGETPLATFORM}" != "linux/i386" ]; then
107-
sed -i '/Device::Firmata::Constants/d' /usr/src/app/core-cpanfile
108-
fi
109-
cpm install --without-test --with-suggests --with-recommends --cpanfile /usr/src/app/core-cpanfile --show-build-log-on-failure --global --configure-timeout=360 --workers=2
110-
111-
rm -rf /root/.cpanm
112-
rm -rf /root/.perl-cpm/
113-
rm -rf /tmp/* /var/tmp/* ~/.[^.] ~/.??* ~/*
114-
EOF
152+
COPY --from=build-cpan /usr/src/app/core/lib/perl5 /usr/src/app/core/lib/perl5
115153

116154
#
117155
# Standard FHEM Layer
118156
#
119157
FROM base-cpan as with-fhem
120158

159+
ENV PERL5LIB=/usr/src/app/core/lib/perl5
160+
121161
# Install base environment and FHEM Docker module
122162
COPY src/entry.sh src/health-check.sh src/ssh_known_hosts.txt /
123163
COPY src/FHEM/99_DockerImageInfo.pm /fhem/FHEM/
@@ -207,6 +247,7 @@ CMD [ "start" ]
207247

208248
FROM with-fhem as with-fhem-extended
209249

250+
ENV PERL5LIB=${PERL5LIB}:/usr/src/app/3rdparty/lib/perl5
210251

211252
# Add extended system layer
212253
RUN <<EOF
@@ -221,36 +262,17 @@ RUN <<EOF
221262
mp3wrap \
222263
mpg123 \
223264
mplayer \
224-
nmap \
225265
normalize-audio \
226266
snmp \
227267
snmp-mibs-downloader \
228268
sox \
229269
vorbis-tools \
230-
gstreamer1.0-tools \
231-
libsox-fmt-all \
232-
libbluetooth-dev \
233-
libi2c-dev \
234-
libgd-dev \
235-
libdbus-1-dev
236-
libsodium-dev
270+
gstreamer1.0-tools
237271
LC_ALL=C apt-get autoremove -qqy && LC_ALL=C apt-get clean
238272
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* ~/.[^.] ~/.??* ~/*
239273
EOF
240274

241-
# Install all CPAN Modules, needed from 3rd party module repositorys
242-
COPY 3rdParty/cpanfile /usr/src/app/3rdparty-cpanfile
243-
# Fixup modules which do not work on all platforms and install afterwards
244-
RUN <<EOF
245-
if [ "${TARGETPLATFORM}" != "linux/amd64" ] && [ "${TARGETPLATFORM}" != "linux/i386" ]; then
246-
sed -i '/Device::Firmata::Constants/d' /usr/src/app/3rdparty-cpanfile
247-
fi
248-
249-
cpm install --cpanfile /usr/src/app/3rdparty-cpanfile --without-test --with-recommends --with-suggests --show-build-log-on-failure --global --configure-timeout=360 --workers=2
250-
rm -rf /root/.cpanm
251-
rm -rf /root/.perl-cpm
252-
EOF
253-
275+
COPY --from=build-cpan /usr/src/app/3rdparty/lib/perl5 /usr/src/app/3rdparty/lib/perl5
254276

255277
#
256278
# Add additional Python layer

0 commit comments

Comments
 (0)