Search code examples
dockerkubernetesgithub-actionsamazon-eksamazon-ecr

Github Action CI/CD to EKS and ECR


i have an apps based on Node.js and i want to automation every step my deployment. here my 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 }}

and i have an error like this every step must define a `uses` or `run` key

please help me, thank you.


Solution

  • As the error message says

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

    Each step begins with a hyphen (-) and should contain uses or run keyword. Your workflow does not meet the requirements. For example, the fragment contains two steps

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

    The first one is invalid

    - name: Use Node.js 12
    

    It does not contain uses or run so you get the error.

    It should be

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

    or you can omit the name and it still will be valid

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

    You have also the same erroneous case in

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

    It should be

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

    or simply

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

    As a rule, you cannot have a single - name: as the step definition. It should be followed either with uses or run without a hyphen as it's already added next to name:. A hyphen starts a new step and, as the error message says:

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