Last active
January 9, 2024 15:09
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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;"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Wouldn't this copy all the code due to
COPY . .including yourpackage*.jsonfiles? 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?