R
Railway13mo ago
Craig

ENV vars not been passed on build?

Hello, i'm currently building a Payload CMS & Next.js website, I'm trying to deploy the site to Railway but keep getting the following error. Error: Error: missing secret key. A secret key is needed to secure Payload Even though all my env vars are set. Anyone had a similar sort of issue?
17 Replies
Percy
Percy13mo ago
Project ID: 1c0a43f8-b799-450b-a357-77fe5d973c74
Craig
CraigOP13mo ago
1c0a43f8-b799-450b-a357-77fe5d973c74
Fragly
Fragly13mo ago
Are the env vars set on railway's "Service Variables" in your project settings?
Craig
CraigOP13mo ago
Yeah
No description
Brody
Brody13mo ago
are you building with a dockerfile?
Craig
CraigOP13mo ago
@Brody yeah
Brody
Brody13mo ago
are you referencing the variable with ARG VARIABLE_NAME
Craig
CraigOP13mo ago
@Brody I don't reference any of the above variables in my docker file
FROM node:18.8-alpine as base

FROM base as builder

WORKDIR /home/node/app
COPY package*.json ./

COPY . .
RUN yarn install
RUN yarn build

FROM base as runtime

ENV NODE_ENV=production
ENV PAYLOAD_CONFIG_PATH=dist/payload.config.js

WORKDIR /home/node/app
COPY package*.json ./
COPY yarn.lock ./

RUN yarn install --production
COPY --from=builder /home/node/app/dist ./dist
COPY --from=builder /home/node/app/build ./build

EXPOSE 3000

CMD ["node", "dist/server.js"]
FROM node:18.8-alpine as base

FROM base as builder

WORKDIR /home/node/app
COPY package*.json ./

COPY . .
RUN yarn install
RUN yarn build

FROM base as runtime

ENV NODE_ENV=production
ENV PAYLOAD_CONFIG_PATH=dist/payload.config.js

WORKDIR /home/node/app
COPY package*.json ./
COPY yarn.lock ./

RUN yarn install --production
COPY --from=builder /home/node/app/dist ./dist
COPY --from=builder /home/node/app/build ./build

EXPOSE 3000

CMD ["node", "dist/server.js"]
Craig
CraigOP13mo ago
Turns out adding them does nothing... pushing my .env file does fix the issue but this obviously isn't ideal.
Brody
Brody13mo ago
show me the updated dockerfile please
Craig
CraigOP13mo ago
FROM node:18.8-alpine as base

FROM base as builder

WORKDIR /home/node/app
COPY package*.json ./

COPY . .
RUN yarn install
RUN yarn build

FROM base as runtime

ENV NODE_ENV=production
ENV PAYLOAD_CONFIG_PATH=dist/payload.config.js

ENV DATABASE_URI=xxx
ENV NEXT_PRIVATE_DRAFT_SECRET=xxx
ENV NEXT_PRIVATE_REVALIDATION_KEY=xxx
ENV NEXT_PUBLIC_IS_LIVE=false
ENV NEXT_PUBLIC_SERVER_URL=https://xxx
ENV PAYLOAD_PUBLIC_DRAFT_SECRET=xxx
ENV PAYLOAD_PUBLIC_SERVER_URL=https://xxx
ENV PAYLOAD_SECRET=xxx
ENV PORT=3000
ENV REVALIDATION_KEY=xxx

WORKDIR /home/node/app
COPY package*.json ./
COPY yarn.lock ./

RUN yarn install --production
COPY --from=builder /home/node/app/dist ./dist
COPY --from=builder /home/node/app/build ./build

EXPOSE 3000

CMD ["node", "dist/server.js"]
FROM node:18.8-alpine as base

FROM base as builder

WORKDIR /home/node/app
COPY package*.json ./

COPY . .
RUN yarn install
RUN yarn build

FROM base as runtime

ENV NODE_ENV=production
ENV PAYLOAD_CONFIG_PATH=dist/payload.config.js

ENV DATABASE_URI=xxx
ENV NEXT_PRIVATE_DRAFT_SECRET=xxx
ENV NEXT_PRIVATE_REVALIDATION_KEY=xxx
ENV NEXT_PUBLIC_IS_LIVE=false
ENV NEXT_PUBLIC_SERVER_URL=https://xxx
ENV PAYLOAD_PUBLIC_DRAFT_SECRET=xxx
ENV PAYLOAD_PUBLIC_SERVER_URL=https://xxx
ENV PAYLOAD_SECRET=xxx
ENV PORT=3000
ENV REVALIDATION_KEY=xxx

WORKDIR /home/node/app
COPY package*.json ./
COPY yarn.lock ./

RUN yarn install --production
COPY --from=builder /home/node/app/dist ./dist
COPY --from=builder /home/node/app/build ./build

EXPOSE 3000

CMD ["node", "dist/server.js"]
Brody
Brody13mo ago
hmmm don't think you read the docs page I linked either way, nixpacks should have no problem building a payload app, try temporarily removing or renaming the dockerfile and for sure remove the .env file from the repo and make sure it's in your gitignore
Craig
CraigOP13mo ago
Sorry just realised I didn't redo the file far enough, but I did use ARG PAYLOAD_SECRET=xxx already removed the .env was just a tempory thing to see if it built. WIll try removing the docker file and re adding it again.
Brody
Brody13mo ago
let me know how that goes!
Craig
CraigOP13mo ago
@Brody simple fix after all I just needed to move ARG PAYLOAD_SECRET before FROM base as runtime
Brody
Brody13mo ago
nixpacks couldn't build your app?
Want results from more Discord servers?
Add your server