Skip to content

Instantly share code, notes, and snippets.

@nostrapollo
Last active January 9, 2024 15:09
Show Gist options
  • Select an option

  • Save nostrapollo/a7c777b284b1ef864766cebb6e3c838b to your computer and use it in GitHub Desktop.

Select an option

Save nostrapollo/a7c777b284b1ef864766cebb6e3c838b to your computer and use it in GitHub Desktop.
Build and deploy NX managed react app on Google Cloud Run using Dockerfile with multiple stages
steps:
# Build the container image
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', '${IMAGE_URL}', '.']
dir: 'app' # Working directory for build context
# Push the container image to Container Registry
- name: 'gcr.io/cloud-builders/docker'
args: ['push', '${IMAGE_URL}']
# Deploy container image to Cloud Run
- name: 'gcr.io/google.com/cloudsdktool/cloud-sdk'
entrypoint: gcloud
args: ['run', 'deploy', '${SERVICE_NAME}', '--image', '${IMAGE_URL}', '--region', 'us-central1', '--platform', 'managed']
substitutions:
# Replace these variables with your own values
IMAGE_URL: gcr.io/project-id/image-name:tag
SERVICE_NAME: 'service-name'
images: ['$IMAGE_URL']
#build stage for a Node.js application
FROM node:lts-alpine as build-stage
WORKDIR /app
COPY package*.json ./
RUN npm install
RUN npm install -g nx
COPY . .
RUN nx build app-name --prod
#production stage
FROM nginx:stable-alpine as production-stage
COPY --from=build-stage /app/dist/apps/app-name /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
@BoscoDomingo
Copy link

Wouldn't this copy all the code due to COPY . . including your package*.json files? Meaning if we had multiple apps and/or libraries, they'd be copied too, even if we don't need them for one specific app.

I assume this is for a single-app repo, correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment