Would anyone be able to assist in sharing the Dockerfile they use for deployment on Google Cloud Run?
Very much out of my depth with docker 😅
to clarify, i'm having difficulties with the built image saying that it's unable to find payload config
try this out;
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 ./
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"]thank you for providing this, unfortunately this didn't solve the issue 😦
what i found though is that if the end CMD is instead ["yarn", "run", "serve"] it runs fine 🙂
mine keeps annoying me about missing secret key -- it's hilarious how each one of has inconsistent Dockerfiles. One would think a consistent one would be available now
That sounds like an environment variable problem. You shouldn't include your environment variable values in your Docker Container
Are you setting them in Google Cloud Run?
As long as you are not using Payload v3 beta, this docker file works as of Payload 2.14.1;
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 8000 ###change this
CMD ["node", "dist/server.js"]yeah i know it's bad practice but i'm trying to get one decent build through --- i've tried setting them in Cloud Run container and still get secret key doesnt exist message
my dockerfile is
FROM node:20-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/public ./public
COPY --from=builder /home/node/app/dist ./dist
COPY --from=builder /home/node/app/build ./build
COPY --from=builder /home/node/app/.next ./.next
EXPOSE 3000
CMD ["node", "dist/server.js"]i've also gone via cloudbuild.yaml route when setting up the trigger and force adding the ENV at build without success... same build failed error
steps:
# Build the Docker image
- name: 'gcr.io/cloud-builders/docker:latest'
dir: '.'
args:
- 'build'
- '-t'
- 'australia-southeast1-docker.pkg.dev/thankly-co/thankly-repository/cms:$SHORT_SHA'
- '-f'
- './Dockerfile'
- '--build-arg'
- 'PAYLOAD_SECRET=purplemonkeydishwasher'
- '.'
# Push the Docker image to Artifact Registry
- name: 'gcr.io/cloud-builders/docker'
args:
- 'push'
- 'australia-southeast1-docker.pkg.dev/thankly-co/thankly-repository/cms:$SHORT_SHA'
# Deploy the container to Cloud Run
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: gcloud
args:
- 'run'
- 'deploy'
- 'cms'
- '--region=australia-southeast1'
- '--platform=managed'
- '--image=australia-southeast1-docker.pkg.dev/thankly-co/thankly-repository/cms:$SHORT_SHA'
# - '--set-env-vars=ENV_VAR1=value1,ENV_VAR2=value2' # Add your environment variables here
timeout: '1800s'it's borked at build time -- but the prior instructions dont mention payload secret which has been a thing since forever
any ideas?
my Dockerfile
FROM node:20-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 8000
CMD ["node", "dist/server.js"]im on payload 2.14.2
my cloudbuild.yaml
steps:
# Print environment variables
- name: 'gcr.io/cloud-builders/docker:latest'
entrypoint: '/bin/sh'
args:
- '-c'
- 'printenv | sort'
env:
- PAYLOAD_SECRET=purplemonkeydishwasher
- DATABASE_URI=mongodb://mongo:27017/test
# Build the Docker image
- name: 'gcr.io/cloud-builders/docker:latest'
dir: '.'
args:
- 'build'
- '-t'
- 'australia-southeast1-docker.pkg.dev/thankly-co/thankly-repository/cms:$SHORT_SHA'
- '-f'
- './Dockerfile'
- '.'
# Push the Docker image to Artifact Registry
- name: 'gcr.io/cloud-builders/docker'
args:
- 'push'
- 'australia-southeast1-docker.pkg.dev/thankly-co/thankly-repository/cms:$SHORT_SHA'
# Deploy the container to Cloud Run
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: gcloud
args:
- 'run'
- 'deploy'
- 'cms'
- '--region=australia-southeast1'
- '--platform=managed'
- '--image=australia-southeast1-docker.pkg.dev/thankly-co/thankly-repository/cms:$SHORT_SHA'
timeout: '1800s'hey folks those monitoring this thread -- i've got Cloud Build working for me with some fun & games on ENVs during build.
deets here if useful --
https://discord.com/channels/967097582721572934/1158896261798301696Star
Discord
online
Get dedicated engineering support directly from the Payload team.