I just dockerized my Angular Universal application and created a Google Cloud Run service with the created docker image to render the HTML on the server. Furthermore, since it was a Firebase project already using Firebase Hosting, I paired Cloud Run with Firebase Hosting (see ref. https://firebase.google.com/docs/hosting/cloud-run?hl=en).
1) create Dockerfile
in root:
Dockerfile
:
FROM node:14
WORKDIR usr/src/app
COPY package*.json ./
RUN npm install
# Copy local angular/nest code to the container
COPY . .
# Build development app
RUN npm run build:ssr
CMD ["npm", "run", "serve:ssr"]
2) Add docker container to Google Container Registry
gcloud builds submit --tag gcr.io/PROJECT_ID/CONTAINER_NAME --timeout=1200
3) Create Cloud Run service with the new container
gcloud beta run deploy --image gcr.io/PROJECT_ID/CONTAINER_NAME
4) Update firebase.json
to pair Hosting with Cloud Run
firebase.json
:
"hosting": {
// ...
// Add the "rewrites" attribute within "hosting"
"rewrites": [ {
"source": "**",
"run": {
"serviceId": "SERVICE_NAME", // "service name" (from when you deployed the container image)
"region": "europe-west3" // optional (if omitted, default is us-central1)
}
} ]
}
Following this guide, I managed to make it work as expected. However, now I´m confused on how to properly deploy code changes in the future. Before Cloud Run, I just ran firebase deploy --only hosting
to push the changes onto the static server. I´m new to docker and containers, but now it seems like I have to deploy every code change to Firebase Hosting and additionally to Cloud Run (and also probably create a new container for every little change before?).