Angular 谷歌云构建-firebase部署错误:“;公共目录';区/浏览器';不存在,可以';t将托管部署到站点PROJECT-ID“;
我试图同时将我的Angular Universal web应用程序部署到Cloud Run(用于SSR)和Firebase Hosting(用于缓存)。部署到云运行工作正常,我遵循本指南()使用Google Cloud Build启用Firebase部署 但是,每当我运行Angular 谷歌云构建-firebase部署错误:“;公共目录';区/浏览器';不存在,可以';t将托管部署到站点PROJECT-ID“;,angular,firebase,docker,google-cloud-run,google-cloud-build,Angular,Firebase,Docker,Google Cloud Run,Google Cloud Build,我试图同时将我的Angular Universal web应用程序部署到Cloud Run(用于SSR)和Firebase Hosting(用于缓存)。部署到云运行工作正常,我遵循本指南()使用Google Cloud Build启用Firebase部署 但是,每当我运行gcloud builds submit--config=cloudbuild.yaml时,在cloudbuild.yaml中的Firebase部署步骤中抛出错误:公用目录“dist/browser”不存在,无法将主机部署到站点
gcloud builds submit--config=cloudbuild.yaml
时,在cloudbuild.yaml
中的Firebase部署步骤中抛出错误:公用目录“dist/browser”不存在,无法将主机部署到站点项目ID
cloudbuild.yaml
:
步骤:
#塑造形象
-名称:“gcr.io/cloud builders/docker”
参数:['build','-t','gcr.io/PROJECT-ID/SERVICE-ID','.]
#推送图像
-名称:“gcr.io/cloud builders/docker”
参数:['push','gcr.io/PROJECT-ID/SERVICE-ID']
#部署到云运行
-名称:“gcr.io/cloud builders/gcloud”
参数:[“运行”、“部署”、“服务ID”、“--image”、“gcr.io/PROJECT-ID/SERVICE-ID”、“区域”、“us-central1”、“平台”、“托管”、“允许未经身份验证”]
#部署到Firebase(此处发生错误,指定的公用目录“xx”不存在,无法将主机部署到站点PROJECT-ID)
-名称:gcr.io/PROJECT-ID/firebase
参数:['deploy','-project=project-ID','-only=hosting']
图像:
-“gcr.io/PROJECT-ID/SERVICE-ID”
超时:1800秒
替换:
_环境变量:发展
Dockerfile
FROM node:14
# set work directory
WORKDIR usr/src/app
# copy package.json and package-lock
COPY package*.json ./
# install dependencies
RUN npm install
# copy local code to container
COPY . .
# build app
RUN npm run build:ssr
# serve app
CMD ["npm", "run", "serve:ssr"]
firebase.json
{
...
“托管”:[
{
“public”:“dist/browser”,
“忽略”:[
"**/.*"
],
...
}
]
...
}
错误日志
DEBUG: https://storage.googleapis.com:443 "GET /987290120943.cloudbuild-logs.googleusercontent.com/log-93082fbf-1b87-499a-9132-fed5f1c06aad.txt HTTP/1.1" 206 290
DEBUG: Reading GCS logfile: 206 (read 290 bytes)
Step #3:
Step #3: ←[1m←[37m===←[39m Deploying to 'PROJECT-ID'...←[22m
Step #3:
Step #3: ←[1m←[36mi ←[39m←[22m deploying ←[1mhosting←[22m
Step #3:
Step #3: ←[1m←[31mError:←[39m←[22m Specified public directory 'dist/browser' does not exist, can't deploy hosting to site PROJECT-ID
DEBUG: https://cloudbuild.googleapis.com:443 "GET /v1/projects/PROJECT-ID/locations/global/builds/93082fbf-1b87-499a-9132-fed5f1c06aad?alt=json HTTP/1.1" 200 None
DEBUG: https://storage.googleapis.com:443 "GET /987290120943.cloudbuild-logs.googleusercontent.com/log-93082fbf-1b87-499a-9132-fed5f1c06aad.txt HTTP/1.1" 206 120
DEBUG: Reading GCS logfile: 206 (read 120 bytes)
Finished Step #3
ERROR
ERROR: build step 3 "gcr.io/PROJECT-ID/firebase" failed: step exited with non-zero status: 1
DEBUG: https://storage.googleapis.com:443 "GET /987290120943.cloudbuild-logs.googleusercontent.com/log-93082fbf-1b87-499a-9132-fed5f1c06aad.txt HTTP/1.1" 416 168
DEBUG: Reading GCS logfile: 416 (no new content; keep polling)
由于本地一切正常,我假设它可能与gcr.io/PROJECT-ID/firebase
位于不同于创建dist
文件夹的服务gcr.io/PROJECT-ID/service-ID
的容器中有关
编辑#1:
我测试了在项目根目录中创建一个名为“static”的文件夹,并将firebase.json
中的public
属性更改为“static”。它起作用了,这让我相信由于某种原因,dist/browser
目录在cloudbuild.yaml
中的“部署到Firebase”步骤中不存在,即使它是在Dockerfile
的运行npm RUN build:ssr
期间创建的
编辑#2:
我在一个类似的问题上发现了一些不太充分的地方。但是,建议在cloudbuild.yaml
中的Firebase部署之前也运行build命令npm run build:ssr
,以确保dist/browser
目录存在。但我真的不想在云上运行一个构建,而是将一个新构建部署到Firebase,因为Angular每次都对.js
和.css
文件使用独特的哈希,我觉得这可能会导致缓存问题
编辑#3:
我创建了一个图像来更好地可视化我的问题(见下图)。我不熟悉docker和Cloud Build,但我觉得这是我运行gcloud builds submit--config=cloudbuild.yaml
时的过程。我不明白为什么dist/browser
存在于Dockerfile
范围中,而不存在于cloudbuild.yaml
范围中
根据,我无法访问cloudbuild.yaml
中的dist/browser
目录,因为该目录是通过Dockerfile
在不同的上下文中创建的
目前,我找到的唯一解决方案是在部署构建到云运行后立即将空文件夹部署到Firebase主机。据我所知,用户现在向Firebase Hosting发出请求,并在Firebase Hosting服务器上缓存响应。如果未缓存请求的数据,则会在firebase.json
中重写,允许从云运行中获取渲染数据,并在可能的情况下缓存
虽然它似乎可以工作,但我不知道Cloud Run中的文件是否正确缓存在Firebase主机上,此外,Lighthouse在性能方面的得分要差得多,因为之前Firebase主机自动管理的文本、图像和文件缺少压缩。尽管如此,目前这是最可行的解决方案。为了确认问题发生的步骤,您能否共享gcloud builds submit--config=cloudbuild.yaml-verbosity=“debug”
的日志输出?@FaridShumbar我将在接下来的几个小时内发布日志。然而,我觉得我知道问题发生在哪里,但我不知道如何解决它。问题可能是dist/browser
目录只存在于Dockerfile
上下文中,在该上下文中调用了npm run buid:ssr
,但不存在于cloudbuild.yaml
中,我想将dist/browser
目录部署到Firebase。也许上面的图片可以更好地说明这一点。