Skip to content

Commit 699cccb

Browse files
author
Paramtamtam
committed
v1.1.0
1 parent abc3179 commit 699cccb

File tree

4 files changed

+59
-9
lines changed

4 files changed

+59
-9
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this package will be documented in this file.
44

55
The format is based on [Keep a Changelog][keepachangelog] and this project adheres to [Semantic Versioning][semver].
66

7+
## v1.1.0
8+
9+
### Added
10+
11+
- Environment variable `DEFAULT_ERROR_CODE` support in docker image
12+
713
## v1.0.1
814

915
### Changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ gen: ## Generate error pages
2626
preview: ## Build docker image and start preview
2727
$(DOCKER_BIN) build -f ./Dockerfile -t $(APP_NAME):local .
2828
@printf "\n \e[30;42m %s \033[0m\n\n" 'Now open in your favorite browser <http://127.0.0.1:8081> and press CTRL+C for stopping'
29-
$(DOCKER_BIN) run --rm -i -p 8081:8080 $(APP_NAME):local
29+
$(DOCKER_BIN) run --rm -i -p 8081:8080 -e "TEMPLATE_NAME=ghost" $(APP_NAME):local
3030

3131
shell: ## Start shell into container with node
3232
$(DC_BIN) run $(DC_RUN_ARGS) app sh

README.md

Lines changed: 43 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,20 +50,21 @@ $ make preview
5050

5151
## Usage
5252

53-
Generated error pages in our [docker image][link_docker_hub] permanently located in directory `/opt/html/%TEMPLATE_NAME%`. `nginx` in container listen for `8080` (`http`) port.
53+
Generated error pages in our [docker image][link_docker_hub] permanently located in directory `/opt/html/%TEMPLATE_NAME%`. `nginx` in a container listen for `8080` (`http`) port.
5454

5555
#### Supported environment variables
5656

57-
Name | Description
58-
--------------- | -----------
59-
`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`)_
57+
Name | Description
58+
-------------------- | -----------
59+
`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`)_
60+
`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)
6061

6162
### HTTP server for error pages serving only
6263

6364
Execute in your shell:
6465

6566
```bash
66-
$ docker run --rm -p "8082:8080" tarampampam/error-pages
67+
$ docker run --rm -p "8082:8080" tarampampam/error-pages:1.1.0
6768
```
6869

6970
And open in your browser `http://127.0.0.1:8082/ghost/400.html`.
@@ -104,18 +105,52 @@ FROM nginx:1.18-alpine
104105
COPY --chown=nginx \
105106
./nginx.conf /etc/nginx/conf.d/default.conf
106107
COPY --chown=nginx \
107-
--from=tarampampam/error-pages:1.0.0 \
108+
--from=tarampampam/error-pages:1.1.0 \
108109
/opt/html/ghost /usr/share/nginx/errorpages/_error-pages
109110
```
110111

111112
> More info about `error_page` directive can be [found here](http://nginx.org/en/docs/http/ngx_http_core_module.html#error_page).
112113
113114
### Custom error pages for [Traefik][link_traefik]
114115

115-
Simple traefik service configuration for usage in [docker swarm][link_swarm] (**change with your needs**):
116+
Simple traefik (tested on `v2.2.1`) service configuration for usage in [docker swarm][link_swarm] (**change with your needs**):
116117

117118
```yaml
118-
# Work in progress
119+
version: '3.8'
120+
121+
services:
122+
error-pages:
123+
image: tarampampam/error-pages:1.1.0
124+
environment:
125+
TEMPLATE_NAME: ghost
126+
networks:
127+
- traefik-public
128+
deploy:
129+
placement:
130+
constraints:
131+
- node.role == worker
132+
max_replicas_per_node: 1
133+
resources:
134+
limits:
135+
memory: 32M
136+
reservations:
137+
memory: 16M
138+
labels:
139+
- traefik.enable=true
140+
- traefik.docker.network=traefik-public
141+
- traefik.http.routers.error-pages-router.rule=HostRegexp(`{host:.+}`)
142+
- traefik.http.routers.error-pages-router.tls=true
143+
- traefik.http.routers.error-pages-router.priority=10
144+
- traefik.http.routers.error-pages-router.entrypoints=https
145+
- traefik.http.routers.error-pages-router.middlewares=error-pages-middleware@docker
146+
- traefik.http.services.error-pages-service.loadbalancer.server.port=8080
147+
- traefik.http.middlewares.error-pages-middleware.errors.status=400-599
148+
- traefik.http.middlewares.error-pages-middleware.errors.service=error-pages-service@docker
149+
- traefik.http.middlewares.error-pages-middleware.errors.query=/{status}.html
150+
151+
networks:
152+
traefik-public:
153+
external: true
119154
```
120155
121156
## Changes log

docker/docker-entrypoint.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
set -e
33

44
TEMPLATE_NAME=${TEMPLATE_NAME:-} # string|empty
5+
DEFAULT_ERROR_CODE=${DEFAULT_ERROR_CODE:-404} # numeric
56

67
if [ -n "$TEMPLATE_NAME" ]; then
78
echo "$0: set pages for template '$TEMPLATE_NAME' as default (make accessible in root directory)";
@@ -11,6 +12,14 @@ if [ -n "$TEMPLATE_NAME" ]; then
1112
fi;
1213

1314
ln -f -s "/opt/html/$TEMPLATE_NAME/"* /opt/html;
15+
16+
if [ -L "/opt/html/$DEFAULT_ERROR_CODE.html" ]; then
17+
echo "$0: set page with error code '$DEFAULT_ERROR_CODE' as default (index) page";
18+
19+
cp -f "/opt/html/$DEFAULT_ERROR_CODE.html" /opt/html/index.html;
20+
else
21+
(>&2 echo "$0: cannot set page with error code '$DEFAULT_ERROR_CODE' as default (index) page!");
22+
fi;
1423
fi;
1524

1625
exec "$@"

0 commit comments

Comments
 (0)