Skip to content

Commit 92d8515

Browse files
committed
docs: add table description explaining the filters
1 parent d1e7885 commit 92d8515

File tree

1 file changed

+45
-15
lines changed

1 file changed

+45
-15
lines changed

README.md

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,29 @@
1-
[![Docker Pulls](https://img.shields.io/docker/pulls/nstapelbroek/static-webserver.svg?style=flat-square)](https://hub.docker.com/r/nstapelbroek/static-webserver/tags/)
2-
31
# Docker static webserver
42

3+
<!-- MANPAGE: BEGIN EXCLUDED SECTION -->
4+
<div align="center">
5+
6+
[![Docker Pulls](https://img.shields.io/docker/pulls/nstapelbroek/static-webserver.svg?style=for-the-badge)](https://hub.docker.com/r/nstapelbroek/static-webserver/tags/)
7+
![Docker Image Size (tag)](https://img.shields.io/docker/image-size/nstapelbroek/static-webserver/latest?style=for-the-badge)
8+
![Docker Image Version](https://img.shields.io/docker/v/nstapelbroek/static-webserver.svg?style=for-the-badge)
9+
10+
</div>
11+
512
A simple nginx docker image that has the ability to insert environment variables. Created so I could re-use an image between prod and staging environments for my frontend builds.
613
It replaces environment variables on container startup, so you don´t have to rebuild your Docker image or use a server-side language to change some settings.
714

8-
## Getting Started
15+
<!-- MANPAGE: BEGIN EXCLUDED SECTION -->
16+
* [Usage](#usage)
17+
* [Dockerfile example](#dockerfile-example)
18+
* [Using environment variables](#using-environment-variables)
19+
* [Envsubst filters](#envsubst-filters)
20+
* [Mounting volumes](#mounting-volumes)
21+
* [Versioning](#versioning)
22+
* [License](#license)
23+
* [Acknowledgments](#acknowledgments)
24+
25+
<!-- MANPAGE: END EXCLUDED SECTION -->
26+
## Dockerfile example
927

1028
This repository generates the images available on the [Docker hub](https://hub.docker.com/r/nstapelbroek/static-webserver/tags).
1129
Using this image for your own project is as simple as creating a Dockerfile with the two lines below:
@@ -31,9 +49,9 @@ FROM nstapelbroek/static-webserver:4
3149
COPY --from=build --chown=nginx:nginx /opt/project/dist /var/www
3250
```
3351

34-
### Using environment variables
52+
## Using environment variables
3553

36-
When this container starts, a script will replace all occurrences of ${%variableName%} in `/var/www` with
54+
When this container starts, a script will replace all occurrences of ${VARIABLE_NAME} in `/var/www` with
3755
their matching environment variable.
3856

3957
For example, given this HTML in a file located at `/var/www/index.html`
@@ -47,25 +65,37 @@ And building & running this with an environment variable passed in docker run (`
4765

4866
![result](https://user-images.githubusercontent.com/3368018/27512102-48ae27aa-5936-11e7-824a-92ca12d5334f.png)
4967

50-
### What tag should I use?
68+
Note: Please make sure your environment keys do not contain special characters. Only `a-z`, `A-Z`, `0-9` and `_` are recommended.
69+
70+
## Envsubst filters
71+
By default, the script only changes files located in `/var/www`. You can change this by setting the `NGINX_ENVSUBST_WWW_DIR` environment variable.
72+
Using es6 template literals can cause issues. You can fine-tune the replacement by configuring a filter with the `NGINX_ENVSUBST_FILTER` environment variable. This should allow you to set a prefix like `CONFIG_`.
73+
Here's a table that should help you understand the behavior:
74+
75+
text value in file | passed environment variable | passed nginx filter | result | why
76+
--- | --- | --- | --- | ---
77+
`$MY_PROJECT_URL` | `MY_PROJECT_URL=123` | `PROJECT` | `123` | the passed filter matches we have an environment variable to replace
78+
`${MY_PROJECT_URL}` | `MY_PROJECT_URL=123` | `PROJECT` | `123` | the passed filter matches and we have an environment variable to replace
79+
\`${MY_PROJECT_URL}\` | `MY_PROJECT_URL=123` | `PROJECT` | \`123\` | the passed filter matches we have an environment variable to replace
80+
`MY_PROJECT_URL` | `MY_PROJECT_URL=123` | `PROJECT` | `MY_PROJECT_URL` | this is not a valid form [for envsubst ](https://www.gnu.org/software/gettext/manual/html_node/envsubst-Invocation.html)
81+
`$MY_PROJECT_URL` | `YOUR_PROJECT_URL=123` | `PROJECT` | `MY_PROJECT_URL` | the filter matches, but we have no environment variable to replace
82+
`$MY_PROJECT_URL` | `MY_PROJECT_URL=123` | `PUBLIC_` | `MY_PROJECT_URL` | the variable does match the allowed filter
83+
84+
85+
## Mounting volumes
86+
The project is not meant as a development environment. Don´t mount your code in here as it will only change environment variables on the first container startup.
87+
88+
## Versioning
5189

5290
To prevent sudden BC-breaks you should avoid using the `latest` tag when building upon this image (or any image for that reason).
53-
I'm using [Semver](https://semver.org/) as a base for versioning schematics. Due to the small functionality of this container I'm considering the following changes as "incompatible API changes":
91+
I'm using [Semver](https://semver.org/) as a base for versioning schematics. Due to the small functionality of this container I'm considering the following changes as "incompatible API changes":
5492

5593
- Altered behavior at clients, for example due to changes in cache-headers
5694
- Altered behavior in the find & replace script
5795
- Altered behavior in the file locations
5896

5997
You should use the latest available tag in [at in the registry](https://hub.docker.com/r/nstapelbroek/static-webserver/tags/).
6098

61-
## Known limitations
62-
63-
Due to the simple approach of finding & replacing the keywords there are some limitations:
64-
- Please make sure your environment keys do not contain special characters. Only `a-z`, `A-Z`, `0-9` and `_` are recommended.
65-
- By default, the script only changes files located in `/var/www`. You can change this by setting the `NGINX_ENVSUBST_WWW_DIR` environment variable.
66-
- Using es6 template literals can cause issues. You can fine-tune the replacement by configuring a filter with the `NGINX_ENVSUBST_FILTER` environment variable. This should allow you to set a prefix like `CONFIG_`.
67-
- The project is not meant as a development environment. Don´t mount your code in here as it will only change environment variables on the first startup.
68-
6999
## License
70100

71101
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details

0 commit comments

Comments
 (0)