From 5121f4d1f1d330a4db53af54e375551d31efa91d Mon Sep 17 00:00:00 2001 From: sidey79 <7968127+sidey79@users.noreply.github.com> Date: Sun, 10 Mar 2024 00:37:01 +0100 Subject: [PATCH 1/5] feat[threaded]: provide an image with perl threaded --- .github/workflows/build.yml | 44 ++--- Dockerfile-threaded-bullseye | 308 +++++++++++++++++++++++++++++++++++ 2 files changed, 330 insertions(+), 22 deletions(-) create mode 100644 Dockerfile-threaded-bullseye diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 5e87acb7..dc8f6223 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -78,7 +78,7 @@ jobs: base_build: strategy: matrix: - dockerfile: [Dockerfile-bullseye] + dockerfile: [-bullseye, -threaded-bullseye] platform: [arm/v7, amd64, arm64, 386] runs-on: ubuntu-latest steps: @@ -100,7 +100,7 @@ jobs: with: context: . load: true - file: ./${{ matrix.dockerfile }} + file: ./Dockerfile${{ matrix.dockerfile }} platforms: linux/${{ matrix.platform }} push: false target: base @@ -115,7 +115,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - dockerfile: [Dockerfile-bullseye] + dockerfile: [-bullseye, -threaded-bullseye] # Steps represent a sequence of tasks that will be executed as part of the job steps: - name: Checkout this repository @@ -165,10 +165,10 @@ jobs: flavor: | latest= ${{ fromJSON('["auto", "false"]')[github.event.release.prerelease == 1 || endsWith(matrix.dockerfile, 'Dockerfile')] }} tags: | - type=semver,pattern={{version}},suffix=${{ fromJSON('["-bullseye", "-buster"]')[endsWith(matrix.dockerfile, 'Dockerfile')] }} - type=semver,pattern={{major}},enable=${{ github.event.release.prerelease == 0 }},suffix=${{ fromJSON('["-bullseye", "-buster"]')[endsWith(matrix.dockerfile, 'Dockerfile')] }} - type=ref,event=branch,suffix=${{ fromJSON('["-bullseye", "-buster"]')[endsWith(matrix.dockerfile, 'Dockerfile')] }} - type=ref,event=pr,suffix=${{ fromJSON('["-bullseye", "-buster"]')[endsWith(matrix.dockerfile, 'Dockerfile')] }} + type=semver,pattern={{version}},suffix=${{ matrix.dockerfile }} + type=semver,pattern={{major}},enable=${{ github.event.release.prerelease == 0 }},suffix=${{ matrix.dockerfile }} + type=ref,event=branch,suffix=${{ matrix.dockerfile }} + type=ref,event=pr,suffix=${{ matrix.dockerfile }} - name: Build for bats with fhem base layer uses: docker/build-push-action@v5 @@ -244,7 +244,7 @@ jobs: needs: test_build strategy: matrix: - dockerfile: [Dockerfile-bullseye] + dockerfile: [-bullseye, -threaded-bullseye] # Steps represent a sequence of tasks that will be executed as part of the job steps: @@ -291,11 +291,11 @@ jobs: flavor: | latest= ${{ fromJSON('["auto", "false"]')[github.event.release.prerelease == 1] }} tags: | - type=semver,pattern={{version}},suffix=${{ fromJSON('["-bullseye", "-buster"]')[endsWith(matrix.dockerfile, 'Dockerfile')] }} - type=semver,pattern={{major}},enable=${{ github.event.release.prerelease == 0 }},suffix=${{ fromJSON('["-bullseye", "-buster"]')[endsWith(matrix.dockerfile, 'Dockerfile')] }} - type=ref,event=branch,suffix=${{ fromJSON('["-bullseye", "-buster"]')[endsWith(matrix.dockerfile, 'Dockerfile')] }},enable=${{ github.event.release.prerelease == 0 && env.GITHUB_REF_SLUG != 'master' }} - type=ref,event=pr,suffix=${{ fromJSON('["-bullseye", "-buster"]')[endsWith(matrix.dockerfile, 'Dockerfile')] }} - type=raw,enable=${{ env.GITHUB_REF_SLUG == 'master' }},priority=200,prefix=,suffix=${{ fromJSON('["bullseye", "buster"]')[endsWith(matrix.dockerfile, 'Dockerfile')] }},value= + type=semver,pattern={{version}},suffix=${{ matrix.dockerfile }} + type=semver,pattern={{major}},enable=${{ github.event.release.prerelease == 0 }},suffix=${{ matrix.dockerfile }} + type=ref,event=branch,suffix=${{ matrix.dockerfile }},enable=${{ github.event.release.prerelease == 0 && env.GITHUB_REF_SLUG != 'master' }} + type=ref,event=pr,suffix=${{ matrix.dockerfile }} + type=raw,enable=${{ env.GITHUB_REF_SLUG == 'master' }},priority=200,prefix=,suffix=${{ matrix.dockerfile }},value= - name: Build and push cross compiled fhem, python and nodejs layer on supported platforms uses: docker/build-push-action@v5 @@ -303,7 +303,7 @@ jobs: with: context: . load: false - file: ./${{ matrix.dockerfile }} + file: ./Dockerfile${{ matrix.dockerfile }} platforms: linux/amd64,linux/arm/v7,linux/arm64 push: ${{ github.event_name != 'pull_request' }} target: with-fhem-python-nodejs @@ -323,7 +323,7 @@ jobs: 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 - L_DESCR=A full blown Docker image for FHEM house automation system, based on Debian ${{ fromJSON('["bullseye", "buster"]')[endsWith(matrix.dockerfile, 'Dockerfile')] }}. + L_DESCR=A full blown Docker image for FHEM house automation system, based on Debian Perl ${{ matrix.dockerfile }}. - name: Docker meta id: meta_base @@ -335,11 +335,11 @@ jobs: flavor: | latest= ${{ fromJSON('["auto", "false"]')[github.event.release.prerelease == 1] }} tags: | - type=semver,pattern={{version}},suffix=${{ fromJSON('["-bullseye", "-buster"]')[endsWith(matrix.dockerfile, 'Dockerfile')] }} - type=semver,pattern={{major}},enable=${{ github.event.release.prerelease == 0 }},suffix=${{ fromJSON('["-bullseye", "-buster"]')[endsWith(matrix.dockerfile, 'Dockerfile')] }} - type=ref,event=branch,suffix=${{ fromJSON('["-bullseye", "-buster"]')[endsWith(matrix.dockerfile, 'Dockerfile')] }},enable=${{ github.event.release.prerelease == 0 && env.GITHUB_REF_SLUG != 'master' }} - type=ref,event=pr,suffix=${{ fromJSON('["-bullseye", "-buster"]')[endsWith(matrix.dockerfile, 'Dockerfile')] }} - type=raw,enable=${{ env.GITHUB_REF_SLUG == 'master' }},priority=200,prefix=,suffix=${{ fromJSON('["bullseye", "buster"]')[endsWith(matrix.dockerfile, 'Dockerfile')] }},value= + type=semver,pattern={{version}},suffix=${{ matrix.dockerfile }} + type=semver,pattern={{major}},enable=${{ github.event.release.prerelease == 0 }},suffix=${{ matrix.dockerfile }} + type=ref,event=branch,suffix=${{ matrix.dockerfile }},enable=${{ github.event.release.prerelease == 0 && env.GITHUB_REF_SLUG != 'master' }} + type=ref,event=pr,suffix=${{ matrix.dockerfile }} + type=raw,enable=${{ env.GITHUB_REF_SLUG == 'master' }},priority=200,prefix=,suffix=${{ matrix.dockerfile }},value= - name: Build and push cross compiled base image on supported platforms uses: docker/build-push-action@v5 @@ -347,7 +347,7 @@ jobs: with: context: . load: false - file: ./${{ matrix.dockerfile }} + file: ./Dockerfile${{ matrix.dockerfile }} platforms: linux/386,linux/amd64,linux/arm/v7,linux/arm64 push: ${{ github.event_name != 'pull_request' }} target: with-fhem @@ -368,4 +368,4 @@ jobs: 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 - L_DESCR=A minimal (perl) Docker image for FHEM house automation system, based on Debian ${{ fromJSON('["bullseye", "buster"]')[endsWith(matrix.dockerfile, 'Dockerfile')] }}. + L_DESCR=A minimal (perl) Docker image for FHEM house automation system, based on Debian Perl ${{ matrix.dockerfile }}. diff --git a/Dockerfile-threaded-bullseye b/Dockerfile-threaded-bullseye new file mode 100644 index 00000000..a2497848 --- /dev/null +++ b/Dockerfile-threaded-bullseye @@ -0,0 +1,308 @@ +# syntax=docker/dockerfile:1 +# +# base layer with perl and some general preparations +# +FROM perl:5.36.3-threaded-bullseye as base + +ARG TARGETPLATFORM + +ENV LANG=en_US.UTF-8 \ + LANGUAGE=en_US:en \ + LC_ADDRESS=de_DE.UTF-8 \ + LC_MEASUREMENT=de_DE.UTF-8 \ + LC_MESSAGES=en_DK.UTF-8 \ + LC_MONETARY=de_DE.UTF-8 \ + LC_NAME=de_DE.UTF-8 \ + LC_NUMERIC=de_DE.UTF-8 \ + LC_PAPER=de_DE.UTF-8 \ + LC_TELEPHONE=de_DE.UTF-8 \ + LC_TIME=de_DE.UTF-8 \ + TERM=xterm \ + TZ=Europe/Berlin + +RUN </etc/locale.gen + LC_ALL=C locale-gen + ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime + echo "Europe/Berlin" > /etc/timezone + LC_ALL=C DEBIAN_FRONTEND=noninteractive dpkg-reconfigure tzdata + LC_ALL=C apt-get autoremove -qqy && LC_ALL=C apt-get clean + rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* ~/.[^.] ~/.??* ~/* +EOF + +RUN < /root/cpanfile + sed -i '/Device::Firmata::Constants/d' root/cpanfile >/root/cpanfile + fi + cpanm --notest --cpanfile /root/cpanfile --installdeps . + rm -rf /root/.cpanm +EOF + +RUN < /root/cpanfile_3rdparty + sed -i '/Device::Firmata::Constants/d' /root/cpanfile_3rdparty > /root/cpanfile_3rdparty + fi + + cpanm --notest --cpanfile /root/cpanfile_3rdparty --installdeps --with-suggests . + rm -rf /root/.cpanm +EOF + + + +# +# Standard FHEM Layer +# +FROM base-cpan as with-fhem + +# Install base environment, cache is invalidated here, because we set a BUILD_DATE Variable which changes every run. +COPY src/entry.sh src/health-check.sh src/ssh_known_hosts.txt / +COPY src/find-* /usr/local/bin/ + +# Add FHEM app layer +# Note: Manual checkout is required if build is not run by Github Actions workflow: +# svn co https://svn.fhem.de/fhem/trunk ./src/fhem/trunk +#COPY src/fhem/trunk/fhem/ /fhem/ +#COPY src/FHEM/trunk/fhem/* /fhem/ + +COPY src/FHEM/99_DockerImageInfo.pm /fhem/FHEM/ + +# FHEM specific ENVs +ENV LOGFILE=./log/fhem-%Y-%m-%d.log \ + TELNETPORT=7072 \ + FHEM_UID=6061 \ + FHEM_GID=6061 \ + FHEM_PERM_DIR=0750 \ + FHEM_PERM_FILE=0640 \ + UMASK=0037 \ + BLUETOOTH_GID=6001 \ + GPIO_GID=6002 \ + I2C_GID=6003 \ + TIMEOUT=10 \ + CONFIGTYPE=fhem.cfg + +# Moved AGS to the end, because it changes every run and invalidates the cache for all following steps https://github.com/moby/moby/issues/20136 +# Arguments to instantiate as variables +ARG PLATFORM="linux" +ARG TAG="" +ARG IMAGE_VCS_REF="" +ARG IMAGE_VERSION="" +ARG BUILD_DATE="" + +# Re-usable variables during build +ARG L_AUTHORS="" +ARG L_URL="https://hub.docker.com/r/fhem/fhem-${TARGETPLATFORM}" +ARG L_USAGE="https://github.com/fhem/fhem-docker/blob/${IMAGE_VCS_REF}/README.md" +ARG L_VCS_URL="https://github.com/fhem/fhem-docker/" +ARG L_VENDOR="FHEM" +ARG L_LICENSES="MIT" +ARG L_TITLE="fhem-${TARGETPLATFORM}" +ARG L_DESCR="A basic Docker image for FHEM house automation system, based on Debian Bullseye Perl image." + +ARG L_AUTHORS_FHEM="https://fhem.de/MAINTAINER.txt" +ARG L_URL_FHEM="https://fhem.de/" +ARG L_USAGE_FHEM="https://fhem.de/#Documentation" +ARG L_VCS_URL_FHEM="https://svn.fhem.de/" +ARG L_VENDOR_FHEM="FHEM e.V." +ARG L_LICENSES_FHEM="GPL-2.0" +ARG L_DESCR_FHEM="FHEM (TM) is a GPL'd perl server for house automation. It is used to automate some common tasks in the household like switching lamps / shutters / heating / etc. and to log events like temperature / humidity / power consumption." + + +# non-standard labels +LABEL org.fhem.authors=${L_AUTHORS_FHEM} \ + org.fhem.url=${L_URL_FHEM} \ + org.fhem.documentation=${L_USAGE_FHEM} \ + org.fhem.source=${L_VCS_URL_FHEM} \ + org.fhem.vendor=${L_VENDOR_FHEM} \ + org.fhem.licenses=${L_LICENSES_FHEM} \ + org.fhem.description=${L_DESCR_FHEM} + +# annotation labels according to +# https://github.com/opencontainers/image-spec/blob/v1.0.1/annotations.md#pre-defined-annotation-keys +LABEL org.opencontainers.image.created=${BUILD_DATE} \ + org.opencontainers.image.authors=${L_AUTHORS} \ + org.opencontainers.image.url=${L_URL} \ + org.opencontainers.image.documentation=${L_USAGE} \ + org.opencontainers.image.source=${L_VCS_URL} \ + org.opencontainers.image.version=${IMAGE_VERSION} \ + org.opencontainers.image.revision=${IMAGE_VCS_REF} \ + org.opencontainers.image.vendor=${L_VENDOR} \ + org.opencontainers.image.licenses=${L_LICENSES} \ + org.opencontainers.image.title=${L_TITLE} \ + org.opencontainers.image.description=${L_DESCR} + +RUN chmod 755 /*.sh /usr/local/bin/* \ + && echo "org.opencontainers.image.created=${BUILD_DATE}\norg.opencontainers.image.authors=${L_AUTHORS}\norg.opencontainers.image.url=${L_URL}\norg.opencontainers.image.documentation=${L_USAGE}\norg.opencontainers.image.source=${L_VCS_URL}\norg.opencontainers.image.version=${IMAGE_VERSION}\norg.opencontainers.image.revision=${IMAGE_VCS_REF}\norg.opencontainers.image.vendor=${L_VENDOR}\norg.opencontainers.image.licenses=${L_LICENSES}\norg.opencontainers.image.title=${L_TITLE}\norg.opencontainers.image.description=${L_DESCR}\norg.fhem.authors=${L_AUTHORS_FHEM}\norg.fhem.url=${L_URL_FHEM}\norg.fhem.documentation=${L_USAGE_FHEM}\norg.fhem.source=${L_VCS_URL_FHEM}\norg.fhem.version=${FHEM_VERSION}\norg.fhem.vendor=${L_VENDOR_FHEM}\norg.fhem.licenses=${L_LICENSES_FHEM}\norg.fhem.description=${L_DESCR_FHEM}" > /image_info + +VOLUME [ "/opt/fhem" ] + +EXPOSE 8083 + +HEALTHCHECK --interval=20s --timeout=10s --start-period=60s --retries=5 CMD /health-check.sh + +WORKDIR "/opt/fhem" +ENTRYPOINT [ "/entry.sh" ] +CMD [ "start" ] + +# +# Add additional Python layer +# + +FROM with-fhem as with-fhem-python + +RUN < Date: Sun, 10 Mar 2024 00:50:05 +0100 Subject: [PATCH 2/5] Update build.yml Fix filename reference --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dc8f6223..f115676c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -176,7 +176,7 @@ jobs: with: context: . load: true - file: ./${{ matrix.dockerfile }} + file: ./Dockerfile${{ matrix.dockerfile }} platforms: linux/amd64 push: false target: with-fhem-bats From 651c88a98b82ce4bf2f665f10d95f57c3f5c9cbc Mon Sep 17 00:00:00 2001 From: sidey79 <7968127+sidey79@users.noreply.github.com> Date: Sun, 10 Mar 2024 09:10:27 +0100 Subject: [PATCH 3/5] Update build.yml Fix filename --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f115676c..2da0696d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -204,7 +204,7 @@ jobs: with: context: . load: true - file: ./${{ matrix.dockerfile }} + file: ./Dockerfile${{ matrix.dockerfile }} platforms: linux/amd64 push: false target: with-fhem-python-nodejs From 6ce04375051b3772304fe593568bcc412e2f40b2 Mon Sep 17 00:00:00 2001 From: sidey79 <7968127+sidey79@users.noreply.github.com> Date: Sun, 10 Mar 2024 15:16:39 +0100 Subject: [PATCH 4/5] docs[Readme]: updated with threads tag --- README.md | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 05a9322d..a309e2f8 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Reccomended pulling from [Github Container Registry](https://github.com/orgs/fhe Updated versions based on - debian bullseye -- Perl 5.36.3 +- Perl 5.36.3 (optional threaded) - NodeJS 18 LTS - Python 3.9.2 - Python 2.7.18 @@ -30,6 +30,7 @@ Updated versions based on - NOTE: alexa-fhem, alexa-cookie, gassistant-fhem, homebridge, homebridge-fhem, tradfri-fhem are not installed per default! docker pull ghcr.io/fhem/fhem-docker:4-bullseye + docker pull ghcr.io/fhem/fhem-docker:4-threaded-bullseye ##### Not updated anymore since Jan 2024 @@ -49,12 +50,13 @@ Updated versions based on #### Image with perl core services installed - debian bullseye -- Perl 5.36.3 +- Perl 5.36.3 (optional threaded) - Python 3.9.2 - Python 2.7.18 - Supported Plattforms: linux/amd64, linux/arm/v7, linux/arm64, linux/i386, docker pull ghcr.io/fhem/fhem-minimal-docker:4-bullseye + docker pull ghcr.io/fhem/fhem-minimal-docker:4-threaded-bullseye ##### Not updated anymore since Jan 2024 @@ -69,17 +71,17 @@ Updated versions based on #### To start your container right away: - docker run -d --name fhem -p 8083:8083 ghcr.io/fhem/fhem/fhem-docker:4-bullseye + docker run -d --name fhem -p 8083:8083 ghcr.io/fhem/fhem-docker:4-bullseye #### Storage Usually you want to keep your FHEM setup after a container was destroyed (or re-build) so it is a good idea to provide an external directory on your Docker host to keep that data: - docker run -d --name fhem -p 8083:8083 -v /some/host/directory:/opt/fhem ghcr.io/fhem/fhem/fhem-docker:4-bullseye + docker run -d --name fhem -p 8083:8083 -v /some/host/directory:/opt/fhem ghcr.io/fhem/fhem-docker:4-bullseye You will find more general information about using volumes from the Docker documentation for [Use volumes](https://docs.docker.com/storage/volumes/) and [Bind mounts](https://docs.docker.com/storage/bind-mounts/). -It is also possible to mount CIFS mounts directly +It is also possible to mount CIFS mounts directly. ### Access FHEM @@ -100,7 +102,8 @@ Note that any existing FHEM installation you are mounting into the container wil The FHEM log file is mirrored to the Docker console output in order to give input for any Docker related tools. However, if the log file becomes too big, this will lead to some performance implications. For that reason, the default value of the global attribute `logfile` is different from the FHEM default configuration and set to a daily file (`attr global logfile ./log/fhem-%Y-%m-%d.log`). -It is highly recommended to keep this setting. Please note that FileLog devices might still need to be checked and adjusted manually if you would like to properly watch the log file from within FHEM. +It is highly recommended to keep this setting. Please note that FileLog are only patched if fhem is fresh installed. +Devices might still need to be checked and adjusted manually if you would like to properly watch the log file from within FHEM. ### Add custom packages From 66438672ded79de8d9510e84fc84cff7f098e062 Mon Sep 17 00:00:00 2001 From: sidey79 <7968127+sidey79@users.noreply.github.com> Date: Sun, 10 Mar 2024 15:40:54 +0100 Subject: [PATCH 5/5] pipeline[build.yml]: Change latest tag detection --- .github/workflows/build.yml | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2da0696d..f718c90c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -117,6 +117,8 @@ jobs: matrix: dockerfile: [-bullseye, -threaded-bullseye] # Steps represent a sequence of tasks that will be executed as part of the job + env: + TAG_LATEST: ${{ (contains(matrix.dockerfile,'threaded') && github.event.release.prerelease == 1) && 'false' || 'auto' }} steps: - name: Checkout this repository uses: actions/checkout@v4 @@ -163,7 +165,7 @@ jobs: ghcr.io/${{ github.repository_owner }}/fhem-docker fhem/fhem flavor: | - latest= ${{ fromJSON('["auto", "false"]')[github.event.release.prerelease == 1 || endsWith(matrix.dockerfile, 'Dockerfile')] }} + latest= ${{ env.TAG_LATEST }} tags: | type=semver,pattern={{version}},suffix=${{ matrix.dockerfile }} type=semver,pattern={{major}},enable=${{ github.event.release.prerelease == 0 }},suffix=${{ matrix.dockerfile }} @@ -245,7 +247,8 @@ jobs: strategy: matrix: dockerfile: [-bullseye, -threaded-bullseye] - + env: + TAG_LATEST: ${{ (contains(matrix.dockerfile,'threaded') && github.event.release.prerelease == 1) && 'false' || 'auto' }} # Steps represent a sequence of tasks that will be executed as part of the job steps: - name: Checkout this repository @@ -289,7 +292,7 @@ jobs: ghcr.io/${{ github.repository_owner }}/fhem-docker fhem/fhem flavor: | - latest= ${{ fromJSON('["auto", "false"]')[github.event.release.prerelease == 1] }} + latest= ${{ env.TAG_LATEST }} tags: | type=semver,pattern={{version}},suffix=${{ matrix.dockerfile }} type=semver,pattern={{major}},enable=${{ github.event.release.prerelease == 0 }},suffix=${{ matrix.dockerfile }} @@ -333,7 +336,7 @@ jobs: ghcr.io/${{ github.repository_owner }}/fhem-minimal-docker fhem/fhem-minimal flavor: | - latest= ${{ fromJSON('["auto", "false"]')[github.event.release.prerelease == 1] }} + latest= ${{ env.TAG_LATEST }} tags: | type=semver,pattern={{version}},suffix=${{ matrix.dockerfile }} type=semver,pattern={{major}},enable=${{ github.event.release.prerelease == 0 }},suffix=${{ matrix.dockerfile }}