From 3d6647c4ff639d2f93dd1b5b3b58292794eba51a Mon Sep 17 00:00:00 2001 From: barshaul Date: Sat, 16 Mar 2024 13:08:42 +0000 Subject: [PATCH] Moved to SSM --- .github/workflows/npm-cd.yml | 12 ++++ .github/workflows/pypi-cd.yml | 63 ++++--------------- .../start-self-hosted-runner/action.yml | 22 +++++++ 3 files changed, 45 insertions(+), 52 deletions(-) create mode 100644 .github/workflows/start-self-hosted-runner/action.yml diff --git a/.github/workflows/npm-cd.yml b/.github/workflows/npm-cd.yml index 83b0ab6185..efe3d0b4be 100644 --- a/.github/workflows/npm-cd.yml +++ b/.github/workflows/npm-cd.yml @@ -7,6 +7,7 @@ on: paths: - .github/workflows/npm-cd.yml - .github/workflows/build-node-wrapper/action.yml + - .github/workflows/start-self-hosted-runner/action.yml push: tags: - "v*.*" @@ -16,7 +17,14 @@ concurrency: cancel-in-progress: true jobs: + start-self-hosted-runner: + runs-on: ubuntu-latest + steps: + - name: Start self hosted EC2 runner + uses: ./.github/workflows/start-self-hosted-runner + publish-binaries: + needs: start-self-hosted-runner if: github.repository_owner == 'aws' name: Publish packages to NPM runs-on: ${{ matrix.build.RUNNER }} @@ -54,6 +62,10 @@ jobs: TARGET: aarch64-apple-darwin, } steps: + - name: Cleanup self-hosted runner + if: ${{ contains(matrix.build.RUNNER, 'self-hosted') }} + run: sudo rm -rf /home/ubuntu/actions-runner/_work/glide-for-redis/glide-for-redis/node/target/ + - name: Checkout uses: actions/checkout@v4 with: diff --git a/.github/workflows/pypi-cd.yml b/.github/workflows/pypi-cd.yml index 81bd8c165f..d58bc451a1 100644 --- a/.github/workflows/pypi-cd.yml +++ b/.github/workflows/pypi-cd.yml @@ -7,6 +7,7 @@ on: paths: - .github/workflows/pypi-cd.yml - .github/workflows/build-python-wrapper/action.yml + - .github/workflows/start-self-hosted-runner/action.yml push: tags: - "v*.*" @@ -14,43 +15,19 @@ on: concurrency: group: pypi-${{ github.head_ref || github.ref }} cancel-in-progress: true -permissions: write-all jobs: start-self-hosted-runner: - name: Start self hosted EC2 runner - runs-on: ubuntu-latest - outputs: - label: ${{ steps.start-ec2-runner.outputs.label }} - ec2-instance-id: ${{ steps.start-ec2-runner.outputs.ec2-instance-id }} - steps: - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v4 - with: - aws-access-key-id: ${{ secrets.AWS_EC2_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_EC2_SECRET_ACCESS_KEY }} - aws-region: ${{ secrets.AWS_REGION }} - - name: Start EC2 runner - id: start-ec2-runner - uses: machulav/ec2-github-runner@v2 - with: - mode: start - github-token: ${{ secrets.GITHUB_TOKEN }} - ec2-image-id: ami-03831836fb1f65aac - ec2-instance-type: m6g.xlarge - subnet-id: subnet-0a88f7abc7e1490e1 - security-group-id: sg-05024f40170e648f0 - iam-role-name: github-actions-role - aws-resource-tags: > - [ - {"Key": "Name", "Value": "ec2-github-runner"}, - {"Key": "GitHubRepository", "Value": "${{ github.repository }}"} - ] + runs-on: ubuntu-latest + steps: + - name: Start self hosted EC2 runner + uses: ./.github/workflows/start-self-hosted-runner + publish-binaries: needs: start-self-hosted-runner if: github.repository_owner == 'aws' name: Publish packages to PyPi - runs-on: ${{ matrix.build.RUNNER == 'self-hosted' && needs.start-self-hosted-runner.outputs.label || matrix.build.RUNNER }} + runs-on: ${{ matrix.build.RUNNER }} strategy: fail-fast: false matrix: @@ -65,7 +42,7 @@ jobs: - { OS: ubuntu-latest, NAMED_OS: linux, - RUNNER: self-hosted, + RUNNER: [self-hosted, Linux, ARM64], ARCH: arm64, TARGET: aarch64-unknown-linux-gnu, CONTAINER: "2_28", @@ -85,6 +62,9 @@ jobs: TARGET: aarch64-apple-darwin, } steps: + - name: Cleanup self-hosted runner + if: ${{ contains(matrix.build.RUNNER, 'self-hosted') }} + run: sudo rm -rf /home/ubuntu/actions-runner/_work/glide-for-redis/glide-for-redis/python/target/ - name: Checkout uses: actions/checkout@v4 with: @@ -201,24 +181,3 @@ jobs: with: command: upload args: --skip-existing python/wheels/* - stop-runner: - name: Stop self-hosted EC2 runner - needs: - - start-self-hosted-runner # required to get output from the start-runner job - - publish-to-pypi # required to wait when the main job is done - runs-on: ubuntu-latest - if: ${{ always() }} # required to stop the runner even if the error happened in the previous jobs - steps: - - name: Configure AWS Credentials - uses: aws-actions/configure-aws-credentials@v4 - with: - aws-access-key-id: ${{ secrets.AWS_EC2_ACCESS_KEY_ID }} - aws-secret-access-key: ${{ secrets.AWS_EC2_SECRET_ACCESS_KEY }} - aws-region: ${{ secrets.AWS_REGION }} - - name: Stop EC2 runner - uses: machulav/ec2-github-runner@v2 - with: - mode: stop - github-token: ${{ secrets.GITHUB_TOKEN }} - label: ${{ needs.start-self-hosted-runner.outputs.label }} - ec2-instance-id: ${{ needs.start-self-hosted-runner.outputs.ec2-instance-id }} diff --git a/.github/workflows/start-self-hosted-runner/action.yml b/.github/workflows/start-self-hosted-runner/action.yml new file mode 100644 index 0000000000..148e91d294 --- /dev/null +++ b/.github/workflows/start-self-hosted-runner/action.yml @@ -0,0 +1,22 @@ +name: Start self hosted EC2 runner + +runs: + using: "composite" + steps: + start-self-hosted-runner: + name: Start self hosted EC2 runner + runs-on: ubuntu-latest + steps: + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + aws-access-key-id: ${{ secrets.AWS_EC2_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_EC2_SECRET_ACCESS_KEY }} + aws-region: ${{ secrets.AWS_REGION }} + - name: Start EC2 self hosted runner + shell: bash + run: | + sudo apt update + sudo apt install awscli -y + aws ssm send-command --instance-ids ${{secrets.AWS_EC2_INSTANCE_ID }} --document-name StartGithubSelfHostedRunner --output text + aws ssm list-command-invocations