gpt4 book ai didi

amazon-web-services - 如何使用 github 操作部署到 aws elastic beanstalk?

转载 作者:行者123 更新时间:2023-12-05 06:48:58 25 4
gpt4 key购买 nike

我目前正在尝试通过 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

当前的 elastic beanstalk 环境设置了负载均衡器——我认为这是导致部署失败的主要问题。当环境包含负载均衡器时,我一直无法找到有关如何部署到 aws elastic beanstalk 的解决方案。 enter image description here

enter image description here

最佳答案

我知道你已经这样做了,但它会帮助有需要的人:-)我是新来的所以不能在框中正确写入,但是 yaml 代码从“name:dotnet..”开始直到结束,相应地缩进 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"

关于amazon-web-services - 如何使用 github 操作部署到 aws elastic beanstalk?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66701927/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com