Skip to content

Commit

Permalink
Use slim variant for running image (#228)
Browse files Browse the repository at this point in the history
 - build tools removed
 - dev libs removed
 - binarys from cpan builds removed
  • Loading branch information
sidey79 authored May 5, 2024
2 parents 33eca29 + 2107b9c commit acb7771
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 113 deletions.
48 changes: 35 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ jobs:
cache-to: type=gha,mode=max,scope=base_linux/${{ matrix.platform }}-${{ matrix.dockerfile }}
tags: baseonly

base_cpan_build:
cpan_build:
needs: [get_dependencies, base_build]
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -175,7 +175,7 @@ jobs:
GHCR_ACCESS_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCKERFILE: ${{ matrix.dockerfile }}

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


test_build:
Expand Down Expand Up @@ -254,6 +254,30 @@ jobs:
type=ref,event=branch,suffix=${{ matrix.dockerfile }}
type=ref,event=pr,suffix=${{ matrix.dockerfile }}
- name: Build and cache fhem base layer
uses: docker/build-push-action@v5
id: docker_build_fhem
with:
context: .
load: true
file: ./Dockerfile${{ matrix.dockerfile }}
platforms: linux/amd64
push: false
target: with-fhem-bats
cache-from: |
type=gha,scope=fhem_linux/amd64-${{ matrix.dockerfile }}
type=gha,scope=base_linux/amd64-${{ matrix.dockerfile }}
cache-to: type=gha,mode=max,scope=fhem_linux/amd64-${{ matrix.dockerfile }}
tags: with-fhem
labels: ${{ steps.meta.outputs.labels }}
build-args: |
BUILD_DATE=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.created'] }}
IMAGE_VERSION=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.version'] }}
IMAGE_VCS_REF=${{ fromJSON(steps.meta.outputs.json).labels['org.opencontainers.image.revision'] }}
L_USAGE=${{ github.server_url }}/${{ github.repository }}/blob/${{ github.sha }}/README.md
L_VCS_URL=${{ github.server_url }}/${{ github.repository }}/
L_AUTHORS=${{ github.server_url }}/${{ github.repository }}/graphs/contributors
- name: Build for bats with fhem base layer
uses: docker/build-push-action@v5
id: docker_build_bats
Expand All @@ -265,9 +289,7 @@ jobs:
push: false
target: with-fhem-bats
cache-from: |
type=gha,scope=base_linux/amd64-${{ matrix.dockerfile }}
type=gha,scope=full_linux/amd64-${{ matrix.dockerfile }}
cache-to: type=gha,mode=max,scope=full_linux/amd64-${{ matrix.dockerfile }}
type=gha,scope=fhem_linux/amd64-${{ matrix.dockerfile }}
tags: bats-withfhem
labels: ${{ steps.meta.outputs.labels }}
build-args: |
Expand Down Expand Up @@ -301,8 +323,8 @@ jobs:
push: false
target: with-fhem-extended-python-nodejs
cache-from: |
type=gha,scope=base_linux/amd64-${{ matrix.dockerfile }}
type=gha,scope=full_linux/amd64-${{ matrix.dockerfile }}
type=gha,scope=full_linux/amd64-${{ matrix.dockerfile }}
type=gha,scope=fhem_linux/amd64-${{ matrix.dockerfile }}
cache-to: type=gha,mode=max,scope=full_linux/amd64-${{ matrix.dockerfile }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Expand Down Expand Up @@ -333,7 +355,7 @@ jobs:
published_build:
runs-on: ubuntu-latest
needs: [test_build, base_cpan_build]
needs: [test_build, cpan_build]
strategy:
matrix:
dockerfile: [-bullseye, -threaded-bullseye]
Expand Down Expand Up @@ -397,10 +419,11 @@ jobs:
context: .
load: false
file: ./Dockerfile${{ matrix.dockerfile }}
platforms: linux/amd64,linux/arm/v7,linux/arm64
platforms: linux/amd64,linux/arm/v7,linux/arm64,linux/386
push: ${{ github.event_name != 'pull_request' }}
target: with-fhem-extended-python-nodejs
cache-from: |
type=gha,scope=base-cpan_linux/386-${{ matrix.dockerfile }}
type=gha,scope=base-cpan_linux/arm64-${{ matrix.dockerfile }}
type=gha,scope=base-cpan_linux/arm/v7-${{ matrix.dockerfile }}
type=gha,scope=full_linux/amd64-${{ matrix.dockerfile }}
Expand Down Expand Up @@ -440,17 +463,16 @@ jobs:
context: .
load: false
file: ./Dockerfile${{ matrix.dockerfile }}
platforms: linux/386,linux/amd64,linux/arm/v7,linux/arm64
platforms: linux/386,linux/amd64,linux/arm/v7,linux/arm64,386
push: ${{ github.event_name != 'pull_request' }}
target: with-fhem
cache-from: |
type=gha,scope=base_linux/arm64-${{ matrix.dockerfile }}
type=gha,scope=base_linux/amd64-${{ matrix.dockerfile }}
type=gha,scope=base_linux/arm/v7-${{ matrix.dockerfile }}
type=gha,scope=base_linux/386-${{ matrix.dockerfile }}
type=gha,scope=full_linux/amd64-${{ matrix.dockerfile }}
type=gha,scope=full_linux/cross-${{ matrix.dockerfile }}
type=gha,scope=base_linux/cross-${{ matrix.dockerfile }}
cache-to: type=gha,mode=max,scope=base_linux/cross-${{ matrix.dockerfile }}
tags: ${{ steps.meta_base.outputs.tags }}
labels: ${{ steps.meta_base.outputs.labels }}
build-args: |
Expand Down
120 changes: 71 additions & 49 deletions Dockerfile-bullseye
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#
# base layer with perl and some general preparations
#
FROM perl:5.36.3-bullseye@sha256:e341d89b87dbf8caf8a3e33e8d606e1cb4f975d43553a083040fae3402d078c3 as base
FROM perl:5.36.3-slim-bullseye as base

ARG TARGETPLATFORM

Expand All @@ -28,9 +28,7 @@ RUN <<EOF
LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install -qqy --no-install-recommends \
ca-certificates \
gnupg \
locales \
libusb-dev \
python3-dev
locales
LC_ALL=C c_rehash
LC_ALL=C DEBIAN_FRONTEND=noninteractive dpkg-reconfigure locales
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
Expand All @@ -48,9 +46,70 @@ EOF
# Install all CPAN Modules, needed from FHEM and standard modules
#

FROM base as base-cpan
FROM perl:5.36.3-bullseye as build-cpan

COPY cpanfile /usr/src/app/core/cpanfile

# Install Packages used for building cpan modules:
RUN <<EOF
LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get update
LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install -qqy --no-install-recommends \
libusb-dev \
python3-dev
LC_ALL=C apt-get autoremove -qqy && LC_ALL=C apt-get clean
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* ~/.[^.] ~/.??* ~/*
EOF

#
# Fixup modules which do not work on all platforms and install afterwards
# Install Modules from CPAN
#

# JSON::XS isn't marked as compatible with Perl 5.36, we prevent some output
ENV PERL_CANARY_STABILITY_NOPROMPT=1
RUN <<EOF
if [ "${TARGETPLATFORM}" != "linux/amd64" ] && [ "${TARGETPLATFORM}" != "linux/i386" ]; then
sed -i '/Device::Firmata::Constants/d' /usr/src/app/core/cpanfile
fi

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/
rm -rf /root/.cpanm
rm -rf /root/.perl-cpm/
rm -rf /tmp/* /var/tmp/* ~/.[^.] ~/.??* ~/*
EOF


# Install Packages used for building 3rdparty cpan modules:
RUN <<EOF
LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get update
LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install -qqy --no-install-recommends \
libsox-fmt-all \
libbluetooth-dev \
libi2c-dev \
libgd-dev \
libdbus-1-dev \
libimlib2-dev \
libsodium-dev
LC_ALL=C apt-get autoremove -qqy && LC_ALL=C apt-get clean
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* ~/.[^.] ~/.??* ~/*
EOF


# Install all CPAN Modules, needed from 3rd party module repositorys
COPY 3rdParty/cpanfile /usr/src/app/3rdparty/cpanfile
# Fixup modules which do not work on all platforms and install afterwards
RUN <<EOF
if [ "${TARGETPLATFORM}" != "linux/amd64" ] && [ "${TARGETPLATFORM}" != "linux/i386" ]; then
sed -i '/Device::Firmata::Constants/d' /usr/src/app/3rdparty/cpanfile
fi

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/
rm -rf /root/.cpanm
rm -rf /root/.perl-cpm
EOF

COPY cpanfile /usr/src/app/core-cpanfile

FROM base as base-cpan

RUN <<EOF
LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get update
Expand Down Expand Up @@ -84,40 +143,21 @@ RUN <<EOF
usbutils \
wget \
libarchive-dev \
libimlib2-dev \
bash \
iproute2
# Install Packages used for building cpan modules:
LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install -qqy --no-install-recommends \
libusb-dev \
python3-dev
LC_ALL=C apt-get autoremove -qqy && LC_ALL=C apt-get clean
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* ~/.[^.] ~/.??* ~/*
EOF

#
# Fixup modules which do not work on all platforms and install afterwards
# Install Modules from CPAN
#

# JSON::XS isn't marked as compatible with Persl 5.36, we prevent some output
ENV PERL_CANARY_STABILITY_NOPROMPT=1
RUN <<EOF
if [ "${TARGETPLATFORM}" != "linux/amd64" ] && [ "${TARGETPLATFORM}" != "linux/i386" ]; then
sed -i '/Device::Firmata::Constants/d' /usr/src/app/core-cpanfile
fi
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

rm -rf /root/.cpanm
rm -rf /root/.perl-cpm/
rm -rf /tmp/* /var/tmp/* ~/.[^.] ~/.??* ~/*
EOF
COPY --from=build-cpan /usr/src/app/core/lib/perl5 /usr/src/app/core/lib/perl5

#
# Standard FHEM Layer
#
FROM base-cpan as with-fhem

ENV PERL5LIB=/usr/src/app/core/lib/perl5

# Install base environment and FHEM Docker module
COPY src/entry.sh src/health-check.sh src/ssh_known_hosts.txt /
COPY src/FHEM/99_DockerImageInfo.pm /fhem/FHEM/
Expand Down Expand Up @@ -207,6 +247,7 @@ CMD [ "start" ]

FROM with-fhem as with-fhem-extended

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

# Add extended system layer
RUN <<EOF
Expand All @@ -221,36 +262,17 @@ RUN <<EOF
mp3wrap \
mpg123 \
mplayer \
nmap \
normalize-audio \
snmp \
snmp-mibs-downloader \
sox \
vorbis-tools \
gstreamer1.0-tools \
libsox-fmt-all \
libbluetooth-dev \
libi2c-dev \
libgd-dev \
libdbus-1-dev
libsodium-dev
gstreamer1.0-tools
LC_ALL=C apt-get autoremove -qqy && LC_ALL=C apt-get clean
rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* ~/.[^.] ~/.??* ~/*
EOF

# Install all CPAN Modules, needed from 3rd party module repositorys
COPY 3rdParty/cpanfile /usr/src/app/3rdparty-cpanfile
# Fixup modules which do not work on all platforms and install afterwards
RUN <<EOF
if [ "${TARGETPLATFORM}" != "linux/amd64" ] && [ "${TARGETPLATFORM}" != "linux/i386" ]; then
sed -i '/Device::Firmata::Constants/d' /usr/src/app/3rdparty-cpanfile
fi

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
rm -rf /root/.cpanm
rm -rf /root/.perl-cpm
EOF

COPY --from=build-cpan /usr/src/app/3rdparty/lib/perl5 /usr/src/app/3rdparty/lib/perl5

#
# Add additional Python layer
Expand Down
Loading

0 comments on commit acb7771

Please sign in to comment.