From f140dd3ad80f646649c26836d2de7eb7d7650d25 Mon Sep 17 00:00:00 2001 From: Paramtamtam Date: Fri, 10 Jul 2020 12:43:48 +0500 Subject: [PATCH] v1.2.0 --- .github/workflows/tests.yml | 5 ++++- CHANGELOG.md | 18 ++++++++++++++++ Makefile | 2 +- README.md | 43 +++++++++++++++++++------------------ config.json | 8 +++++++ docker/docker-entrypoint.sh | 13 ++++------- docker/nginx-server.conf | 18 ++++++++++++++-- static/index.html | 22 ------------------- templates/l7-dark.html | 29 +++++++++++++++++++++++++ templates/l7-light.html | 29 +++++++++++++++++++++++++ 10 files changed, 131 insertions(+), 56 deletions(-) delete mode 100644 static/index.html create mode 100644 templates/l7-dark.html create mode 100644 templates/l7-light.html diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6aa1dcc..80021b0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -51,5 +51,8 @@ jobs: # Docs: - name: Pause run: sleep 2 - - name: Send HTTP request + - name: Verify 500.html error file exists in root run: curl -sS --fail "http://127.0.0.1:8080/500.html" + + - name: Verify root request HTTP code + run: test $(curl --write-out %{http_code} --silent --output /dev/null http://127.0.0.1:8080/) -eq 404 diff --git a/CHANGELOG.md b/CHANGELOG.md index 69744ec..c6301f6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,24 @@ All notable changes to this package will be documented in this file. The format is based on [Keep a Changelog][keepachangelog] and this project adheres to [Semantic Versioning][semver]. +## v1.2.0 + +### Fixed + +- By default `nginx` in docker container returns 404 http code instead 200 when `/` requested + +### Changed + +- Default value for `TEMPLATE_NAME` is `ghost` now + +### Removed + +- Environment variable `DEFAULT_ERROR_CODE` support in docker image + +### Added + +- Templates `l7-light` and `l7-dark` + ## v1.1.0 ### Added diff --git a/Makefile b/Makefile index 0c2cc93..5362a53 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ gen: ## Generate error pages preview: ## Build docker image and start preview $(DOCKER_BIN) build -f ./Dockerfile -t $(APP_NAME):local . @printf "\n \e[30;42m %s \033[0m\n\n" 'Now open in your favorite browser and press CTRL+C for stopping' - $(DOCKER_BIN) run --rm -i -p 8081:8080 -e "TEMPLATE_NAME=ghost" $(APP_NAME):local + $(DOCKER_BIN) run --rm -i -p 8081:8080 -e "TEMPLATE_NAME=l7-light" $(APP_NAME):local shell: ## Start shell into container with node $(DC_BIN) run $(DC_RUN_ARGS) app sh diff --git a/README.md b/README.md index 39011b7..e38c19b 100644 --- a/README.md +++ b/README.md @@ -44,9 +44,11 @@ $ make preview ## Templates - Name | Preview -:------: | :-----: -`ghost` | ![ghost](https://hsto.org/webt/zg/ul/cv/zgulcvxqzhazoebxhg8kpxla8lk.png) + Name | Preview +:--------: | :-----: +`ghost` | ![ghost](https://hsto.org/webt/zg/ul/cv/zgulcvxqzhazoebxhg8kpxla8lk.png) +`l7-light` | ![ghost](https://hsto.org/webt/xc/iq/vt/xciqvty-aoj-rchfarsjhutpjny.png) +`l7-dark` | ![ghost](https://hsto.org/webt/s1/ih/yr/s1ihyrqs_y-sgraoimfhk6ypney.png) ## Usage @@ -54,17 +56,16 @@ Generated error pages in our [docker image][link_docker_hub] permanently located #### Supported environment variables -Name | Description --------------------- | ----------- -`TEMPLATE_NAME` | "default" pages template _(allows to use error pages without passing theme name in URL - `http://127.0.0.1/500.html` instead `http://127.0.0.1/ghost/500.html`)_ -`DEFAULT_ERROR_CODE` | (`404` by default) Code with passed error code will be used as default (index) page (can be used only with `TEMPLATE_NAME` variable) +Name | Description +--------------- | ----------- +`TEMPLATE_NAME` | (`ghost` by default) "default" pages template _(allows to use error pages without passing theme name in URL - `http://127.0.0.1/500.html` instead `http://127.0.0.1/ghost/500.html`)_ ### HTTP server for error pages serving only Execute in your shell: ```bash -$ docker run --rm -p "8082:8080" tarampampam/error-pages:1.1.0 +$ docker run --rm -p "8082:8080" tarampampam/error-pages:1.2.0 ``` And open in your browser `http://127.0.0.1:8082/ghost/400.html`. @@ -105,7 +106,7 @@ FROM nginx:1.18-alpine COPY --chown=nginx \ ./nginx.conf /etc/nginx/conf.d/default.conf COPY --chown=nginx \ - --from=tarampampam/error-pages:1.1.0 \ + --from=tarampampam/error-pages:1.2.0 \ /opt/html/ghost /usr/share/nginx/errorpages/_error-pages ``` @@ -120,7 +121,7 @@ version: '3.8' services: error-pages: - image: tarampampam/error-pages:1.1.0 + image: tarampampam/error-pages:1.2.0 environment: TEMPLATE_NAME: ghost networks: @@ -136,17 +137,17 @@ services: reservations: memory: 16M labels: - - traefik.enable=true - - traefik.docker.network=traefik-public - - traefik.http.routers.error-pages-router.rule=HostRegexp(`{host:.+}`) - - traefik.http.routers.error-pages-router.tls=true - - traefik.http.routers.error-pages-router.priority=10 - - traefik.http.routers.error-pages-router.entrypoints=https - - traefik.http.routers.error-pages-router.middlewares=error-pages-middleware@docker - - traefik.http.services.error-pages-service.loadbalancer.server.port=8080 - - traefik.http.middlewares.error-pages-middleware.errors.status=400-599 - - traefik.http.middlewares.error-pages-middleware.errors.service=error-pages-service@docker - - traefik.http.middlewares.error-pages-middleware.errors.query=/{status}.html + - traefik.enable: true + - traefik.docker.network: traefik-public + - traefik.http.routers.error-pages-router.rule: HostRegexp(`{host:.+}`) + - traefik.http.routers.error-pages-router.tls: true + - traefik.http.routers.error-pages-router.priority: 10 + - traefik.http.routers.error-pages-router.entrypoints: https + - traefik.http.routers.error-pages-router.middlewares: error-pages-middleware@docker + - traefik.http.services.error-pages-service.loadbalancer.server.port: 8080 + - traefik.http.middlewares.error-pages-middleware.errors.status: 400-599 + - traefik.http.middlewares.error-pages-middleware.errors.service: error-pages-service@docker + - traefik.http.middlewares.error-pages-middleware.errors.query: /{status}.html networks: traefik-public: diff --git a/config.json b/config.json index 5916e55..b822ff5 100644 --- a/config.json +++ b/config.json @@ -3,6 +3,14 @@ { "name": "ghost", "path": "./templates/ghost.html" + }, + { + "name": "l7-light", + "path": "./templates/l7-light.html" + }, + { + "name": "l7-dark", + "path": "./templates/l7-dark.html" } ], "output": { diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh index 8775c85..484c781 100755 --- a/docker/docker-entrypoint.sh +++ b/docker/docker-entrypoint.sh @@ -1,8 +1,7 @@ #!/usr/bin/env sh set -e -TEMPLATE_NAME=${TEMPLATE_NAME:-} # string|empty -DEFAULT_ERROR_CODE=${DEFAULT_ERROR_CODE:-404} # numeric +TEMPLATE_NAME=${TEMPLATE_NAME:-ghost} # string|empty if [ -n "$TEMPLATE_NAME" ]; then echo "$0: set pages for template '$TEMPLATE_NAME' as default (make accessible in root directory)"; @@ -13,13 +12,9 @@ if [ -n "$TEMPLATE_NAME" ]; then ln -f -s "/opt/html/$TEMPLATE_NAME/"* /opt/html; - if [ -L "/opt/html/$DEFAULT_ERROR_CODE.html" ]; then - echo "$0: set page with error code '$DEFAULT_ERROR_CODE' as default (index) page"; - - cp -f "/opt/html/$DEFAULT_ERROR_CODE.html" /opt/html/index.html; - else - (>&2 echo "$0: cannot set page with error code '$DEFAULT_ERROR_CODE' as default (index) page!"); - fi; + # next directory is required for easy nginx `error_page` usage + mkdir /opt/html/nginx-error-pages; + ln -f -s "/opt/html/$TEMPLATE_NAME/"* /opt/html/nginx-error-pages; fi; exec "$@" diff --git a/docker/nginx-server.conf b/docker/nginx-server.conf index 23ad5e1..549b27c 100644 --- a/docker/nginx-server.conf +++ b/docker/nginx-server.conf @@ -2,8 +2,22 @@ server { listen 8080; server_name _; + index index.html index.htm; + root /opt/html; + + error_page 400 /nginx-error-pages/400.html; + error_page 401 /nginx-error-pages/401.html; + error_page 403 /nginx-error-pages/403.html; + error_page 404 /nginx-error-pages/404.html; + error_page 500 /nginx-error-pages/500.html; + error_page 502 /nginx-error-pages/502.html; + + location ^~ /nginx-error-pages/ { + internal; + root /opt/html; + } + location / { - root /opt/html; - index index.html index.htm; + try_files $uri =404; } } diff --git a/static/index.html b/static/index.html deleted file mode 100644 index 6acc70f..0000000 --- a/static/index.html +++ /dev/null @@ -1,22 +0,0 @@ - - - - - Error pages - - - - -
-

Error pages

-

- For online documentation and support please refer to project repository. -

-
- diff --git a/templates/l7-dark.html b/templates/l7-dark.html new file mode 100644 index 0000000..b633993 --- /dev/null +++ b/templates/l7-dark.html @@ -0,0 +1,29 @@ + + + + + + + {{ message }} + + + + + +
+
+ {{ code }} +
+
+ {{ message }} +
+
+ + diff --git a/templates/l7-light.html b/templates/l7-light.html new file mode 100644 index 0000000..bc5586e --- /dev/null +++ b/templates/l7-light.html @@ -0,0 +1,29 @@ + + + + + + + {{ message }} + + + + + +
+
+ {{ code }} +
+
+ {{ message }} +
+
+ +