繁体   English   中英

如何使用 github 操作部署到 aws elastic beanstalk?

[英]How to deploy to aws elastic beanstalk with github actions?

我目前正在尝试通过 github 操作进行自动部署。 下面是我当前的工作流程 yaml 文件:

name: Deploy AWS
on: [workflow_dispatch]

    
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
    
    - name: 'Git: Checkout source code'
      uses: actions/checkout@v1

    - name: '.NET Core: Setup'
      uses: actions/setup-dotnet@v1
      with:
        dotnet-version: '3.0.*'
    
    - name: '.NET Core: Get dependencies'
      run: dotnet restore
    
    - name: '.NET Core: Build'
      run: dotnet build --configuration Debug --no-restore

    - name: 'AWS: Timestamp action'
      uses: gerred/actions/current-time@master
      id: current-time
      
    - name: 'AWS: String replace action'
      uses: frabert/replace-string-action@master
      id: format-time
      with:
        pattern: '[:\.]+'
        string: "${{ steps.current-time.outputs.time }}"
        replace-with: '-'
        flags: 'g'

    - name: 'AWS: Generate build archive'
      run: (cd ./project.Api/bin/Debug/netcoreapp3.0 && zip -r "../../../../${{ steps.format-time.outputs.replaced }}.zip" . -x '*.git*')
    
    - name: 'AWS: Deploying build'
      uses: einaregilsson/beanstalk-deploy@v14
      with:
        aws_access_key: { my_access_key }
        aws_secret_key: { my_secret_key }            
        application_name: api_test
        environment_name: my-api-test
        version_label: "v${{ steps.format-time.outputs.replaced }}"
        region: ap-southeast-2
        deployment_package: "${{ steps.format-time.outputs.replaced }}.zip"
        
    - name: 'AWS: Deployment complete'
      run: echo Should be on EB now

当前的弹性 beantalk 环境是使用负载均衡器设置的——我认为这是部署失败导致的主要问题。 当环境包含负载均衡器时,我一直无法找到有关如何部署到 aws elastic beanstalk 的解决方案。 在此处输入图像描述

在此处输入图像描述

我知道你已经这样做了,但它会帮助有需要的人:-) 我是新来的所以不能在框中正确写入,但是 yaml 代码从“name:do.net..”开始直到结束,缩进 yaml因此

name: dotnet -> s3 -> Elastic Beanstalk
on:
   workflow_dispatch

#Setting up some environment variables
env:    
  EB_PACKAGE_S3_BUCKET_NAME : "php-bucket"
  EB_APPLICATION_NAME       : "dotnet-app"
  EB_ENVIRONMENT_NAME       : "Dotnetapp-env"
  DEPLOY_PACKAGE_NAME       : "dotnet-app-${{ github.sha }}.zip"
  AWS_REGION_NAME           : "af-south-1"

jobs:
 build_and_create_Artifact:
 runs-on: ubuntu-latest
 steps:
  - name: Checkout repo
    uses: actions/checkout@v3

  - name: Setup .NET Core
    uses: actions/setup-dotnet@v1
    with:
      dotnet-version: 6.0.*

  - name: Install dependencies
    run: dotnet restore

  - name: Build
    run: dotnet build --configuration Release --no-restore

  - name: Test
    run: dotnet test --no-restore --verbosity normal

  - name: Publish
    run: dotnet publish -c Release -o '${{ github.workspace }}/out'

  - name: Zip Package
    run: |
      cd ${{ github.workspace }}/out
      zip -r ${{ env.DEPLOY_PACKAGE_NAME }} *       

  - name: Upload a Build Artifact
    uses: actions/upload-artifact@v3.1.0
    with:

      name: .Net-artifact
      path: ${{ github.workspace }}/out/${{ env.DEPLOY_PACKAGE_NAME }}


    
  - name: "Configure AWS Credentials"
    uses: aws-actions/configure-aws-credentials@v1
    with:
       aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID}}
       aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
       aws-region: ${{ env.AWS_REGION_NAME }}
       
  - name: "Copy artifact to S3"     
    run: aws s3 cp ${{ github.workspace }}/out/${{ env.DEPLOY_PACKAGE_NAME }} s3://${{ env.EB_PACKAGE_S3_BUCKET_NAME }}/
       
  - name: "Build Successful"
    run: echo "CD part completed successfully"
  
Deploy_Artifact:
 needs: build_and_create_Artifact
 runs-on: ubuntu-latest
 steps: 
  - name: "Configure AWS Credentials"
    uses: aws-actions/configure-aws-credentials@v1
    with:
       aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID}}
       aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
       aws-region: ${{ env.AWS_REGION_NAME }}
     
  - name: 'AWS: Timestamp action'
    uses: gerred/actions/current-time@master
    id: current-time
  
  - name: 'AWS: String replace action'
    uses: frabert/replace-string-action@master
    id: format-time
    with:
     pattern: '[:\.]+'
     string: "${{ steps.current-time.outputs.time }}"
     replace-with: '-'
     flags: 'g'
           
  - name: "Create Elastic Beanstalk Application Version"
    run :  aws elasticbeanstalk create-application-version --application-name ${{ env.EB_APPLICATION_NAME }} --version-label version@${{ github.sha }} --source-bundle S3Bucket=${{ env.EB_PACKAGE_S3_BUCKET_NAME }},S3Key=${{ env.DEPLOY_PACKAGE_NAME }}  --description SHA_of_app_is_${{ github.sha }}__Created_at__${{ steps.format-time.outputs.replaced }}
   
  - name: "Deploy Application Version"
    run: aws elasticbeanstalk update-environment --environment-name ${{ env.EB_ENVIRONMENT_NAME }} --version-label "version@${{ github.sha }}"
   
  - name: "Successfully run CD pipeline"
    run: echo "CD part completed successfully"

暂无
暂无

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

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