From fbf37456d02523bf9beeac9f498384de283b6258 Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Tue, 11 Jan 2022 22:38:30 +0100 Subject: [PATCH 1/3] feat: display container version --- Dockerfile | 15 ++++++++------- Dockerfile.alpine | 15 ++++++++------- docker-entrypoint.sh | 8 ++++++++ nginx.tmpl | 5 +++++ 4 files changed, 29 insertions(+), 14 deletions(-) diff --git a/Dockerfile b/Dockerfile index 22f910d..232098e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -39,6 +39,14 @@ RUN git clone https://github.com/nginx-proxy/forego/ \ FROM nginx:1.21.5 LABEL maintainer="Nicolas Duchon (@buchdag)" +ARG NGINX_PROXY_VERSION +# Add DOCKER_GEN_VERSION environment variable +# Because some external projects rely on it +ARG DOCKER_GEN_VERSION +ENV NGINX_PROXY_VERSION=${NGINX_PROXY_VERSION} \ + DOCKER_GEN_VERSION=${DOCKER_GEN_VERSION} \ + DOCKER_HOST=unix:///tmp/docker.sock + # Install wget and install/updates certificates RUN apt-get update \ && apt-get install -y -q --no-install-recommends \ @@ -58,17 +66,10 @@ RUN echo "daemon off;" >> /etc/nginx/nginx.conf \ COPY --from=forego /usr/local/bin/forego /usr/local/bin/forego COPY --from=dockergen /usr/local/bin/docker-gen /usr/local/bin/docker-gen -# Add DOCKER_GEN_VERSION environment variable -# Because some external projects rely on it -ARG DOCKER_GEN_VERSION -ENV DOCKER_GEN_VERSION=${DOCKER_GEN_VERSION} - COPY network_internal.conf /etc/nginx/ COPY . /app/ WORKDIR /app/ -ENV DOCKER_HOST unix:///tmp/docker.sock - ENTRYPOINT ["/app/docker-entrypoint.sh"] CMD ["forego", "start", "-r"] diff --git a/Dockerfile.alpine b/Dockerfile.alpine index 94a122e..6852b5a 100644 --- a/Dockerfile.alpine +++ b/Dockerfile.alpine @@ -40,6 +40,14 @@ RUN git clone https://github.com/nginx-proxy/forego/ \ FROM nginx:1.21.5-alpine LABEL maintainer="Nicolas Duchon (@buchdag)" +ARG NGINX_PROXY_VERSION +# Add DOCKER_GEN_VERSION environment variable +# Because some external projects rely on it +ARG DOCKER_GEN_VERSION +ENV NGINX_PROXY_VERSION=${NGINX_PROXY_VERSION} \ + DOCKER_GEN_VERSION=${DOCKER_GEN_VERSION} \ + DOCKER_HOST=unix:///tmp/docker.sock + # Install wget and install/updates certificates RUN apk add --no-cache --virtual .run-deps \ ca-certificates bash wget openssl \ @@ -55,17 +63,10 @@ RUN echo "daemon off;" >> /etc/nginx/nginx.conf \ COPY --from=forego /usr/local/bin/forego /usr/local/bin/forego COPY --from=dockergen /usr/local/bin/docker-gen /usr/local/bin/docker-gen -# Add DOCKER_GEN_VERSION environment variable -# Because some external projects rely on it -ARG DOCKER_GEN_VERSION -ENV DOCKER_GEN_VERSION=${DOCKER_GEN_VERSION} - COPY network_internal.conf /etc/nginx/ COPY . /app/ WORKDIR /app/ -ENV DOCKER_HOST unix:///tmp/docker.sock - ENTRYPOINT ["/app/docker-entrypoint.sh"] CMD ["forego", "start", "-r"] diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 45d6cd2..8f4ed7a 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -29,6 +29,12 @@ function _parse_false() { esac } +function _print_version { + if [[ -n "${NGINX_PROXY_VERSION:-}" ]]; then + echo "Info: running nginx-proxy version ${NGINX_PROXY_VERSION}" + fi +} + function _check_unix_socket() { # Warn if the DOCKER_HOST socket does not exist if [[ ${DOCKER_HOST} == unix://* ]]; then @@ -96,6 +102,8 @@ function _setup_dhparam() { # Run the init logic if the default CMD was provided if [[ $* == 'forego start -r' ]]; then + _print_version + _check_unix_socket _resolvers diff --git a/nginx.tmpl b/nginx.tmpl index 2e1415e..2414633 100644 --- a/nginx.tmpl +++ b/nginx.tmpl @@ -1,5 +1,6 @@ {{ $CurrentContainer := where $ "ID" .Docker.CurrentContainerID | first }} +{{ $nginx_proxy_version := coalesce $.Env.NGINX_PROXY_VERSION "" }} {{ $external_http_port := coalesce $.Env.HTTP_PORT "80" }} {{ $external_https_port := coalesce $.Env.HTTPS_PORT "443" }} {{ $debug_all := $.Env.DEBUG }} @@ -48,6 +49,10 @@ {{ end }} {{ end }} +{{ if ne $nginx_proxy_version "" }} +# nginx-proxy version : {{ $nginx_proxy_version }} +{{ end }} + # If we receive X-Forwarded-Proto, pass it through; otherwise, pass along the # scheme used to connect to this server map $http_x_forwarded_proto $proxy_x_forwarded_proto { From e22ae4a6fdfa6760651b9864a3fb042ba896a9ff Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Tue, 11 Jan 2022 22:53:39 +0100 Subject: [PATCH 2/3] tests: display container version --- Makefile | 4 ++-- test/test_nominal.py | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 18fcd33..ab44880 100644 --- a/Makefile +++ b/Makefile @@ -6,10 +6,10 @@ build-webserver: docker build -t web test/requirements/web build-nginx-proxy-test-debian: - docker build -t nginxproxy/nginx-proxy:test . + docker build --build-arg NGINX_PROXY_VERSION="test" -t nginxproxy/nginx-proxy:test . build-nginx-proxy-test-alpine: - docker build -f Dockerfile.alpine -t nginxproxy/nginx-proxy:test . + docker build --build-arg NGINX_PROXY_VERSION="test" -f Dockerfile.alpine -t nginxproxy/nginx-proxy:test . test-debian: build-webserver build-nginx-proxy-test-debian test/pytest.sh diff --git a/test/test_nominal.py b/test/test_nominal.py index cce7c94..a3f9c87 100644 --- a/test/test_nominal.py +++ b/test/test_nominal.py @@ -22,3 +22,8 @@ def test_forwards_to_web2(docker_compose, nginxproxy): def test_ipv6_is_disabled_by_default(docker_compose, nginxproxy): with pytest.raises(ConnectionError): nginxproxy.get("http://nginx-proxy/port", ipv6=True) + + +def test_container_version_is_displayed(docker_compose, nginxproxy): + conf = nginxproxy.get_conf().decode('ASCII') + assert "# nginx-proxy version : test" in conf From dbca945a8f1f1dbd35f0f8308413a1859882660a Mon Sep 17 00:00:00 2001 From: Nicolas Duchon Date: Wed, 12 Jan 2022 11:26:20 +0100 Subject: [PATCH 3/3] ci: add nginx-proxy version to image on build --- .github/workflows/dockerhub.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/dockerhub.yml b/.github/workflows/dockerhub.yml index 5d4cfba..3dea999 100644 --- a/.github/workflows/dockerhub.yml +++ b/.github/workflows/dockerhub.yml @@ -53,12 +53,16 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Retrieve version + run: echo "GIT_DESCRIBE=$(git describe --tags)" >> $GITHUB_ENV + - name: Build and push the Debian based image id: docker_build_debian uses: docker/build-push-action@v2 with: context: . file: Dockerfile + build-args: NGINX_PROXY_VERSION=${{ env.GIT_DESCRIBE }} platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true tags: ${{ steps.docker_meta_debian.outputs.tags }} @@ -101,12 +105,16 @@ jobs: username: ${{ secrets.DOCKERHUB_USERNAME }} password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Retrieve version + run: echo "GIT_DESCRIBE=$(git describe --tags)" >> $GITHUB_ENV + - name: Build and push the Alpine based image id: docker_build_alpine uses: docker/build-push-action@v2 with: context: . file: Dockerfile.alpine + build-args: NGINX_PROXY_VERSION=${{ env.GIT_DESCRIBE }} platforms: linux/amd64,linux/arm64,linux/arm/v7 push: true tags: ${{ steps.docker_meta_alpine.outputs.tags }}