Title
j

James Fox

05/24/2020, 6:07 PM
Is there any guidance to running
npx ts-node --transpile-only src/schema
within a Docker container? The command doesn’t error for me, but the types are not generated
:docker: 1
🤔 1
It works fine when I run it outside of Docker
Dockerfile
FROM node:12.13.0

# All this to pass the database url from parameter store
ARG DATABASE_URL
ENV DATABASE_URL=$DATABASE_URL

ARG NODE_ENV
ENV NODE_ENV=$NODE_ENV

RUN mkdir /app
WORKDIR /app

COPY . .
RUN yarn install --no-optional \
  && yarn cache clean --force \
  && chown -R node ./

USER node
RUN npx prisma generate
RUN npx ts-node --transpile-only src/schema
RUN npx tsc

ENTRYPOINT yarn prod
docker-compose.yml
version: "3.7"
services:
  backend:
    image: backend
    container_name: backend
    ports:
      - "8000:8000"
    build:
      context: .
      dockerfile: Dockerfile
      args:
        - DATABASE_URL=${DATABASE_URL}
        - NODE_ENV=${NODE_ENV:-production}
    volumes:
      - "./:/app/"
      - ~/.aws/:/root/.aws:ro
r

Ryan

05/25/2020, 9:48 AM
Hey James 👋 Is there any error or console being shown while running this? As this command should generate the nexus types and schema.
j

James Fox

05/25/2020, 3:06 PM
Nope! That’s what’s strange
I’m not a Docker expert, but I would think that if I run the command from within the container, verify the typegen path, and don’t see an error, that the types would be written to the file system
r

Ryan

05/25/2020, 3:23 PM
Could you try it without npx and use it via a a
package.json
script? Something like:
"generate:nexus": "ts-node --transpile-only src/schema"
And then run
npm run generate:nexus
.
j

James Fox

05/25/2020, 3:42 PM
Will try that now - I have a
build
script just like the typescript graphql-apollo example (thats when i first encountered it not working)
same problem
Running the same commands outside the container works as expected:
i see the yarn version is older in the docker container. will try upgrading that
r

Ryan

05/25/2020, 3:51 PM
So there is an error actually while you run the dockerfile. Could you replace your
Dockerfile
with this and run as follows:
FROM node:12.13.0
# All this to pass the database url from parameter store
ARG DATABASE_URL
ENV DATABASE_URL=$DATABASE_URL
ARG NODE_ENV
ENV NODE_ENV=$NODE_ENV
RUN mkdir /app
WORKDIR /app
COPY . .
RUN yarn install --no-optional \
  && yarn cache clean --force

RUN npx prisma generate
RUN npx ts-node --transpile-only src/schema
RUN npx tsc
ENTRYPOINT yarn prod
j

James Fox

05/25/2020, 3:54 PM
trying that now!
although i did mess with
yarn cache clean
yesterday to no avail
r

Ryan

05/25/2020, 3:56 PM
yarn wasn't the issue, permissions were 🙂
j

James Fox

05/25/2020, 3:56 PM
Oh I see you removed
USER node
i originally didnt have that
and still encountered problems
(still am now after removing that)
r

Ryan

05/25/2020, 3:58 PM
Maybe try adding an mkdir then to create the folder beforehand
FROM node:12.13.0
# All this to pass the database url from parameter store
ARG DATABASE_URL
ENV DATABASE_URL=$DATABASE_URL
ARG NODE_ENV
ENV NODE_ENV=$NODE_ENV
RUN mkdir /app
WORKDIR /app
COPY . .
RUN yarn install --no-optional \
  && yarn cache clean --force
RUN npx prisma generate
RUN mkdir -p src/generate
RUN npx ts-node --transpile-only src/schema
RUN npx tsc
ENTRYPOINT yarn prod
j

James Fox

05/25/2020, 3:59 PM
i tried that yesterday too with no luck, but will try again!
RUN mkdir -p src/schema/generate
ya same issue (no errors but files not on filesystem)
heres my schema file output setup:
...
  plugins: [
    nexusPrismaPlugin({
      outputs: {
        typegen: __dirname + "/generated/nexusTypes.gen.ts",
      },
    }),
  ],
  outputs: {
    schema: __dirname + "/generated/schema.graphql",
    typegen: __dirname + "/generated/typings.ts",
  },
  ...
Oh boy- @Ryan I found the problem 🤦‍♂️
NODE_ENV=production
fails
NODE_ENV=development
succeeds
Reproducible outside of Docker via
NODE_ENV=production yarn build
But I guess that makes sense for a production build where types aren’t consumed
But im still confused because TSC is the tool that is generating the production code
and for it to compile, it must verify typings
r

Ryan

05/25/2020, 4:38 PM
That doesn't make up for the fact that docker cannot generate the directory Also the issue was with
npx ts-node --transpile-only src/schema
and not with the build
j

James Fox

05/25/2020, 4:41 PM
WDYM? I verified that setting NODE_ENV to development in the docker container fixed the issue
👍 1
The ts-node command is not outputting files when that is set to production
👍 1
This should probably be noted in the docs/examples as I expect others might come across it
For anyone who comes across this, the only change to my Dockerfile necessary was the
yarn build
command:
FROM node:12.13.0

# All this to pass the database url from parameter store
ARG DATABASE_URL
ENV DATABASE_URL=$DATABASE_URL

ARG NODE_ENV
ENV NODE_ENV=$NODE_ENV

RUN mkdir /app
WORKDIR /app

COPY . .
RUN yarn
# Run the tsc build in development mode so that the type definitions are emitted
RUN NODE_ENV=development yarn build
ENTRYPOINT yarn prod
👍 1