diff --git a/.github/workflows/test-and-build.yaml b/.github/workflows/test-and-build.yaml index 299cd35..8c25d07 100644 --- a/.github/workflows/test-and-build.yaml +++ b/.github/workflows/test-and-build.yaml @@ -9,7 +9,6 @@ on: release: types: [published] - jobs: test: runs-on: ubuntu-latest @@ -31,26 +30,14 @@ jobs: steps: - name: Checkout + if: github.event_name != 'schedule' uses: actions/checkout@v2 - - name: Calculate the versions to use - id: variables - run: | - # If trigged by schedule then container tag will be nightly, else it's either dev or whatever the tagged version number is - PIHOLE_VERSION=$([ "${{ github.event_name == 'schedule' }}" = "true" ] && echo "nightly" || echo "${GITHUB_REF#refs/*/}") - - # If we are building dev branch or nightly then we want to use the development branches of the core components - # otherwise they will be unset and the main branches will be pulled - if [ "${PIHOLE_VERSION}" = "dev" || "${PIHOLE_VERSION}" = "nightly" ]; then - CORE_VERSION=development - WEB_VERSION=devel - FTL_VERSION=development - fi - - echo ::set-output name=CORE_VERSION::${CORE_VERSION} - echo ::set-output name=WEB_VERSION::${WEB_VERSION} - echo ::set-output name=FTL_VERSION::${FTL_VERSION} - echo ::set-output name=PIHOLE_VERSION::${PIHOLE_VERSION} + name: Checkout dev branch if we are building nightly + if: github.event_name == 'schedule' + uses: actions/checkout@v2 + with: + ref: dev - name: Set up QEMU uses: docker/setup-qemu-action@v1 @@ -69,7 +56,9 @@ jobs: flavor: | latest=${{ startsWith(github.ref, 'refs/tags/') }} tags: | - ${{ steps.variables.outputs.PIHOLE_VERSION }} + type=schedule + type=ref,event=branch + type=ref,event=tag - name: Login to DockerHub uses: docker/login-action@v1 @@ -90,10 +79,7 @@ jobs: context: . platforms: linux/amd64, linux/arm64, linux/386, linux/arm/v7, linux/arm/v6, linux/ppc64le build-args: | - CORE_VERSION=${{ steps.variables.outputs.CORE_VERSION }} - WEB_VERSION=${{ steps.variables.outputs.WEB_VERSION }} - FTL_VERSION=${{ steps.variables.outputs.FTL_VERSION }} - PIHOLE_VERSION=${{ steps.variables.outputs.PIHOLE_VERSION }} + PIHOLE_DOCKER_TAG=${{ steps.meta.outputs.version }} push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/workflow_dispatch.yml b/.github/workflows/workflow_dispatch.yml deleted file mode 100644 index d8c1615..0000000 --- a/.github/workflows/workflow_dispatch.yml +++ /dev/null @@ -1,75 +0,0 @@ -name: Build & Deploy custom image manually -on: - workflow_dispatch: - inputs: - name: - description: 'Name of tag' - required: true - core: - description: 'Branch or tag of core repo' - required: false - web: - description: 'Branch or tag of web repo' - required: false - ftl: - description: 'Branch or tag of ftl repo' - required: false - -jobs: - test: - runs-on: ubuntu-latest - env: - ARCH: amd64 - DEBIAN_VERSION: buster - CORE_VERSION: ${{ github.event.inputs.core }} - WEB_VERSION: ${{ github.event.inputs.web }} - FTL_VERSION: ${{ github.event.inputs.ftl }} - steps: - - name: Checkout Repo - uses: actions/checkout@v2 - - name: Run Tests - run: | - echo "Building ${ARCH}-${DEBIAN_VERSION}" - ./gh-actions-test.sh - - build-and-publish: - needs: test - runs-on: ubuntu-latest - steps: - - - name: Checkout - uses: actions/checkout@v2 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v1 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v1 - - - name: Login to DockerHub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKERHUB_USER }} - password: ${{ secrets.DOCKERHUB_PASS }} - - - name: Login to GitHub Container Registry - uses: docker/login-action@v1 - with: - registry: ghcr.io - username: ${{ github.repository_owner }} - password: ${{ secrets.GITHUB_TOKEN }} - - - name: Build and push - uses: docker/build-push-action@v2 - with: - context: . - platforms: linux/amd64, linux/arm64, linux/386, linux/arm/v7, linux/arm/v6, linux/ppc64le - build-args: | - CORE_VERSION=${{ github.event.inputs.core }} - WEB_VERSION=${{ github.event.inputs.web }} - FTL_VERSION=${{ github.event.inputs.ftl }} - PIHOLE_VERSION=${{ github.event.inputs.name }} - push: true - tags: | - ${{ secrets.DOCKERHUB_NAMESPACE }}/pihole:${{ github.event.inputs.name }} - ghcr.io/${{ github.repository_owner }}/pihole:${{ github.event.inputs.name }} diff --git a/Dockerfile b/Dockerfile index f7e8102..7a6ce89 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,28 +1,22 @@ ARG PIHOLE_BASE FROM "${PIHOLE_BASE:-debian:buster-slim}" -ARG CORE_VERSION -ENV CORE_VERSION "${CORE_VERSION}" -ARG WEB_VERSION -ENV WEB_VERSION "${WEB_VERSION}" -ARG FTL_VERSION -ENV FTL_VERSION "${FTL_VERSION}" -ARG PIHOLE_VERSION -ENV PIHOLE_VERSION "${PIHOLE_VERSION}" +ARG PIHOLE_DOCKER_TAG +ENV PIHOLE_DOCKER_TAG "${PIHOLE_DOCKER_TAG}" ENV S6_OVERLAY_VERSION v2.1.0.2 COPY install.sh /usr/local/bin/install.sh ENV PIHOLE_INSTALL /etc/.pihole/automated\ install/basic-install.sh -RUN bash -ex install.sh 2>&1 && \ - rm -rf /var/cache/apt/archives /var/lib/apt/lists/* - ENTRYPOINT [ "/s6-init" ] -ADD s6/debian-root / +COPY s6/debian-root / COPY s6/service /usr/local/bin/service +RUN bash -ex install.sh 2>&1 && \ + rm -rf /var/cache/apt/archives /var/lib/apt/lists/* + # php config start passes special ENVs into ARG PHP_ENV_CONFIG ENV PHP_ENV_CONFIG /etc/lighttpd/conf-enabled/15-fastcgi-php.conf diff --git a/Dockerfile.py b/Dockerfile.py index dc8e44f..f5bfc5e 100755 --- a/Dockerfile.py +++ b/Dockerfile.py @@ -61,7 +61,7 @@ def build(docker_repo: str, arch: str, debian_version: str, hub_tag: str, show_t time_arg = 'time' if show_time else '' cache_arg = '--no-cache' if no_cache else '' build_env = os.environ.copy() - build_env['PIHOLE_VERSION'] = os.environ.get('GIT_TAG', None) + build_env['PIHOLE_DOCKER_TAG'] = os.environ.get('GIT_TAG', None) build_env['DEBIAN_VERSION'] = debian_version build_command = f'{time_arg} docker-compose -f build.yml build {cache_arg} --pull {arch}' print(f' ::: Building {arch} into {create_tag}') diff --git a/bash_functions.sh b/bash_functions.sh index 0b8cb02..55980ba 100644 --- a/bash_functions.sh +++ b/bash_functions.sh @@ -202,7 +202,7 @@ setup_php_env() { local corshosts_line="\t\t\t\"CORS_HOSTS\" => \"${CORS_HOSTS}\"," local serverip_line="\t\t\t\"ServerIP\" => \"${ServerIP}\"," local php_error_line="\t\t\t\"PHP_ERROR_LOG\" => \"${PHP_ERROR_LOG}\"," - local pihole_docker_tag_line="\t\t\t\"PIHOLE_DOCKER_TAG\" => \"${PIHOLE_VERSION}\"," + local pihole_docker_tag_line="\t\t\t\"PIHOLE_DOCKER_TAG\" => \"${PIHOLE_DOCKER_TAG}\"," # idempotent line additions grep -qP "$vhost_line" "$PHP_ENV_CONFIG" || \ @@ -217,7 +217,7 @@ setup_php_env() { sed -i "/bin-environment/ a\\${pihole_docker_tag_line}" "$PHP_ENV_CONFIG" echo "Added ENV to php:" - grep -E '(VIRTUAL_HOST|CORS_HOSTS|ServerIP|PHP_ERROR_LOG)' "$PHP_ENV_CONFIG" + grep -E '(VIRTUAL_HOST|CORS_HOSTS|ServerIP|PHP_ERROR_LOG|PIHOLE_DOCKER_TAG)' "$PHP_ENV_CONFIG" } setup_web_port() { diff --git a/build.yml b/build.yml index 097fd4e..5f3f4f3 100644 --- a/build.yml +++ b/build.yml @@ -2,42 +2,42 @@ version: "3.7" x-common-args: &common-args - PIHOLE_VERSION: ${PIHOLE_VERSION} + PIHOLE_DOCKER_TAG: ${PIHOLE_DOCKER_TAG} CORE_VERSION: ${CORE_VERSION} WEB_VERSION: ${WEB_VERSION} FTL_VERSION: ${FTL_VERSION} services: amd64: - image: pihole:${PIHOLE_VERSION}-amd64-${DEBIAN_VERSION:-buster} + image: pihole:${PIHOLE_DOCKER_TAG}-amd64-${DEBIAN_VERSION:-buster} build: context: . args: <<: *common-args PIHOLE_BASE: debian:${DEBIAN_VERSION:-buster}-slim armel: - image: pihole:${PIHOLE_VERSION}-armel-${DEBIAN_VERSION:-buster} + image: pihole:${PIHOLE_DOCKER_TAG}-armel-${DEBIAN_VERSION:-buster} build: context: . args: <<: *common-args PIHOLE_BASE: pihole/debian-debootstrap:armel-${DEBIAN_VERSION:-buster}-slim armhf: - image: pihole:${PIHOLE_VERSION}-armhf-${DEBIAN_VERSION:-buster} + image: pihole:${PIHOLE_DOCKER_TAG}-armhf-${DEBIAN_VERSION:-buster} build: context: . args: <<: *common-args PIHOLE_BASE: pihole/debian-debootstrap:armhf-${DEBIAN_VERSION:-buster}-slim arm64: - image: pihole:${PIHOLE_VERSION}-arm64-${DEBIAN_VERSION:-buster} + image: pihole:${PIHOLE_DOCKER_TAG}-arm64-${DEBIAN_VERSION:-buster} build: context: . args: <<: *common-args PIHOLE_BASE: pihole/debian-debootstrap:arm64-${DEBIAN_VERSION:-buster}-slim i386: - image: pihole:${PIHOLE_VERSION}-i386-${DEBIAN_VERSION:-buster} + image: pihole:${PIHOLE_DOCKER_TAG}-i386-${DEBIAN_VERSION:-buster} build: context: . args: diff --git a/install.sh b/install.sh index 3190353..f2ca5b9 100644 --- a/install.sh +++ b/install.sh @@ -52,44 +52,35 @@ export USER=pihole export PIHOLE_SKIP_OS_CHECK=true -ln -s /bin/true /usr/local/bin/service # Run the installer in unattended mode using the preseeded variables above and --reconfigure so that local repos are not updated curl -sSL https://install.pi-hole.net | bash -sex -- --unattended -rm /usr/local/bin/service - -# IPv6 support for nc openbsd better than traditional -apt-get install -y --force-yes netcat-openbsd - -# Source the Pi-hole install script to make use of the fetch_checkout_pull_branch functions as calling pihole checkout directly does not work hre -PH_TEST="true" . "${PIHOLE_INSTALL}" - -[ -n "${CORE_VERSION}" ] && fetch_checkout_pull_branch ${CORE_LOCAL_REPO} "${CORE_VERSION}" && RELOAD=1 -[ -n "${WEB_VERSION}" ] && fetch_checkout_pull_branch ${WEB_LOCAL_REPO} "${WEB_VERSION}" # No need to reload when checking out a new web branch -[ -n "${FTL_VERSION}" ] && echo "${FTL_VERSION}" > /etc/pihole/ftlbranch && RELOAD=1 - -[ -n "${RELOAD}" ] && bash -ex "${PIHOLE_INSTALL}" --unattended --reconfigure +# At this stage, if we are building a :nightly tag, then switch the Pi-hole install to dev versions +if [[ "${PIHOLE_DOCKER_TAG}" = 'nightly' ]]; then + yes | pihole checkout dev +fi sed -i 's/readonly //g' /opt/pihole/webpage.sh sed -i '/^WEBPASSWORD/d' /etc/pihole/setupVars.conf # sed a new function into the `pihole` script just above the `helpFunc()` function for later use. sed -i $'s/helpFunc() {/unsupportedFunc() {\\\n echo "Function not supported in Docker images"\\\n exit 0\\\n}\\\n\\\nhelpFunc() {/g' /usr/local/bin/pihole + # Replace a few of the `pihole` options with calls to `unsupportedFunc`: # pihole -up / pihole updatePihole sed -i $'s/)\s*updatePiholeFunc/) unsupportedFunc/g' /usr/local/bin/pihole -# pihole -r / pihole reconfigure -sed -i $'s/)\s*reconfigurePiholeFunc/) unsupportedFunc/g' /usr/local/bin/pihole # pihole uninstall sed -i $'s/)\s*uninstallFunc/) unsupportedFunc/g' /usr/local/bin/pihole +# pihole -r / pihole reconfigure +sed -i $'s/)\s*reconfigurePiholeFunc/) unsupportedFunc/g' /usr/local/bin/pihole -if [[ "${PIHOLE_VERSION}" != "dev" && "${PIHOLE_VERSION}" != "nightly" ]]; then - # If we are on a version other than dev or nightly, disable `pihole checkout` +if [[ "${PIHOLE_DOCKER_TAG}" != "dev" && "${PIHOLE_DOCKER_TAG}" != "nightly" ]]; then + # If we are on a version other than dev or nightly, disable `pihole checkout`, otherwise it is useful to have for quick troubleshooting sometimes sed -i $'s/)\s*piholeCheckoutFunc/) unsupportedFunc/g' /usr/local/bin/pihole fi # Inject a message into the debug scripts Operating System section to indicate that the debug log comes from a Docker system. -sed -i $'s/echo_current_diagnostic "Operating system"/echo_current_diagnostic "Operating system"\\\n log_write "${INFO} Pi-hole Docker Container: ${PIHOLE_VERSION:-PIHOLE_VERSION is unset}"/g' /opt/pihole/piholeDebug.sh +sed -i $'s/echo_current_diagnostic "Operating system"/echo_current_diagnostic "Operating system"\\\n log_write "${INFO} Pi-hole Docker Container: ${PIHOLE_DOCKER_TAG:-PIHOLE_DOCKER_TAG is unset}"/g' /opt/pihole/piholeDebug.sh touch /.piholeFirstBoot diff --git a/s6/debian-root/etc/cont-init.d/20-start.sh b/s6/debian-root/etc/cont-init.d/20-start.sh index e2ab3a1..97cd6ab 100644 --- a/s6/debian-root/etc/cont-init.d/20-start.sh +++ b/s6/debian-root/etc/cont-init.d/20-start.sh @@ -36,4 +36,4 @@ fi pihole -v -echo " Container tag is: ${PIHOLE_VERSION}" \ No newline at end of file +echo " Container tag is: ${PIHOLE_DOCKER_TAG}" \ No newline at end of file diff --git a/test/conftest.py b/test/conftest.py index ec5bbfb..f76e9cf 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -14,7 +14,7 @@ def run_and_stream_command_output(): def run_and_stream_command_output_inner(command, verbose=False): print("Running", command) build_env = os.environ.copy() - build_env['PIHOLE_VERSION'] = version + build_env['PIHOLE_DOCKER_TAG'] = version build_result = subprocess.Popen(command.split(), env=build_env, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, universal_newlines=True) if verbose: