-
-
Save TheRealFlyingCoder/80556cb29463ae3d2b424f61e8e5830d to your computer and use it in GitHub Desktop.
So you want to set up remix in cloud run huh? It's pretty simple but i'm going to assume you can figure out most of the GCP UI on your own. | |
Cloud Run: | |
Step 1: Create a new service and take note of the service ID | |
Step 2: Allow all traffic in the /triggers tab | |
Cloud Build: | |
Step 1: Set up a Cloud Build trigger on your repo | |
Step 2: Point the configuration to "cloud build configuration file" at the root of your project | |
Step 3: Add the following to the substitution variables (so you can keep it safe): | |
_SERVICE_NAME: your service ID from Cloud run above | |
_DEPLOY_REGION: where you want it deployed to | |
Repo: | |
Step 1: Add the cloudbuild.yaml to your project root | |
Step 2: Add the Dockerfile to your project root | |
Note: The Dockerfile will change depending on which Remix version you are using | |
so try to understand what it does so you can make project specific changes | |
Step 3: Update your firebase.json to rewrite all routes to the cloud build service | |
Step 4: Push up the changes and watch to see cloud build successfully ran. |
steps: | |
# Build the container image | |
- name: "gcr.io/cloud-builders/docker" | |
args: | |
[ | |
"build", | |
"-t", | |
"gcr.io/$PROJECT_ID/$_SERVICE_NAME:$COMMIT_SHA", | |
"." | |
] | |
- name: 'gcr.io/cloud-builders/docker' | |
args: ['push', 'gcr.io/$PROJECT_ID/$_SERVICE_NAME:$COMMIT_SHA'] | |
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk' | |
entrypoint: gcloud | |
args: ['run', 'deploy', '$_SERVICE_NAME', '--image', 'gcr.io/$PROJECT_ID/$_SERVICE_NAME:$COMMIT_SHA', '--region', '$_DEPLOY_REGION'] | |
images: [ | |
"gcr.io/$PROJECT_ID/$_SERVICE_NAME:$COMMIT_SHA" | |
] |
# # base node image | |
FROM node:16-bullseye-slim as base | |
# # Build the dev image | |
FROM base as build | |
RUN mkdir /app/ | |
WORKDIR /app/ | |
COPY . /app | |
RUN npm install | |
RUN npm run build | |
# # Get the production modules | |
FROM base as production-deps | |
RUN mkdir /app/ | |
WORKDIR /app/ | |
COPY --from=build /app/node_modules /app/node_modules | |
ADD package.json package-lock.json /app/ | |
RUN npm prune --production | |
# Pull out the build files and do a production install | |
FROM base | |
ENV NODE_ENV=production | |
RUN mkdir /app/ | |
WORKDIR /app/ | |
ADD package.json package-lock.json /app/ | |
COPY --from=build /app/public /app/public | |
COPY --from=build /app/server /app/server | |
COPY --from=production-deps /app/node_modules /app/node_modules | |
CMD ["node", "server/index.js"] |
"hosting": [ | |
{ | |
"site": "my-site", | |
"public": "public", | |
"ignore": [ | |
"firebase.json", | |
"**/.*", | |
"**/node_modules/**" | |
], | |
"rewrites": [ | |
{ | |
"source": "**", | |
"run": { | |
"serviceId": "my-service-id" | |
} | |
} | |
] | |
} | |
], |
This is very helpful - thank you - what is the _REMIX_TOKEN for?
Oh that was from before open source I haven't touched this gist in ages 😅 you can ignore it
I just cleared it out, hopefully I didn't break the gist 👍
Thanks again, that makes sense now - still feels very recent as the Dockerfile looks similar to the one in the indie stack
First go this error (solved by using version 18)
1.637 Error: ️🚨 Oops, Node v16.20.2 detected. Remix requires a Node version greater than 18.
1.637 at Object.run (/app/node_modules/@remix-run/dev/dist/cli/run.js:106:11)
1.637 at Object.<anonymous> (/app/node_modules/@remix-run/dev/dist/cli.js:16:11)
1.637 at Module._compile (node:internal/modules/cjs/loader:1198:14)
1.637 at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10)
1.637 at Module.load (node:internal/modules/cjs/loader:1076:32)
1.637 at Function.Module._load (node:internal/modules/cjs/loader:911:12)
1.637 at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
1.637 at node:internal/main/run_main_module:22:47
I fixed this by using FROM node:18-bullseye-slim as base
But then afterwards I hit this error:
Dockerfile:27
--------------------
25 | ADD package.json package-lock.json /app/
26 | COPY --from=build /app/public /app/public
27 | >>> COPY --from=build /app/server /app/server
28 | COPY --from=production-deps /app/node_modules /app/node_modules
29 | CMD ["node", "server/index.js"]
--------------------
ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref FGXF:Q62Y:M7QI:W4P7:IXL
J:OCF2:W3ON:UOIC:QGZX:TV7E:AKES:UGCX::hd2muhin3q1pe47ocigqvh22k: "/app/server": not found
The 2nd issue is fixed by using npm run
instead. Here is the full working Dockerfile:
# # base node image
FROM node:18-bullseye-slim as base
# # Build the dev image
FROM base as build
RUN mkdir /app/
WORKDIR /app/
COPY . /app
RUN npm install
RUN npm run build
# # Get the production modules
FROM base as production-deps
RUN mkdir /app/
WORKDIR /app/
COPY --from=build /app/node_modules /app/node_modules
ADD package.json package-lock.json /app/
RUN npm prune --production
# Pull out the build files and do a production install
FROM base
ENV NODE_ENV=production
ENV HOST=0.0.0.0
ENV PORT=8080
RUN mkdir /app/
WORKDIR /app/
ADD package.json package-lock.json /app/
COPY --from=build /app/build /app/build
COPY --from=build /app/public/build /app/public/build
COPY --from=production-deps /app/node_modules /app/node_modules
CMD ["npm", "start"]
EXPOSE $PORT
First go this error (solved by using version 18)
1.637 Error: ️🚨 Oops, Node v16.20.2 detected. Remix requires a Node version greater than 18. 1.637 at Object.run (/app/node_modules/@remix-run/dev/dist/cli/run.js:106:11) 1.637 at Object.<anonymous> (/app/node_modules/@remix-run/dev/dist/cli.js:16:11) 1.637 at Module._compile (node:internal/modules/cjs/loader:1198:14) 1.637 at Object.Module._extensions..js (node:internal/modules/cjs/loader:1252:10) 1.637 at Module.load (node:internal/modules/cjs/loader:1076:32) 1.637 at Function.Module._load (node:internal/modules/cjs/loader:911:12) 1.637 at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) 1.637 at node:internal/main/run_main_module:22:47
I fixed this by using
FROM node:18-bullseye-slim as base
But then afterwards I hit this error:
Dockerfile:27 -------------------- 25 | ADD package.json package-lock.json /app/ 26 | COPY --from=build /app/public /app/public 27 | >>> COPY --from=build /app/server /app/server 28 | COPY --from=production-deps /app/node_modules /app/node_modules 29 | CMD ["node", "server/index.js"] -------------------- ERROR: failed to solve: failed to compute cache key: failed to calculate checksum of ref FGXF:Q62Y:M7QI:W4P7:IXL J:OCF2:W3ON:UOIC:QGZX:TV7E:AKES:UGCX::hd2muhin3q1pe47ocigqvh22k: "/app/server": not found
The 2nd issue is fixed by using
npm run
instead. Here is the full working Dockerfile:# # base node image FROM node:18-bullseye-slim as base # # Build the dev image FROM base as build RUN mkdir /app/ WORKDIR /app/ COPY . /app RUN npm install RUN npm run build # # Get the production modules FROM base as production-deps RUN mkdir /app/ WORKDIR /app/ COPY --from=build /app/node_modules /app/node_modules ADD package.json package-lock.json /app/ RUN npm prune --production # Pull out the build files and do a production install FROM base ENV NODE_ENV=production ENV HOST=0.0.0.0 ENV PORT=8080 RUN mkdir /app/ WORKDIR /app/ ADD package.json package-lock.json /app/ COPY --from=build /app/build /app/build COPY --from=build /app/public/build /app/public/build COPY --from=production-deps /app/node_modules /app/node_modules CMD ["npm", "start"] EXPOSE $PORT
You might be running a different version of remix but its probably similar I have a server.js file
so my dockerfile looked like
COPY --from=build /app/public /app/public COPY --from=build /app/build /app/build COPY --from=build /app/server.js /app/server.js
This is very helpful - thank you - what is the _REMIX_TOKEN for?