Github 操作中的 docker 容器的 Vuejs
Vuejs to docker container in Github Actions
我正在尝试找出如何最好地容器化我的 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/setup-gcloud@0.1.3
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 error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable
我通常部署到 AppEngine,但我正在学习如何使用容器,我还不太了解我所缺少的东西。
您收到的错误是因为您没有在代码中侦听传入的 HTTP 请求,或者您在错误的端口上侦听传入的请求。
正如您在 Cloud Run container runtime 中看到的那样,您的容器必须在云 运行 定义并在 $PORT
环境变量中提供的端口上侦听传入的 HTTP 请求.
如果失败,健康检查将失败,并且会切换到错误状态,流量将不会路由到正确的端口。
我会 post 作为 Node.js 的示例,据我所知,您没有指定任何与端口相关的内容:
const port = process.env.PORT || 8080;
app.listen(port, () => {
console.log('Hello world listening on port', port);
});
我正在尝试找出如何最好地容器化我的 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/setup-gcloud@0.1.3
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 error: Container failed to start. Failed to start and then listen on the port defined by the PORT environment variable
我通常部署到 AppEngine,但我正在学习如何使用容器,我还不太了解我所缺少的东西。
您收到的错误是因为您没有在代码中侦听传入的 HTTP 请求,或者您在错误的端口上侦听传入的请求。
正如您在 Cloud Run container runtime 中看到的那样,您的容器必须在云 运行 定义并在 $PORT
环境变量中提供的端口上侦听传入的 HTTP 请求.
如果失败,健康检查将失败,并且会切换到错误状态,流量将不会路由到正确的端口。
我会 post 作为 Node.js 的示例,据我所知,您没有指定任何与端口相关的内容:
const port = process.env.PORT || 8080;
app.listen(port, () => {
console.log('Hello world listening on port', port);
});