我试图找出如何最好地容器化我的 Vuejs 应用程序,然后将其上传到 Google Container Registry。
我已经把一些东西砍掉了,但我认为这是不对的,我的容器被推送到 GCR 但它不起作用。
# My GitHub action file to build the container
name: Build and Push container to GCR
on:
push:
branches: [ master ]
env:
PROJECT_ID: ${{ secrets.GKE_PROJECT }}
DEPLOYMENT_NAME: my-deployment
IMAGE: my-app-image
jobs:
setup-build-publish:
name: Setup, Build, Publish, and Deploy
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@master
# Setup gcloud CLI
- uses: GoogleCloudPlatform/github-actions/[email protected]
with:
service_account_key: ${{ secrets.GKE_SA_KEY }}
project_id: ${{ secrets.GKE_PROJECT }}
# Configure Docker to use the gcloud command-line tool as a credential
# helper for authentication
- run: |-
gcloud --quiet auth configure-docker
# Build the Docker image
- name: Build
run: |-
docker build \
--tag "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA" \
--build-arg GITHUB_SHA="$GITHUB_SHA" \
--build-arg GITHUB_REF="$GITHUB_REF" \
.
# Push the Docker image to Google Container Registry
- name: Publish
run: |-
docker push "gcr.io/$PROJECT_ID/$IMAGE:$GITHUB_SHA"
我的 Dockerfile
FROM node:lts-alpine
# make the 'app' folder the current working directory
WORKDIR /app
# copy both 'package.json' and 'package-lock.json' (if available)
COPY package*.json ./
# install project dependencies
RUN npm install
# copy project files and folders to the current working directory (i.e. 'app' folder)
COPY . .
# build app for production with minification
RUN npm run build
然后我将此容器部署到在 GCP 上运行的 clud,但出现错误
Cloud Run 错误:容器无法启动。无法启动然后侦听 PORT 环境变量定义的端口
我通常部署到 AppEngine,但我正在学习如何使用容器,我不太明白我所缺少的东西。
您收到的错误是因为您没有在代码中侦听传入的 HTTP 请求,或者正在侦听错误端口上的传入请求。
正如您在Cloud Run 容器运行时中所记录的那样,您的容器必须在由 Cloud Run 定义并在$PORT
环境变量中提供的端口上侦听传入的 HTTP 请求。
如果这失败,健康检查将失败,并且它会切换到错误状态并且流量不会被路由到正确的端口。
我会为 Node.js 发布一个示例,我可以看到您没有指定与端口相关的任何内容:
const port = process.env.PORT || 8080;
app.listen(port, () => {
console.log('Hello world listening on port', port);
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句