redwood
redwood copied to clipboard
[Bug?]: .env.defaults overwriting .env
What's not working?
We had a setup working since around may.
Basically setting environment variables via gitlab and copying everything over to then build. Today our test and prod instance was not able to connect to the database anymore.
It turned out, that suddenly the entries in .env.defaults
that we're also set via gitlab were overwritten by the default values.
I'm not sure what changed or if this is even actionable. So feel free to close it. Just making sure it's documented.
How do we reproduce the bug?
- Set an env variable both via
.env.defaults
and command line. - Redwood seems to end up with the one from defaults then
What's your environment? (If it applies)
This is my local one, not the server. It also seems to get the database wrong, we're using postgres.
System:
OS: Linux 5.18 Fedora Linux 36 (Workstation Edition)
Shell: 5.8.1 - /usr/bin/zsh
Binaries:
Node: 16.14.0 - /tmp/xfs-314f7f4e/node
Yarn: 3.2.1 - /tmp/xfs-314f7f4e/yarn
Databases:
SQLite: 3.36.0 - /usr/bin/sqlite3
Browsers:
Firefox: 102.0
npmPackages:
@redwoodjs/core: ^2.2.0 => 2.2.0
Are you interested in working on this?
- [ ] I'm interested in working on this
Hello @razzeee - thanks for raising this, but I'm not sure I quite understand what the issue here is.
I tried reproducing the simplest way to verify that I thought of was overriding the DATABASE_URL
variable.
Here's what I did:
- My
.env.defaults
hasDATABASE_URL=file:./dev.db
- In the command line I override it like this:
DATABASE_URL=file:./other.db yarn rw prisma migrate dev
- See that other.db gets created next to dev.db file
Which means that it's using the env var I set through the command line, not the default one.
Is this not the behaviour you are seeing?
It's not the behavior I'm seeing. But I think migrating worked at least I didn't see an error at that step, but on rw serve
I'm not sure if my docker file is breaking the env somehow, but I would be very surprised, as I did not change anything in that part of the code.
# ==
# Base
FROM node:16-alpine as base
WORKDIR /app
ARG NODE_ENV
ENV NODE_ENV=$NODE_ENV
ENV RUNTIME_ENV=$RUNTIME_ENV
ARG RUNTIME_ENV
ARG DATABASE_URL
ENV DATABASE_URL=$DATABASE_URL
ARG GITLAB_CLIENT_ID
ENV GITLAB_CLIENT_ID=$GITLAB_CLIENT_ID
ARG GITLAB_REDIRECT_URI
ENV GITLAB_REDIRECT_URI=$GITLAB_REDIRECT_URI
ARG GITLAB_AUTHORITY
ENV GITLAB_AUTHORITY=$GITLAB_AUTHORITY
ARG SITE_ID
ENV SITE_ID=$SITE_ID
ARG BASE_URL
ENV BASE_URL=$BASE_URL
COPY package.json package.json
COPY yarn.lock yarn.lock
COPY .yarn .yarn
COPY .yarnrc.yml .
COPY redwood.toml redwood.toml
COPY graphql.config.js graphql.config.js
COPY api/package.json api/package.json
COPY web/package.json web/package.json
RUN yarn install
COPY .env.defaults .
COPY run.sh .
# ==
# Build
FROM base as build
COPY api api
COPY web web
COPY scripts scripts
RUN yarn rw build api web
# ==
# Serve
FROM node:16-alpine as serve
WORKDIR /app
ARG DATABASE_URL
ENV DATABASE_URL=$DATABASE_URL
ARG GITLAB_AUTHORITY
ENV GITLAB_AUTHORITY=$GITLAB_AUTHORITY
COPY --from=build /app/run.sh /app/run.sh
RUN chmod +x ./run.sh
COPY --from=build /app/api/db/schema.prisma /app/api/db/schema.prisma
COPY --from=build /app/api/db/migrations /app/api/db/migrations
COPY --from=build /app/node_modules/.prisma /app/api/node_modules/.prisma
COPY --from=build /app/api/dist /app/api/dist
COPY --from=build /app/api/package.json /app/api/package.json
COPY --from=build /app/yarn.lock /app/api/yarn.lock
COPY --from=build /app/web/dist /app/web/dist
COPY --from=build /app/redwood.toml /app/redwood.toml
RUN yarn --cwd "api" --production install && \
yarn global add @redwoodjs/cli react react-dom prisma
EXPOSE 8910
ENTRYPOINT [ "./run.sh" ]
CMD [""]
run.sh
#!/bin/sh
# NOTE: Requires binaries. Install with:
# yarn global add @redwoodjs/api-server @redwoodjs/internal prisma
prisma migrate deploy --schema=/app/api/db/schema.prisma
rw serve