首页 > 解决方案 > AWS CI/CD 与 GItHub 操作和代码部署到 EC2 实例

问题描述

我正在尝试使用 github 操作执行 ci/cd,并将 aws 代码部署到 ec2 实例。

我有一个 ec2 实例和三个 github 存储库(每个存储库也有自己的 gitflow)

name: Deployment

on:
  push:
    branches:
      - main
  pull_request:
    branches:
      - main

jobs:
  buildAndTest:
    name: CI Pipeline
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: [ '14.x' ]

    steps:
      - uses: actions/checkout@v2

      # Initialize Node.js
      - name: Install Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}

      # Install project dependencies, test and build
      - name: Install dependencies
        run: yarn
      - name: Run build
        run: yarn build

  deploy:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        node-version: ['14.x']
        appname: ['app_name']
        deploy-group: ['group_name']
        region: ['region']

    needs: [buildAndTest]
    if: github.ref == 'refs/heads/main'
    steps:
      - uses: actions/checkout@v2

      # Initialize Node.js
      - name: Install Node.js ${{ matrix.node-version }}
        uses: actions/setup-node@v1
        with:
          node-version: ${{ matrix.node-version }}
      # Step 1
      - 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: ${{ matrix.region }}
      # Step 2
      - name: Create CodeDeploy Deployment
        id: deploy
        run: |
          aws deploy create-deployment \
            --application-name ${{ matrix.appname }} \
            --deployment-group-name ${{ matrix.deploy-group }} \
            --deployment-config-name CodeDeployDefault.OneAtATime \
            --github-location repository=${{ github.repository }},commitId=${{ github.sha }}

当我向一个仓库推送或拉取请求时效果很好,但是当我一次推送两个仓库时,这意味着我要同时推送和部署,只有一个成功,另一个失败。

version: 0.0
os: linux
files:
  - source: .
    destination: /var/www/source

hooks:
  ApplicationStart:
    - location: deploy.sh // yarn install and restart server.
      timeout: 300
      runas: root

真正令人好奇的是,除了主要位置(在 ec2 中)之外,其他 repos(两个)中的一些文件(不包括 build 等)被删除了???我对三个存储库使用相同的应用程序和组 ID,这是一个问题吗?

任何帮助都会非常有帮助:)

标签: githubamazon-ec2github-actionspm2cicd

解决方案


推荐阅读