Skip to content

Commit

Permalink
feat[image]: Use slim variant for running image
Browse files Browse the repository at this point in the history
 - build tools removed
  • Loading branch information
sidey79 committed Apr 29, 2024
1 parent 999edd1 commit f8e733f
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 62 deletions.
52 changes: 37 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ jobs:
cache-to: type=gha,mode=max,scope=base_linux/${{ matrix.platform }}-${{ matrix.dockerfile }}
tags: baseonly

base_cpan_build:
needs: [get_dependencies, base_build]
cpan_build:
needs: [get_dependencies]
runs-on: ubuntu-latest
strategy:
matrix:
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 @@ -185,10 +185,10 @@ jobs:
push: false
target: base-cpan
cache-from: |
type=gha,scope=base_linux/${{ matrix.platform }}-${{ matrix.dockerfile }}
type=gha,scope=build_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
61 changes: 38 additions & 23 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,10 +46,41 @@ 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 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)

rm -rf /root/.cpanm
rm -rf /root/.perl-cpm/
rm -rf /tmp/* /var/tmp/* ~/.[^.] ~/.??* ~/*
EOF


FROM base as base-cpan

RUN <<EOF
LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get update
LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install -qqy --no-install-recommends \
Expand Down Expand Up @@ -95,29 +124,15 @@ RUN <<EOF
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/local/lib/perl5 /usr/src/app/local/lib/perl5

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

ENV PERL5LIB=/usr/src/app/local/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 @@ -246,7 +261,7 @@ RUN <<EOF
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
cpm install --cpanfile /usr/src/app/3rdparty-cpanfile --without-test --with-recommends --with-suggests --show-build-log-on-failure --configure-timeout=360 --workers=$(nproc)
rm -rf /root/.cpanm
rm -rf /root/.perl-cpm
EOF
Expand Down
63 changes: 39 additions & 24 deletions Dockerfile-threaded-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-threaded-bullseye@sha256:688a4d97874189bd38cf19fb665c0068978ab1f217a8d0cdc99f02dd23ad9cc9 as base
FROM perl:5.36.3-slim-threaded-buster 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,10 +46,41 @@ EOF
# Install all CPAN Modules, needed from FHEM and standard modules
#

FROM base as base-cpan
FROM perl:5.36.3-threaded-buster 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 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)

rm -rf /root/.cpanm
rm -rf /root/.perl-cpm/
rm -rf /tmp/* /var/tmp/* ~/.[^.] ~/.??* ~/*
EOF


FROM base as base-cpan

RUN <<EOF
LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get update
LC_ALL=C DEBIAN_FRONTEND=noninteractive apt-get install -qqy --no-install-recommends \
Expand Down Expand Up @@ -95,29 +124,15 @@ RUN <<EOF
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/local/lib/perl5 /usr/src/app/local/lib/perl5

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

ENV PERL5LIB=/usr/src/app/local/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 @@ -246,7 +261,7 @@ RUN <<EOF
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
cpm install --cpanfile /usr/src/app/3rdparty-cpanfile --without-test --with-recommends --with-suggests --show-build-log-on-failure --configure-timeout=360 --workers=$(nproc)
rm -rf /root/.cpanm
rm -rf /root/.perl-cpm
EOF
Expand Down Expand Up @@ -322,4 +337,4 @@ ADD https://github.com/grayhemp/bats-mock.git /opt/bats/test_helper/bats-mock

WORKDIR /code/

ENTRYPOINT [ "/usr/local/bin/bats" ]
ENTRYPOINT [ "/usr/local/bin/bats" ]

0 comments on commit f8e733f

Please sign in to comment.