Github 对 EKS 和 ECR 的操作 CI/CD

Github Action CI/CD to EKS and ECR

我有一个基于 Node.js 的应用程序,我想自动化部署的每一步。 这是我的 workflow.yml

name: marketplace-ci

on:
  push:
    branches: [ master, staging ]
  pull_request:
    branches: [ master, staging ]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v2
    - name: Use Node.js 12
    - uses: actions/setup-node@v1
      with:
        node-version: '12'
    - run:  npm ci
    - run:  npm run build --if-present
    - run: npm test
      
    - name: Cache npm
      uses: bahmutov/npm-install@v1
    - run: npm t
    
    - name: copy env
      run: cp stag.dockerfile Dockerfile
      
    - name: Configure AWS credentials
      uses: aws-actions/configure-aws-credentials@v1
      with:
        aws-access-key-id: ${{AWS_ACCOUNT_ID}}
        aws-secret-access-key: ${{AWS_SECRET_KEY}}
        aws-region: ap-southeast-1

    # login ECR
    - name: Login to Amazon ECR
      id: login-ecr
      uses: aws-actions/amazon-ecr-login@v1
      
    - name: Get short SHA
      id: slug
      run: echo "::set-output name=sha8::$(echo ${GITHUB_SHA} | cut -c1-8)"
      
    - name: Build and Push to ECR
    - uses: whoan/docker-build-with-cache-action@v5
      with:
        username: ${{AWS_ACCOUNT_ID}}
        password: ${{AWS_SECRET_KEY}}
        registry: ${{ steps.login-ecr.outputs.registry }}
        image_name: marketplace
        image_tag: "stag-${{ steps.slug.outputs.sha8 }},staging"
        
    - name: Get image name
      id: image
      run: echo "::set-output name=image::${{ steps.login-ecr.outputs.registry }}/<path url registry lo>:prod-${{ steps.slug.outputs.sha8 }}"

    - name: Build and push CONTAINER_NAME
      uses: ianbelcher/eks-kubectl-action@master
      with:
        aws_access_key_id: ${{AWS_ACCOUNT_ID}}
        aws_secret_access_key: ${{AWS_ACCOUNT_ID}}
        aws_region: ap-southeast-1
        cluster_name: stag-marketplace
        args: set image deployment/stag-marketplace stag-marketplace=${{ steps.image.outputs.image }}

我有这样的错误 every step must define a `uses` or `run` key

请帮帮我,谢谢。

如错误信息所述

every step must define a `uses` or `run` key

每个步骤都以连字符 (-) 开头,并且应包含 usesrun 关键字。您的工作流程不符合要求。例如,该片段包含两个步骤

- name: Use Node.js 12
- uses: actions/setup-node@v1
  with:
    node-version: '12'

第一个无效

- name: Use Node.js 12

它不包含 usesrun 所以你得到错误。

应该是

- name: Use Node.js 12
  uses: actions/setup-node@v1
  with:
    node-version: '12'

或者您可以省略名称,它仍然有效

- uses: actions/setup-node@v1
  with:
    node-version: '12'

你也有同样的错误情况

- name: Build and Push to ECR
- uses: whoan/docker-build-with-cache-action@v5

应该是

- name: Build and Push to ECR
  uses: whoan/docker-build-with-cache-action@v5

或者干脆

- uses: whoan/docker-build-with-cache-action@v5

通常,您不能将单个 - name: 作为步骤定义。它后面应该跟不带连字符的 usesrun,因为它已经添加到 name: 旁边。连字符开始一个新步骤,如错误消息所述:

every step must define a `uses` or `run` key