Closed azurejelly closed 1 week ago
i'd prefer if it build the project when the docker container runs, so we can still use $env/static
Do you mean copying the .env
file into the container when it is built? The reason I avoided doing this is because you won't be able to publish a image to Docker Hub or GitHub Packages (whichever one you prefer, or both) that can simply be pulled and ran with docker run -e PUB_PLAUSIBLE_URL=https://epic.plausible.url ...
. You'd have to clone the repository, modify the .env, build the image using docker build -t vert .
and then run it with docker run ...
.
Some relevant discussions that I found:
i mean literally running bun run build
when the container starts so the env vars are statically built. i've done this before so i know its possible (but i'm not sure if this is the best practice?)
That is possible but it is definitely not the best practice - it would make it so that the source and dependencies are kept inside the image which would increase its size
What advantages do you get by using $env/static
over $env/dynamic
? The only thing I saw in the Svelte docs is:
Note that public dynamic environment variables must all be sent from the server to the client, causing larger network requests — when possible, use $env/static/public instead.
But is it that much of a difference?
probably not, but if its a choice between bad practice in the web app and bad practice in the docker container, i'd rather have bad practice in the docker container
I made it so that the environment variables are passed to the Dockerfile as build arguments instead so that you can keep using $env/static
. So for example:
$ docker build -t not-nullptr/vert \
--build-arg PUB_HOSTNAME=vert.sh \
--build-arg PUB_PLAUSIBLE_URL=https://plausible.example.com .
For Docker Compose, you have to change them in the docker-compose.yml
file. Then, simply run:
$ docker compose up
If you want to later change some of the environment variables, take the stack down using docker compose down
, update docker-compose.yml
, then rebuild the image using docker compose up --build
.
Made a Dockerfile along with a Docker Compose file to make deployment a bit easier,
though I had to change a bit of the Svelte code for it to detect the container environment variables (it was only taking the.env
file). Let me know if I didn't do it properly because I've honestly never used Svelte before.