soywod
(Clément DOUIN)
June 17, 2022, 3:38pm
1
Issues information
OS:
databases: postgresql
Programming language and version: node v16
Link to your project on Github/Gitlab: private
Your issue
DATABASE_URL
seems not to be defined, despite the fact to have it in my .env.production
:
DATABASE_URL="${QOVERY_POSTGRESQL_Z234F4230_DATABASE_URL_INTERNAL}"
$ dotenv -c production -- prisma migrate deploy
Prisma schema loaded from prisma/schema.prisma
Error: Get config: Schema Parsing P1012
error: Environment variable not found: DATABASE_URL.
--> schema.prisma:8
|
7 | provider = "postgresql"
8 | url = env("DATABASE_URL")
Validation Error Count: 1
error Command failed with exit code 1.
Dockerfile content (if any)
FROM node:16-alpine as build
WORKDIR /app
COPY package.json .
COPY yarn.lock .
COPY .npmrc .
COPY backend/package.json backend/
RUN yarn --frozen-lockfile --ignore-scripts --ignore-engines
WORKDIR /app/backend
COPY backend/prisma prisma
RUN yarn dotenv -c production -- yarn prisma generate
COPY backend .
RUN yarn graphql-codegen
RUN yarn build
FROM node:16-alpine
WORKDIR /app
EXPOSE 3100
COPY --from=build /app/package.json .
COPY --from=build /app/yarn.lock .
COPY --from=build /app/node_modules node_modules
WORKDIR /app/backend
COPY --from=build /app/backend/package.json .
COPY --from=build /app/backend/prisma prisma
COPY --from=build /app/backend/dist dist
ARG QOVERY_APPLICATION_Z5A52AF3F_HOST_EXTERNAL
ENV QOVERY_APPLICATION_Z5A52AF3F_HOST_EXTERNAL $QOVERY_APPLICATION_Z5A52AF3F_HOST_EXTERNAL
ARG QOVERY_POSTGRESQL_Z234F4230_DATABASE_URL_INTERNAL
ENV QOVERY_POSTGRESQL_Z234F4230_DATABASE_URL_INTERNAL $QOVERY_POSTGRESQL_Z234F4230_DATABASE_URL_INTERNAL
ARG QOVERY_REDIS_ZC5CB5F2F_HOST_INTERNAL
ENV QOVERY_REDIS_ZC5CB5F2F_HOST_INTERNAL $QOVERY_REDIS_ZC5CB5F2F_HOST_INTERNAL
ARG QOVERY_REDIS_ZC5CB5F2F_PORT
ENV QOVERY_REDIS_ZC5CB5F2F_PORT $QOVERY_REDIS_ZC5CB5F2F_PORT
ARG QOVERY_REDIS_ZC5CB5F2F_PASSWORD
ENV QOVERY_REDIS_ZC5CB5F2F_PASSWORD $QOVERY_REDIS_ZC5CB5F2F_PASSWORD
ARG DATABASE_URL
ENV DATABASE_URL $DATABASE_URL
CMD ["yarn", "start:prod"]
package.json’s scripts:
{
"scripts": {
"build": "dotenv -c production -- nest build --webpack",
"prestart:prod": "dotenv -c production -- prisma migrate deploy",
"start:prod": "dotenv -c production -- node dist/main"
},
}
rophilogene
(Romaric Philogene)
June 17, 2022, 4:10pm
2
Hi @soywod ,
When you connect to your application via qovery shell
can you type env | grep DATABASE_URL
command? Do you see the environment variable?
Can you check that you have create an alias for DATABASE_URL
in your Qovery interface?
Thank you
soywod
(Clément DOUIN)
June 17, 2022, 4:45pm
3
I do not use the qovery
CLI, I will install it and let you know!
If I set directly DATABASE_URL
from the dashboard it works well, but I want it from my .env.production
file. I tried to setup an alias called DATABASE_URL_QOVERY
and put in my env file DATABASE_URL="${DATABASE_URL_QOVERY}"
but it does not work. I want it from the env file because I need to override some env vars given by qovery, like QOVERY_APPLICATION_XXX_HOST_EXTERNAL
: this one returns the domain of the frontend without https
, so I put in my env file FRONTEND_URL="https://${QOVERY_APPLICATION_XXX_HOST_EXTERNAL}"
. But no luck with this one also. Any other suggestion?
rophilogene
(Romaric Philogene)
June 17, 2022, 5:46pm
4
Ok, it makes total sense what you want to do.
Can your app interpolate environment variables from a .env
file? Meaning, does your app will replace the placeholders vars $XXX_YYY to the real value?
soywod
(Clément DOUIN)
June 17, 2022, 9:22pm
5
Yes it does, see Documentation | NestJS - A progressive Node.js framework . So it is technically possible but it looks like sth is preventing me to doing so
rophilogene
(Romaric Philogene)
June 18, 2022, 5:45am
6
I suspect a missing configuration in the Dockerfile. I DM you in private and we’ll report back the solution here.
Same issue here with CONFIG_ENV=production not passed to the build nextjs process when configured as a projet/environment/application env var. The only solution I have found is to force that env var value in the Dockerfile but that’s not as flexible
rophilogene
(Romaric Philogene)
June 20, 2022, 7:05am
8
Unfortunately, it’s a requirement of Docker.
Hi Romaric
Well, unless Qovery allowed for --build-arg passing to docker build … would that be feasable, says some list of --build-args in the same way as the env var list perhaps ?
rophilogene
(Romaric Philogene)
June 20, 2022, 7:24am
10
It’s already the case. Qovery passes --env
options which leads you to indicate which environment variables you want to use at the build time .
You can take a look at the engine code here:
vec!["build", "--publish", name_with_tag.as_str(), "--clear-cache"]
} else {
vec!["build", "--publish", name_with_tag.as_str()]
};
// always add 'latest' tag
buildpacks_args.extend(vec!["-t", name_with_latest_tag.as_str()]);
buildpacks_args.extend(vec!["--path", into_dir_docker_style]);
let mut args_buffer = Vec::with_capacity(build.environment_variables.len());
for (key, value) in &build.environment_variables {
args_buffer.push("--env".to_string());
args_buffer.push(format!("{}={}", key, value));
}
buildpacks_args.extend(args_buffer.iter().map(|value| value.as_str()).collect::<Vec<&str>>());
buildpacks_args.push("-B");
buildpacks_args.push(builder_name);
if let Some(buildpacks_language) = &build.git_repository.buildpack_language {
buildpacks_args.push("-b");
match buildpacks_language.split('@').collect::<Vec<&str>>().as_slice() {
Indeed, an improvement that we can do is using --build-arg
and giving the option to the user to specify which environment variable to use at the build time. Then we do not risk unnecessary invalidation of Docker builds cache layers.
cc @a_carrano
1 Like
soywod
(Clément DOUIN)
June 28, 2022, 3:27pm
11
I was able to do what I wanted be prefixing env directly inside the Dockerfile:
ARG FRONTEND_URL_QOVERY
ENV FRONTEND_URL "https://$FRONTEND_URL_QOVERY"
Thanks a lot for you help!
1 Like
rophilogene
(Romaric Philogene)
June 28, 2022, 3:37pm
12
Thank you @soywod for reporting back well done