what-digital / divio

A project for tracking divio.com deployment issues
0 stars 0 forks source link

It's impossible to pass any env variables to the dockerfile #63

Open sgordeychuk opened 11 months ago

sgordeychuk commented 11 months ago

The problem is that we cannot pass env variables to the docker build process. We mostly need that to have environment specific processes during the build. Currently environment variables defined via UI are only added to the running docker container and not during the building process. Basically that means adding --build-arg <varname>=<value> to the build process (docker build call or docker-compose.yml) with customisable variables.

For example we have a simple React application which has different build workflows (yarn build dev and yarn build production), but there's no way to do the switch in the Dockerfile like that:

FROM node:10

ARG environment
COPY frontend/package.json /package.json
COPY frontend/yarn.lock /yarn.lock

RUN yarn install --pure-lockfile --modules-folder /node_modules
RUN yarn build $environment

Actually just adding --build-arg env=<divio_env_name> would solve most of the problems, but having flexibility would allow to remove overhead and workarounds.

Currently our main solution for that is to keep conditions with env vars in the code (for FE projects) and to keep different dockerfiles in git branches. Both creates additional problems and requires time for maintenance for us.