From cbb00b2e7bec0bda19354c414426bfdbd28f2338 Mon Sep 17 00:00:00 2001 From: Maria Grimaldi Date: Mon, 19 Aug 2024 12:39:42 -0400 Subject: [PATCH 1/4] feat: add enough configuration to use self-hosted runners --- .github/workflows/build.yml | 74 ++++++++++++++++++++++++++++++++++++- 1 file changed, 73 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3c045a3..dd118cf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,6 +19,10 @@ on: description: 'The service name to build' required: true type: string + AWS_EC2_INSTANCE_TYPE: + description: 'The EC2 instance type to start' + required: true + type: string secrets: DOCKERHUB_USERNAME: description: 'DockerHub username for login' @@ -29,10 +33,56 @@ on: SSH_PRIVATE_KEY: description: 'Service user SSH key for repository checkout' required: true + GH_PERSONAL_ACCESS_TOKEN: + description: 'GitHub personal access token' + required: true + AWS_ACCESS_KEY_ID: + description: 'AWS access key ID' + required: true + AWS_SECRET_ACCESS_KEY: + description: 'AWS secret access key' + required: true + AWS_REGION: + description: 'AWS region' + required: true + AWS_EC2_IMAGE_ID: + description: 'AWS EC2 image ID' + required: true + AWS_SUBNET_ID: + description: 'AWS subnet ID' + required: true + AWS_SECURITY_GROUP_ID: + description: 'AWS security group ID' + required: true jobs: - build: + start-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@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_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.GH_PERSONAL_ACCESS_TOKEN }} + ec2-image-id: ${{ secrets.AWS_EC2_IMAGE_ID }} + ec2-instance-type: ${{ inputs.AWS_EC2_INSTANCE_TYPE }} + subnet-id: ${{ secrets.AWS_SUBNET_ID }} + security-group-id: ${{ secrets.AWS_SECURITY_GROUP_ID }} + build: + name: Build service image + needs: start-runner + runs-on: ${{ needs.start-runner.outputs.label }} steps: - name: Login to DockerHub @@ -169,3 +219,25 @@ jobs: run: | . .tvm/bin/activate tutor images push $SERVICE + + stop-runner: + name: Stop self-hosted EC2 runner + needs: + - start-runner # required to get output from the start-runner job + - build # required to wait when the main job is done + runs-on: ubuntu-latest + if: ${{ always() }} + 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: ${{ secrets.AWS_REGION }} + - name: Stop EC2 runner + uses: machulav/ec2-github-runner@v2 + with: + mode: stop + github-token: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }} + label: ${{ needs.start-runner.outputs.label }} + ec2-instance-id: ${{ needs.start-runner.outputs.ec2-instance-id }} From 3fa35e53a500333a4ef2b8cfd15b8845121b40c2 Mon Sep 17 00:00:00 2001 From: Maria Grimaldi Date: Tue, 20 Aug 2024 15:35:55 -0400 Subject: [PATCH 2/4] refactor: use machine resources to build with parallelism --- .github/workflows/build.yml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dd118cf..2e87123 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -193,14 +193,6 @@ jobs: . .tvm/bin/activate tutor distro run-extra-commands - - name: Prepare docker if building MFE - if: ${{ inputs.SERVICE == 'mfe' }} - shell: bash - run: | - echo "[worker.oci]" > buildkit.toml - echo "max-parallelism = 2" >> buildkit.toml - docker buildx create --use --node=max2cpu --driver=docker-container --config=./buildkit.toml - - name: Build service image with no cache shell: bash working-directory: ${{ inputs.STRAIN_PATH }}/${{ env.TUTOR_APP_NAME }} From 05f89b12dbc0508ca12a7b507782db45328aa57f Mon Sep 17 00:00:00 2001 From: Maria Grimaldi Date: Wed, 21 Aug 2024 10:35:58 -0400 Subject: [PATCH 3/4] fix: use latest aws credentials action instead --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2e87123..dd1e4c1 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -64,7 +64,7 @@ jobs: ec2-instance-id: ${{ steps.start-ec2-runner.outputs.ec2-instance-id }} steps: - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v1 + uses: aws-actions/configure-aws-credentials@v4 with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} @@ -221,7 +221,7 @@ jobs: if: ${{ always() }} steps: - name: Configure AWS credentials - uses: aws-actions/configure-aws-credentials@v1 + uses: aws-actions/configure-aws-credentials@v4 with: aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} From 53c376ced18eb8ac1ae87667f09575dd0fc429a8 Mon Sep 17 00:00:00 2001 From: Maria Grimaldi Date: Wed, 21 Aug 2024 10:38:30 -0400 Subject: [PATCH 4/4] refactor: remove unnecessary comments --- .github/workflows/build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dd1e4c1..6d642cf 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -215,8 +215,8 @@ jobs: stop-runner: name: Stop self-hosted EC2 runner needs: - - start-runner # required to get output from the start-runner job - - build # required to wait when the main job is done + - start-runner + - build runs-on: ubuntu-latest if: ${{ always() }} steps: