简体   繁体   English

Vuejs 到 Github Actions 中的 docker 容器

[英]Vuejs to docker container in Github Actions

I'm trying to find out how to best containerize my Vuejs app and then upload it to Google Container Registry.我试图找出如何最好地容器化我的 Vuejs 应用程序,然后将其上传到 Google Container Registry。

I've hacked and slashed some stuff together but I don't think it's right, my container gets pushed to GCR but it doesn't work.我已经把一些东西砍掉了,但我认为这是不对的,我的容器被推送到 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"

My Dockerfile我的 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

I then deploy this container to clud run on GCP but I get the error然后我将此容器部署到在 GCP 上运行的 clud,但出现错误

Cloud Run error: Container failed to start. Cloud Run 错误:容器无法启动。 Failed to start and then listen on the port defined by the PORT environment variable无法启动然后侦听 PORT 环境变量定义的端口

I typically deploy to AppEngine, but I'm learning how to use containers, I'm not quite getting what I'm missing.我通常部署到 AppEngine,但我正在学习如何使用容器,我不太明白我所缺少的东西。

The error you are getting is because you aren't listening for incoming HTTP requests in your code or you're listening for incoming requests on the wrong port.您收到的错误是因为您没有在代码中侦听传入的 HTTP 请求,或者正在侦听错误端口上的传入请求。

As you can see documented in the Cloud Run container runtime , your container must listen for incoming HTTP requests on the port that is defined by Cloud Run and provided in the $PORT environment variable.正如您在Cloud Run 容器运行时中所记录的那样,您的容器必须在由 Cloud Run 定义并在$PORT环境变量中提供的端口上侦听传入的 HTTP 请求。

If this fails, the health check will fail to, and it would switch to an error state and the traffic will not be routed to the correct PORT.如果这失败,健康检查将失败,并且它会切换到错误状态并且流量不会被路由到正确的端口。

I would post an example for Node.js and as I can see you do not have specified anything related to the port:我会为 Node.js 发布一个示例,我可以看到您没有指定与端口相关的任何内容:

const port = process.env.PORT || 8080;
app.listen(port, () => {
  console.log('Hello world listening on port', port);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM