【发布时间】:2021-05-17 18:03:41
【问题描述】:
我刚刚对我的 Angular Universal 应用程序进行了 docker 化,并使用创建的 docker 映像创建了一个 Google Cloud Run 服务,以在服务器上呈现 HTML。此外,由于它是一个已经使用 Firebase 托管的 Firebase 项目,因此我将 Cloud Run 与 Firebase 托管配对(参见参考文献https://firebase.google.com/docs/hosting/cloud-run?hl=en)。
1) 在根目录下创建Dockerfile:
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) 将 docker 容器添加到 Google Container Registry
gcloud builds submit --tag gcr.io/PROJECT_ID/CONTAINER_NAME --timeout=1200
3) 使用新容器创建 Cloud Run 服务
gcloud beta run deploy --image gcr.io/PROJECT_ID/CONTAINER_NAME
4) 更新 firebase.json 以将 Hosting 与 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)
}
} ]
}
按照本指南,我设法使其按预期工作。但是,现在我对将来如何正确部署代码更改感到困惑。在 Cloud Run 之前,我只是运行 firebase deploy --only hosting 将更改推送到静态服务器上。我是 docker 和容器的新手,但现在看来我必须将每个代码更改部署到 Firebase 托管,另外还部署到 Cloud Run(还可能为之前的每个小更改创建一个新容器?)。
【问题讨论】:
-
什么类型的变化是“每一个微小的变化”?程序代码、HTML 等。你是处于开发者模式还是生产模式。 Firebase/CloudRun 集成了请求处理,而不是容器的实际部署。
-
是的,对于“每一个微小的变化”,我基本上是指对 Angular 应用程序代码的更改。我处于生产模式,但是,我使用生产服务器 (https.//www.domain.com) 和测试服务器 (https.//www.test.domain.com),每个服务器都有自己的 Firebase 项目。它们具有相同的部署配置,但 Firebase 的 API 密钥不同。当前流程是 1) 进行更改,2) 构建代码,3) 将 dist-folder 部署到 Firebase 托管
标签: firebase-hosting angular-universal google-cloud-run