diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 23c7a29..95da94c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,6 +15,8 @@ jobs: - name: Checkout HEAD uses: actions/checkout@v1 + - run: docker buildx create --use + - name: Icinga Web 2 run: git clone https://github.com/Icinga/icingaweb2.git diff --git a/Dockerfile b/Dockerfile index 79f2e6c..d278760 100644 --- a/Dockerfile +++ b/Dockerfile @@ -8,6 +8,23 @@ WORKDIR /entrypoint RUN ["go", "build", "."] +FROM composer:lts as usr-share +SHELL ["/bin/bash", "-exo", "pipefail", "-c"] + +RUN ["mkdir", "/usr-share"] +WORKDIR /usr-share + +ARG BUILD_MODE +COPY get-mods.sh / +RUN /get-mods.sh $BUILD_MODE + +COPY composer.bash / +RUN ["/composer.bash"] + +COPY --from=icingaweb2-git . /icingaweb2-src/.git +RUN git -C /icingaweb2-src archive --prefix=icingaweb2/ HEAD |tar -x + + FROM debian:bullseye-slim RUN ["bash", "-exo", "pipefail", "-c", "export DEBIAN_FRONTEND=noninteractive; apt-get update; apt-get install --no-install-{recommends,suggests} -y apache2 ca-certificates libapache2-mod-php7.4 libldap-common locales-all php-{imagick,redis} php7.4-{bcmath,bz2,common,curl,dba,enchant,gd,gmp,imap,interbase,intl,json,ldap,mbstring,mysql,odbc,opcache,pgsql,pspell,readline,snmp,soap,sqlite3,sybase,tidy,xml,xmlrpc,xsl,zip}; apt-get clean; rm -vrf /var/lib/apt/lists/*"] @@ -33,9 +50,7 @@ RUN ["install", "-o", "www-data", "-g", "www-data", "-d", "/data"] ENTRYPOINT ["/entrypoint"] -COPY icingaweb2 /usr/share/icingaweb2 -COPY icinga-php /usr/share/icinga-php -COPY icinga-L10n /usr/share/icinga-L10n +COPY --from=usr-share /usr-share/. /usr/share/ COPY php.ini /etc/php/7.4/cli/conf.d/99-docker.ini RUN ["ln", "-vs", "/usr/share/icingaweb2/bin/icingacli", "/usr/local/bin/"] diff --git a/action-base.list b/action-base.list deleted file mode 100644 index 8306e7c..0000000 --- a/action-base.list +++ /dev/null @@ -1,3 +0,0 @@ -# Icinga Web 2 Docker image | (c) 2020 Icinga GmbH | GPLv2+ - -deb [arch=amd64] https://download.docker.com/linux/debian bullseye stable diff --git a/action.Dockerfile b/action.Dockerfile deleted file mode 100644 index 3a6b23c..0000000 --- a/action.Dockerfile +++ /dev/null @@ -1,39 +0,0 @@ -# Icinga Web 2 Docker image | (c) 2020 Icinga GmbH | GPLv2+ - -FROM buildpack-deps:scm as clone -SHELL ["/bin/bash", "-exo", "pipefail", "-c"] - -RUN mkdir actions ;\ - cd actions ;\ - git clone --bare https://github.com/actions/checkout.git ;\ - git -C checkout.git archive --prefix=checkout/ v2 |tar -x ;\ - rm -rf *.git - - -FROM debian:bullseye-slim -SHELL ["/bin/bash", "-exo", "pipefail", "-c"] -ENV DEBIAN_FRONTEND noninteractive - -RUN apt-get update ;\ - apt-get install --no-install-{recommends,suggests} -y \ - apt-transport-https gnupg2 dirmngr ca-certificates ;\ - apt-get clean ;\ - rm -vrf /var/lib/apt/lists/* ;\ - apt-key adv --fetch-keys https://download.docker.com/linux/debian/gpg ;\ - apt-get purge -y gnupg2 dirmngr ;\ - apt-get autoremove --purge -y - -ADD action-base.list /etc/apt/sources.list.d/docker.list - -RUN apt-get update ;\ - apt-get install --no-install-{recommends,suggests} -y \ - composer docker-ce-cli git nodejs patch php7.4-zip ;\ - apt-get clean ;\ - rm -vrf /var/lib/apt/lists/* - -COPY --from=clone /actions /actions - -COPY action.bash composer.bash Dockerfile get-mods.sh php.ini / -COPY entrypoint /entrypoint - -CMD ["/action.bash"] diff --git a/action.bash b/action.bash deleted file mode 100755 index b96aca4..0000000 --- a/action.bash +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash -# Icinga Web 2 Docker image | (c) 2020 Icinga GmbH | GPLv2+ -set -exo pipefail - -TARGET=icinga/icingaweb2 - -mkimg () { - test -n "$TAG" - test -n "$MODE" - - node /actions/checkout/dist/index.js |grep -vFe ::add-matcher:: - - git archive --prefix=icingaweb2/ HEAD |tar -x - - /get-mods.sh "$MODE" - /composer.bash - - cp -r /entrypoint /php.ini . - docker build -f /Dockerfile -t "${TARGET}:$TAG" . - - STATE_isPost=1 node /actions/checkout/dist/index.js -} - -push () { - test -n "$TAG" - - if [ "$(tr -d '\n' <<<"$DOCKER_HUB_PASSWORD" |wc -c)" -gt 0 ]; then - docker login -u icingaadmin --password-stdin <<<"$DOCKER_HUB_PASSWORD" - docker push "${TARGET}:$TAG" - docker logout - fi -} - -case "$GITHUB_EVENT_NAME" in - workflow_dispatch|schedule|release) - case "$GITHUB_REF" in - refs/tags/v*) - MODE=release - TAG=${GITHUB_REF#refs/tags/v} - ;; - refs/heads/*) - MODE=snapshot - TAG=${GITHUB_REF#refs/heads/} - # Remove everything up to the first slash to remove prefixes like "feature/" - TAG=${TAG#*/} - ;; - *) - echo "Unknown ref: $GITHUB_REF" >&2 - false - ;; - esac - mkimg - push - ;; - *) - echo "Unknown event: $GITHUB_EVENT_NAME" >&2 - false - ;; -esac diff --git a/action.yml b/action.yml index 1b062d6..74430d0 100644 --- a/action.yml +++ b/action.yml @@ -1,6 +1,41 @@ # Icinga Web 2 Docker image | (c) 2020 Icinga GmbH | GPLv2+ name: Icinga Web 2 Docker image +inputs: + dockerhub-token: + default: '' runs: - using: docker - image: action.Dockerfile + using: composite + steps: + - uses: actions/checkout@v3 + + - shell: bash + run: docker buildx create --use + + - if: inputs.dockerhub-token != '' + env: + PW: ${{ inputs.dockerhub-token }} + shell: bash + run: | + docker login -u icingaadmin --password-stdin <<<"$PW" + + - if: github.event_name == 'release' + shell: bash + run: | + TAG="$(tr -d v <<<'${{ github.ref_name }}')" + '${{ github.action_path }}/build.bash' . + docker tag icinga/icingaweb2 "icinga/icingaweb2:$TAG" + docker push "icinga/icingaweb2:$TAG" + + - if: github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' + shell: bash + run: | + TAG="$(tr / - <<<'${{ github.ref_name }}')" + '${{ github.action_path }}/build.bash' . snapshot + docker tag icinga/icingaweb2 "icinga/icingaweb2:$TAG" + docker push "icinga/icingaweb2:$TAG" + + - if: github.event_name != 'release' && github.event_name != 'workflow_dispatch' && github.event_name != 'schedule' + shell: bash + run: | + '${{ github.action_path }}/build.bash' . snapshot diff --git a/build.bash b/build.bash index 1cec99d..0c9f329 100755 --- a/build.bash +++ b/build.bash @@ -13,25 +13,14 @@ EOF false fi -IW2SRC="$(realpath "$IW2SRC")" -BLDCTX="$(realpath "$(dirname "$0")")" +if ! docker version; then + echo 'Docker not found' >&2 + false +fi -docker build -f "${BLDCTX}/action.Dockerfile" -t icinga/icingaweb2-builder "$BLDCTX" +if ! docker buildx version; then + echo '"docker buildx" not found (see https://docs.docker.com/buildx/working-with-buildx/ )' >&2 + false +fi -docker run --rm -i \ - -v "${IW2SRC}:/iw2src:ro" \ - -v "${BLDCTX}:/bldctx:ro" \ - -v /var/run/docker.sock:/var/run/docker.sock \ - -e BUILD_MODE \ - icinga/icingaweb2-builder bash </dev/null +} + get_tag () { - if git -C dockerweb2-temp tag |grep -qvFe -; then # ex. RCs - git -C dockerweb2-temp tag --sort=-version:refname |grep -vFe - |head -n 1 + if git -C dockerweb2-temp tag |grep -vFe - >/dev/null; then # ex. RCs + git -C dockerweb2-temp tag --sort=-version:refname |grep -vFe - |get_first_line else - git -C dockerweb2-temp tag --sort=-version:refname |grep -Fe - |head -n 1 + git -C dockerweb2-temp tag --sort=-version:refname |grep -Fe - |get_first_line fi }