From f7677543c69ebe7389a2f7e6e593427562eb45f3 Mon Sep 17 00:00:00 2001 From: Dimitri Huisman Date: Thu, 18 Nov 2021 17:21:56 +0000 Subject: [PATCH] Process code review remarks - Moved run to bottom of Dockerfile to allow using unmodified / cached states. - Simplified bash code in deploy.sh. - Improved the large bash one-liner in CI.yml. It could not handle >9 for 1.x. --- .github/workflows/CI.yml | 22 +++++++++++----------- core/admin/Dockerfile | 2 +- core/dovecot/Dockerfile | 2 +- core/nginx/Dockerfile | 2 +- core/postfix/Dockerfile | 2 +- core/rspamd/Dockerfile | 2 +- docs/Dockerfile | 2 +- optional/clamav/Dockerfile | 2 +- optional/fetchmail/Dockerfile | 4 ++-- optional/postgresql/Dockerfile | 2 +- optional/radicale/Dockerfile | 2 +- optional/traefik-certdumper/Dockerfile | 2 +- optional/unbound/Dockerfile | 2 +- setup/Dockerfile | 3 ++- tests/deploy.sh | 4 ++-- webmails/rainloop/Dockerfile | 2 +- webmails/roundcube/Dockerfile | 2 +- 17 files changed, 30 insertions(+), 29 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 2a0ff932..8cc174f7 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -27,8 +27,8 @@ on: # Code block that is used as one liner. ##!/bin/bash #version=$( git tag --list "{{ env.MAILU_VERSION }}.*" | tail -1 ) -#root_version=${version:0:3} -#patch_version=${version:4:4} +#root_version=${version%.*} +#patch_version=${version##*.} #if [ "$patch_version" == "" ] #then # pinned_version={{ env.MAILU_VERSION }}.0 @@ -73,7 +73,7 @@ jobs: if: ${{ env.BRANCH != 'testing' && env.BRANCH != 'staging' && env.BRANCH != 'master' }} shell: bash run: | - version=$( git tag --list "${{ env.MAILU_VERSION }}.*" | tail -1 );root_version=${version:0:3};patch_version=${version:4:4};if [ "$patch_version" == "" ]; then pinned_version=${{ env.MAILU_VERSION }}.0; else pinned_version=$root_version.$(expr $patch_version + 1); fi;echo "PINNED_MAILU_VERSION=$pinned_version" >> $GITHUB_ENV + version=$( git tag --list "${{ env.MAILU_VERSION }}.*" | tail -1 );root_version=${version%.*};patch_version=${version##*.};if [ "$patch_version" == "" ]; then pinned_version=${{ env.MAILU_VERSION }}.0; else pinned_version=$root_version.$(expr $patch_version + 1); fi;echo "PINNED_MAILU_VERSION=$pinned_version" >> $GITHUB_ENV - name: Derive PINNED_MAILU_VERSION for staging if: ${{ env.BRANCH == 'staging' }} shell: bash @@ -149,7 +149,7 @@ jobs: if: ${{ env.BRANCH != 'testing' && env.BRANCH != 'master' }} shell: bash run: | - version=$( git tag --list "${{ env.MAILU_VERSION }}.*" | tail -1 );root_version=${version:0:3};patch_version=${version:4:4};if [ "$patch_version" == "" ]; then pinned_version=${{ env.MAILU_VERSION }}.0; else pinned_version=$root_version.$(expr $patch_version + 1); fi;echo "PINNED_MAILU_VERSION=$pinned_version" >> $GITHUB_ENV + version=$( git tag --list "${{ env.MAILU_VERSION }}.*" | tail -1 );root_version=${version%.*};patch_version=${version##*.};if [ "$patch_version" == "" ]; then pinned_version=${{ env.MAILU_VERSION }}.0; else pinned_version=$root_version.$(expr $patch_version + 1); fi;echo "PINNED_MAILU_VERSION=$pinned_version" >> $GITHUB_ENV - name: Derive PINNED_MAILU_VERSION for staging if: ${{ env.BRANCH == 'staging' }} shell: bash @@ -221,7 +221,7 @@ jobs: if: ${{ env.BRANCH != 'testing' && env.BRANCH != 'master' }} shell: bash run: | - version=$( git tag --list "${{ env.MAILU_VERSION }}.*" | tail -1 );root_version=${version:0:3};patch_version=${version:4:4};if [ "$patch_version" == "" ]; then pinned_version=${{ env.MAILU_VERSION }}.0; else pinned_version=$root_version.$(expr $patch_version + 1); fi;echo "PINNED_MAILU_VERSION=$pinned_version" >> $GITHUB_ENV + version=$( git tag --list "${{ env.MAILU_VERSION }}.*" | tail -1 );root_version=${version%.*};patch_version=${version##*.};if [ "$patch_version" == "" ]; then pinned_version=${{ env.MAILU_VERSION }}.0; else pinned_version=$root_version.$(expr $patch_version + 1); fi;echo "PINNED_MAILU_VERSION=$pinned_version" >> $GITHUB_ENV - name: Derive PINNED_MAILU_VERSION for staging if: ${{ env.BRANCH == 'staging' }} shell: bash @@ -293,7 +293,7 @@ jobs: if: ${{ env.BRANCH != 'testing' && env.BRANCH != 'master' }} shell: bash run: | - version=$( git tag --list "${{ env.MAILU_VERSION }}.*" | tail -1 );root_version=${version:0:3};patch_version=${version:4:4};if [ "$patch_version" == "" ]; then pinned_version=${{ env.MAILU_VERSION }}.0; else pinned_version=$root_version.$(expr $patch_version + 1); fi;echo "PINNED_MAILU_VERSION=$pinned_version" >> $GITHUB_ENV + version=$( git tag --list "${{ env.MAILU_VERSION }}.*" | tail -1 );root_version=${version%.*};patch_version=${version##*.};if [ "$patch_version" == "" ]; then pinned_version=${{ env.MAILU_VERSION }}.0; else pinned_version=$root_version.$(expr $patch_version + 1); fi;echo "PINNED_MAILU_VERSION=$pinned_version" >> $GITHUB_ENV - name: Derive PINNED_MAILU_VERSION for staging if: ${{ env.BRANCH == 'staging' }} shell: bash @@ -365,7 +365,7 @@ jobs: if: ${{ env.BRANCH != 'testing' && env.BRANCH != 'master' }} shell: bash run: | - version=$( git tag --list "${{ env.MAILU_VERSION }}.*" | tail -1 );root_version=${version:0:3};patch_version=${version:4:4};if [ "$patch_version" == "" ]; then pinned_version=${{ env.MAILU_VERSION }}.0; else pinned_version=$root_version.$(expr $patch_version + 1); fi;echo "PINNED_MAILU_VERSION=$pinned_version" >> $GITHUB_ENV + version=$( git tag --list "${{ env.MAILU_VERSION }}.*" | tail -1 );root_version=${version%.*};patch_version=${version##*.};if [ "$patch_version" == "" ]; then pinned_version=${{ env.MAILU_VERSION }}.0; else pinned_version=$root_version.$(expr $patch_version + 1); fi;echo "PINNED_MAILU_VERSION=$pinned_version" >> $GITHUB_ENV - name: Derive PINNED_MAILU_VERSION for staging if: ${{ env.BRANCH == 'staging' }} shell: bash @@ -437,7 +437,7 @@ jobs: if: ${{ env.BRANCH != 'testing' && env.BRANCH != 'master' }} shell: bash run: | - version=$( git tag --list "${{ env.MAILU_VERSION }}.*" | tail -1 );root_version=${version:0:3};patch_version=${version:4:4};if [ "$patch_version" == "" ]; then pinned_version=${{ env.MAILU_VERSION }}.0; else pinned_version=$root_version.$(expr $patch_version + 1); fi;echo "PINNED_MAILU_VERSION=$pinned_version" >> $GITHUB_ENV + version=$( git tag --list "${{ env.MAILU_VERSION }}.*" | tail -1 );root_version=${version%.*};patch_version=${version##*.};if [ "$patch_version" == "" ]; then pinned_version=${{ env.MAILU_VERSION }}.0; else pinned_version=$root_version.$(expr $patch_version + 1); fi;echo "PINNED_MAILU_VERSION=$pinned_version" >> $GITHUB_ENV - name: Derive PINNED_MAILU_VERSION for staging if: ${{ env.BRANCH == 'staging' }} shell: bash @@ -509,7 +509,7 @@ jobs: if: ${{ env.BRANCH != 'testing' && env.BRANCH != 'master' }} shell: bash run: | - version=$( git tag --list "${{ env.MAILU_VERSION }}.*" | tail -1 );root_version=${version:0:3};patch_version=${version:4:4};if [ "$patch_version" == "" ]; then pinned_version=${{ env.MAILU_VERSION }}.0; else pinned_version=$root_version.$(expr $patch_version + 1); fi;echo "PINNED_MAILU_VERSION=$pinned_version" >> $GITHUB_ENV + version=$( git tag --list "${{ env.MAILU_VERSION }}.*" | tail -1 );root_version=${version%.*};patch_version=${version##*.};if [ "$patch_version" == "" ]; then pinned_version=${{ env.MAILU_VERSION }}.0; else pinned_version=$root_version.$(expr $patch_version + 1); fi;echo "PINNED_MAILU_VERSION=$pinned_version" >> $GITHUB_ENV - name: Derive PINNED_MAILU_VERSION for staging if: ${{ env.BRANCH == 'staging' }} shell: bash @@ -587,7 +587,7 @@ jobs: if: ${{ env.BRANCH != 'testing' && env.BRANCH != 'master' }} shell: bash run: | - version=$( git tag --list "${{ env.MAILU_VERSION }}.*" | tail -1 );root_version=${version:0:3};patch_version=${version:4:4};if [ "$patch_version" == "" ]; then pinned_version=${{ env.MAILU_VERSION }}.0; else pinned_version=$root_version.$(expr $patch_version + 1); fi;echo "PINNED_MAILU_VERSION=$pinned_version" >> $GITHUB_ENV + version=$( git tag --list "${{ env.MAILU_VERSION }}.*" | tail -1 );root_version=${version%.*};patch_version=${version##*.};if [ "$patch_version" == "" ]; then pinned_version=${{ env.MAILU_VERSION }}.0; else pinned_version=$root_version.$(expr $patch_version + 1); fi;echo "PINNED_MAILU_VERSION=$pinned_version" >> $GITHUB_ENV - name: Derive PINNED_MAILU_VERSION for staging if: ${{ env.BRANCH == 'staging' }} shell: bash @@ -649,7 +649,7 @@ jobs: if: ${{ env.BRANCH != 'testing' && env.BRANCH != 'staging' && env.BRANCH != 'master' }} shell: bash run: | - version=$( git tag --list "${{ env.MAILU_VERSION }}.*" | tail -1 );root_version=${version:0:3};patch_version=${version:4:4};if [ "$patch_version" == "" ]; then pinned_version=${{ env.MAILU_VERSION }}.0; else pinned_version=$root_version.$(expr $patch_version + 1); fi;echo "PINNED_MAILU_VERSION=$pinned_version" >> $GITHUB_ENV + version=$( git tag --list "${{ env.MAILU_VERSION }}.*" | tail -1 );root_version=${version%.*};patch_version=${version##*.};if [ "$patch_version" == "" ]; then pinned_version=${{ env.MAILU_VERSION }}.0; else pinned_version=$root_version.$(expr $patch_version + 1); fi;echo "PINNED_MAILU_VERSION=$pinned_version" >> $GITHUB_ENV - name: Tag and create release if: ${{ env.BRANCH != 'testing' && env.BRANCH != 'staging' && env.BRANCH != 'master' && env.PINNED_MAILU_VERSION != '' }} uses: ncipollo/release-action@v1 diff --git a/core/admin/Dockerfile b/core/admin/Dockerfile index ac8ae9fc..fde7c877 100644 --- a/core/admin/Dockerfile +++ b/core/admin/Dockerfile @@ -27,7 +27,6 @@ COPY --from=balenalib/rpi-alpine:3.14 /usr/bin/qemu-arm-static /usr/bin/qemu-arm ENV TZ Etc/UTC LABEL version=$VERSION -RUN echo $VERSION >> /version # python3 shared with most images RUN set -eu \ @@ -60,3 +59,4 @@ ENV FLASK_APP mailu CMD /start.py HEALTHCHECK CMD curl -f -L http://localhost/sso/login?next=ui.index || exit 1 +RUN echo $VERSION >> /version \ No newline at end of file diff --git a/core/dovecot/Dockerfile b/core/dovecot/Dockerfile index 791b6c04..16f35490 100644 --- a/core/dovecot/Dockerfile +++ b/core/dovecot/Dockerfile @@ -15,7 +15,6 @@ ARG VERSION ENV TZ Etc/UTC LABEL version=$VERSION -RUN echo $VERSION >> /version # python3 shared with most images RUN apk add --no-cache \ @@ -44,3 +43,4 @@ VOLUME ["/mail"] CMD /start.py HEALTHCHECK --start-period=350s CMD echo QUIT|nc localhost 110|grep "Dovecot ready." +RUN echo $VERSION >> /version \ No newline at end of file diff --git a/core/nginx/Dockerfile b/core/nginx/Dockerfile index e5d30073..744de810 100644 --- a/core/nginx/Dockerfile +++ b/core/nginx/Dockerfile @@ -5,7 +5,6 @@ ARG VERSION ENV TZ Etc/UTC LABEL version=$VERSION -RUN echo $VERSION >> /version # python3 shared with most images RUN apk add --no-cache \ @@ -32,3 +31,4 @@ VOLUME ["/overrides"] CMD /start.py HEALTHCHECK CMD curl -k -f -L http://localhost/health || exit 1 +RUN echo $VERSION >> /version \ No newline at end of file diff --git a/core/postfix/Dockerfile b/core/postfix/Dockerfile index 5c6238b3..deedd9b8 100644 --- a/core/postfix/Dockerfile +++ b/core/postfix/Dockerfile @@ -6,7 +6,6 @@ ARG VERSION ENV TZ Etc/UTC LABEL version=$VERSION -RUN echo $VERSION >> /version # python3 shared with most images RUN apk add --no-cache \ @@ -35,3 +34,4 @@ VOLUME ["/queue"] CMD /start.py HEALTHCHECK --start-period=350s CMD echo QUIT|nc localhost 25|grep "220 .* ESMTP Postfix" +RUN echo $VERSION >> /version \ No newline at end of file diff --git a/core/rspamd/Dockerfile b/core/rspamd/Dockerfile index d1172ffc..59e6fefa 100644 --- a/core/rspamd/Dockerfile +++ b/core/rspamd/Dockerfile @@ -4,7 +4,6 @@ ARG VERSION ENV TZ Etc/UTC LABEL version=$VERSION -RUN echo $VERSION >> /version # python3 shared with most images RUN apk add --no-cache \ @@ -29,3 +28,4 @@ VOLUME ["/var/lib/rspamd"] CMD /start.py HEALTHCHECK --start-period=350s CMD curl -f -L http://localhost:11334/ || exit 1 +RUN echo $VERSION >> /version \ No newline at end of file diff --git a/docs/Dockerfile b/docs/Dockerfile index b3d1af01..18ca8333 100644 --- a/docs/Dockerfile +++ b/docs/Dockerfile @@ -23,7 +23,6 @@ ARG pinned_version=master ENV VERSION=$version ENV TZ Etc/UTC LABEL version=$VERSION -RUN echo $pinned_version >> /version COPY ./nginx.conf /etc/nginx/conf.d/default.conf COPY --from=build /build/$VERSION /build/$VERSION @@ -31,3 +30,4 @@ COPY --from=build /build/$VERSION /build/$VERSION EXPOSE 80/tcp CMD nginx -g "daemon off;" +RUN echo $pinned_version >> /version \ No newline at end of file diff --git a/optional/clamav/Dockerfile b/optional/clamav/Dockerfile index c68b8888..97a47d30 100644 --- a/optional/clamav/Dockerfile +++ b/optional/clamav/Dockerfile @@ -5,7 +5,6 @@ ARG VERSION ENV TZ Etc/UTC LABEL version=$VERSION -RUN echo $VERSION >> /version # python3 shared with most images RUN apk add --no-cache \ @@ -24,3 +23,4 @@ VOLUME ["/data"] CMD /start.py HEALTHCHECK --start-period=350s CMD /health.sh +RUN echo $VERSION >> /version \ No newline at end of file diff --git a/optional/fetchmail/Dockerfile b/optional/fetchmail/Dockerfile index 3c670bca..81ccc2d1 100644 --- a/optional/fetchmail/Dockerfile +++ b/optional/fetchmail/Dockerfile @@ -5,7 +5,6 @@ ARG VERSION ENV TZ Etc/UTC LABEL version=$VERSION -RUN echo $VERSION >> /version # python3 shared with most images RUN apk add --no-cache \ @@ -20,4 +19,5 @@ RUN mkdir -p /data COPY fetchmail.py /fetchmail.py -CMD ["/fetchmail.py"] \ No newline at end of file +CMD ["/fetchmail.py"] +RUN echo $VERSION >> /version \ No newline at end of file diff --git a/optional/postgresql/Dockerfile b/optional/postgresql/Dockerfile index 14d879f3..e66096ec 100644 --- a/optional/postgresql/Dockerfile +++ b/optional/postgresql/Dockerfile @@ -5,7 +5,6 @@ ARG VERSION ENV TZ Etc/UTC LABEL version=$VERSION -RUN echo $VERSION >> /version # python3 shared with most images RUN apk add --no-cache \ @@ -41,3 +40,4 @@ EXPOSE 5432 CMD /start.py HEALTHCHECK CMD psql -h 127.0.0.1 -d postgres -U health -c "select 1 as ok;" || exit 1 +RUN echo $VERSION >> /version \ No newline at end of file diff --git a/optional/radicale/Dockerfile b/optional/radicale/Dockerfile index 2eee6915..93796eb1 100644 --- a/optional/radicale/Dockerfile +++ b/optional/radicale/Dockerfile @@ -5,7 +5,6 @@ ARG VERSION ENV TZ Etc/UTC LABEL version=$VERSION -RUN echo $VERSION >> /version # python3 shared with most images RUN apk add --no-cache \ @@ -25,3 +24,4 @@ VOLUME ["/data"] CMD radicale -S -C /radicale.conf HEALTHCHECK CMD curl -f -L http://localhost:5232/ || exit 1 +RUN echo $VERSION >> /version \ No newline at end of file diff --git a/optional/traefik-certdumper/Dockerfile b/optional/traefik-certdumper/Dockerfile index 1aecc48e..829655f0 100644 --- a/optional/traefik-certdumper/Dockerfile +++ b/optional/traefik-certdumper/Dockerfile @@ -4,7 +4,6 @@ ARG VERSION ENV TZ Etc/UTC LABEL version=$VERSION -RUN echo $VERSION >> /version RUN apk --no-cache add inotify-tools util-linux bash tzdata @@ -14,3 +13,4 @@ VOLUME ["/traefik"] VOLUME ["/output"] ENTRYPOINT ["/run.sh"] +RUN echo $VERSION >> /version \ No newline at end of file diff --git a/optional/unbound/Dockerfile b/optional/unbound/Dockerfile index 501d562a..3a86cc6c 100644 --- a/optional/unbound/Dockerfile +++ b/optional/unbound/Dockerfile @@ -5,7 +5,6 @@ ARG VERSION ENV TZ Etc/UTC LABEL version=$VERSION -RUN echo $VERSION >> /version # python3 shared with most images RUN apk add --no-cache \ @@ -31,3 +30,4 @@ EXPOSE 53/udp 53/tcp CMD /start.py HEALTHCHECK CMD dig @127.0.0.1 || exit 1 +RUN echo $VERSION >> /version \ No newline at end of file diff --git a/setup/Dockerfile b/setup/Dockerfile index 0635566b..baa35da9 100644 --- a/setup/Dockerfile +++ b/setup/Dockerfile @@ -3,7 +3,7 @@ FROM $DISTRO ARG VERSION ENV TZ Etc/UTC LABEL version=$VERSION -RUN echo $VERSION >> /version + RUN mkdir -p /app WORKDIR /app @@ -21,3 +21,4 @@ COPY static ./static EXPOSE 80/tcp CMD gunicorn -w 4 -b :80 --access-logfile - --error-logfile - --preload main:app +RUN echo $VERSION >> /version \ No newline at end of file diff --git a/tests/deploy.sh b/tests/deploy.sh index 6913e404..e66310af 100755 --- a/tests/deploy.sh +++ b/tests/deploy.sh @@ -17,7 +17,7 @@ fi #After that, both tags are pushed to the docker repository. if [ "$PINNED_MAILU_VERSION" != "" ] && [ "$BRANCH" != "master" ] then - images=$(docker-compose -f tests/build.yml config | grep 'image: ' | awk -F ':' '{ print $2 }') + images=$(docker-compose -f Mailu/tests/build.yml config | awk -F ':' '/image:/{ print $2 }') for image in $images do docker tag "${image}":"${PINNED_MAILU_VERSION}" "${image}":${MAILU_VERSION} @@ -36,7 +36,7 @@ fi #Then we publish the images with tag master if [ "$PINNED_MAILU_VERSION" != "" ] && [ "$BRANCH" == "master" ] then - images=$(docker-compose -f tests/build.yml config | grep 'image: ' | awk -F ':' '{ print $2 }') + images=$(docker-compose -f Mailu/tests/build.yml config | awk -F ':' '/image:/{ print $2 }') for image in $images do docker tag "${image}":"${PINNED_MAILU_VERSION}" "${image}":${MAILU_VERSION} diff --git a/webmails/rainloop/Dockerfile b/webmails/rainloop/Dockerfile index 8039f69a..0938056c 100644 --- a/webmails/rainloop/Dockerfile +++ b/webmails/rainloop/Dockerfile @@ -8,7 +8,6 @@ ONBUILD COPY --from=balenalib/rpi-alpine:3.14 /usr/bin/qemu-arm-static /usr/bin/ ENV TZ Etc/UTC LABEL version=$VERSION -RUN echo $VERSION >> /version # Shared later between dovecot postfix nginx rspamd rainloop and roundloop RUN apk add --no-cache \ @@ -75,3 +74,4 @@ VOLUME ["/data"] CMD php-fpm7 && /start.py HEALTHCHECK CMD curl -f -L http://localhost/ || exit 1 +RUN echo $VERSION >> /version \ No newline at end of file diff --git a/webmails/roundcube/Dockerfile b/webmails/roundcube/Dockerfile index 5c411f84..f28f316c 100644 --- a/webmails/roundcube/Dockerfile +++ b/webmails/roundcube/Dockerfile @@ -11,7 +11,6 @@ ARG VERSION ENV TZ Etc/UTC LABEL version=$VERSION -RUN echo $VERSION >> /version #Shared layer between rainloop and roundcube RUN apt-get update && apt-get install -y \ @@ -62,3 +61,4 @@ VOLUME ["/data"] CMD /start.py HEALTHCHECK CMD curl -f -L -H 'User-Agent: health' http://localhost/ || exit 1 +RUN echo $VERSION >> /version \ No newline at end of file