You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
6
13
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.
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
51
89
52
90
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":
54
92
55
93
- Altered behavior at clients, for example due to changes in cache-headers
56
94
- Altered behavior in the find & replace script
57
95
- Altered behavior in the file locations
58
96
59
97
You should use the latest available tag in [at in the registry](https://hub.docker.com/r/nstapelbroek/static-webserver/tags/).
60
98
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
-
69
99
## License
70
100
71
101
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
0 commit comments