Skip to content

Instantly share code, notes, and snippets.

@OllyHodgson
Forked from TheRealFlyingCoder/Cloud Run & Remix
Created June 15, 2023 19:07
Show Gist options
  • Save OllyHodgson/18efe72f63cca08e8bd3c6de8980e49f to your computer and use it in GitHub Desktop.
Save OllyHodgson/18efe72f63cca08e8bd3c6de8980e49f to your computer and use it in GitHub Desktop.
Remix & Cloud Run
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"
}
}
]
}
],
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment