Now you can configure your container using Environmet vars.
This commit is contained in:
+3
-1
@@ -1,4 +1,6 @@
|
|||||||
node_modules
|
node_modules
|
||||||
build
|
build
|
||||||
.dockerignore
|
.dockerignore
|
||||||
Dockerfile
|
Dockerfile
|
||||||
|
.env
|
||||||
|
.env.local
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
# App config Variables (Will be visible by client):
|
||||||
|
VITE_BACKEND_HOST=SOMNIAROOMS_BACKEND_HOST
|
||||||
|
VITE_BACKEND_PORT=SOMNIAROOMS_BACKEND_PORT
|
||||||
@@ -20,4 +20,6 @@ RUN npm ci && npm run build
|
|||||||
FROM nginx:stable-alpine as final-prod
|
FROM nginx:stable-alpine as final-prod
|
||||||
COPY --from=builder /app/dist /usr/share/nginx/html
|
COPY --from=builder /app/dist /usr/share/nginx/html
|
||||||
EXPOSE 80
|
EXPOSE 80
|
||||||
|
COPY scripts/env.sh /docker-entrypoint.d/env.sh
|
||||||
|
RUN chmod +x /docker-entrypoint.d/env.sh
|
||||||
CMD ["nginx", "-g", "daemon off;"]
|
CMD ["nginx", "-g", "daemon off;"]
|
||||||
|
|||||||
@@ -30,4 +30,31 @@ docker build -t somniarooms-app:prod --target final-prod .
|
|||||||
**Docker Run**
|
**Docker Run**
|
||||||
```
|
```
|
||||||
docker run -d -it -p 8080:80 --name somniarooms-app somniarooms-app:prod
|
docker run -d -it -p 8080:80 --name somniarooms-app somniarooms-app:prod
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Docker run with env vars:**
|
||||||
|
```
|
||||||
|
docker run -d -it -p 8080:80 --name somniarooms-app -e SOMNIAROOMS_BACKEND_HOST=https://somniaapi.example.org/ -e SOMNIAROOMS_BACKEND_PORT=443 somniarooms-app:prod
|
||||||
|
```
|
||||||
|
|
||||||
|
## Env Vars.
|
||||||
|
As this is distributed as a docker image ready to use, you must set some env variables to configure the app:
|
||||||
|
|
||||||
|
| Var | Default Value | Description |
|
||||||
|
| :------------------------: | :----------------------------: | :------------------------------------------------------------------------------------------: |
|
||||||
|
| `SOMNIAROOMS_BACKEND_HOST` | https://somniaapi.example.org/ | Host where uses can connect to the SomniaRoom API. API endpoint should be reachble for uses. |
|
||||||
|
| `SOMNIAROOMS_BACKEND_PORT` | 443 | Port to SomniarRooms API. |
|
||||||
|
|
||||||
|
## .env files
|
||||||
|
|
||||||
|
This project uses .env files to configure the app. As Vite only supports compile-time vars, we use some tricks to allow setting variables from container env variables.
|
||||||
|
|
||||||
|
### .env
|
||||||
|
Contains default values. It is just an example configuration.
|
||||||
|
|
||||||
|
For development is recomended to create a `.env.local` file based on `.env`.
|
||||||
|
|
||||||
|
### .env.production
|
||||||
|
Set varibles to certains placeholder, that are replace on container startup.
|
||||||
|
|
||||||
|
(We are using this solution: https://stackoverflow.com/a/77454537)
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
for i in $(env | grep SOMNIAROOMS_)
|
||||||
|
do
|
||||||
|
key=$(echo $i | cut -d '=' -f 1)
|
||||||
|
value=$(echo $i | cut -d '=' -f 2-)
|
||||||
|
echo $key=$value
|
||||||
|
# sed All files
|
||||||
|
# find /usr/share/nginx/html -type f -exec sed -i "s|${key}|${value}|g" '{}' +
|
||||||
|
|
||||||
|
# sed JS and CSS only
|
||||||
|
find /usr/share/nginx/html -type f \( -name '*.js' -o -name '*.css' \) -exec sed -i "s|${key}|${value}|g" '{}' +
|
||||||
|
done
|
||||||
Reference in New Issue
Block a user