Deploy Remix to Cloud Run
Dockerfile
Now, we deploy Remix to Cloud Run using Tom Rowe's excellent gist with slight modification. Add this Dockerfile to your project root
# Credit to Tom Rowe https://gist.github.com/TheRealFlyingCoder/773bf60f433ccbdbad8c296a99fb3738# base node imageFROM node:16-bullseye-slim as base# Install all node_modules, including dev dependenciesFROM base as depsRUN mkdir /appWORKDIR /appADD package.json package-lock.json ./RUN npm install --production=false# Setup production node_modulesFROM base as production-depsRUN mkdir /appWORKDIR /appCOPY --from=deps /app/node_modules /app/node_modulesADD package.json package-lock.json ./RUN npm prune --production# Build the appFROM base as buildRUN mkdir /appWORKDIR /appCOPY --from=deps /app/node_modules /app/node_modulesADD . .RUN npm run build# Finally, build the production image with minimal footprintFROM baseENV NODE_ENV=productionRUN mkdir /appWORKDIR /appCOPY --from=production-deps /app/node_modules /app/node_modules#My build goes to /app/server/build and i'm running /server/index.js expressCOPY --from=build /app/build /app/buildCOPY --from=build /app/public /app/publicADD . .CMD ["npm", "run", "start"]
Add a .dockerignore file in the project root
hasura/build/public/node_modules/.env.cache.firebase
In the GCP console, enable the Cloud Build API
Enable the Cloud Run API
Run
gcloud init
and select your Firebase projectgcloud builds submit --tag gcr.io/<firebase project ID>/<any image name>
In the GCP console, create a Cloud Run service with your new image. Allow all traffic and allow unauthenticated invocations. In variables & secrets, add these four environment variables:
- FIREBASE_ADMIN_SERVICE_ACCOUNT - from your .env without the single wrapping quotes
- GRAPHQL_ENDPOINT - Your Hasura Cloud GraphQL endpoint
- HASURA_ADMIN_SECRET - Your Hasura Cloud admin secret
- COOKIE_SECRET - a randomly generated string of letters and numbers
- Once you've created the service Cloud Run will give you a URL. Test out your app by opening it in a web browser.
Did you find this page helpful?
Start with GraphQL on Hasura for Free
- Build apps and APIs 10x faster
- Built-in authorization and caching
- 8x more performant than hand-rolled APIs