diff --git a/spindown-ec2/action.yaml b/spindown-ec2/action.yaml deleted file mode 100644 index ba237919..00000000 --- a/spindown-ec2/action.yaml +++ /dev/null @@ -1,29 +0,0 @@ -name: 🔪 Spin down EC2 Runner -description: Spins down an EC2 Runner - -inputs: - github_runner_id: - description: Label of the Github runner to spindown (e.g. '7nwto') - cvs_ops_pat: - description: 'A Github PAT' - required: true - -runs: - using: composite - steps: - - name: Get EC2 instance ID - shell: bash - run: | - echo "aws_ec2_instance_id=$(aws ec2 describe-instances --query 'Reservations[*].Instances[].InstanceId' --filters "Name=tag:GHA_Runner_Tag,Values=${{ inputs.github_runner_id }}" --output text | cat)" >> $GITHUB_ENV - - - name: Target instance ID - shell: bash - run: echo ${{ env.aws_ec2_instance_id }} - - - name: 🛑 Stop EC2 runner - uses: dvsa/aws-github-runner@develop - with: - mode: stop - github-token: ${{ inputs.cvs_ops_pat }} - label: ${{ inputs.github_runner_id }} - ec2-instance-id: ${{ env.aws_ec2_instance_id }} diff --git a/spinup-ec2/action.yaml b/spinup-ec2/action.yaml deleted file mode 100644 index de9a36ab..00000000 --- a/spinup-ec2/action.yaml +++ /dev/null @@ -1,74 +0,0 @@ -name: 🔪 Spin up an EC2 Runner -description: Spins up an EC2 Runner - -inputs: - cvs_ops_pat: - description: 'A Github PAT' - required: true - aws-region: - description: AWS Region - required: true - -runs: - using: composite - steps: - - name: ♦️ Get DB Secrets - uses: aws-actions/aws-secretsmanager-get-secrets@v2.0.10 - with: - secret-ids: | - cvs-wms/env - parse-json-secrets: true - - - name: 🔭 Check active self hosted runners - shell: bash - env: - GH_TOKEN: ${{ inputs.cvs_ops_pat }} - id: runner-check - run: | - total_runners=$(gh api /repos/${{ github.repository }}/actions/runners | jq '[.runners[] | select(.status=="online") | select(.labels[] | select(.type == "custom" and .name == "EC2"))] | length') - available_ec2_runners=$(gh api /repos/${{ github.repository }}/actions/runners | jq '[.runners[] | select(.status=="online") | select(.busy==false) | select(.labels[] | select(.type == "custom" and .name == "EC2"))] | length') - if [[ $total_runners -ge 5 ]]; then - echo "Max number of EC2 runners reached" >> $GITHUB_STEP_SUMMARY - exit 1 - elif [[ $available_ec2_runners -eq 0 ]]; then - echo "No available EC2 runners" - start_runner=true - echo "starting EC2 runner..." >> $GITHUB_STEP_SUMMARY - else - echo "available_runners: $available_ec2_runners. Skipping ▶️ Start EC2 Runner" >> $GITHUB_STEP_SUMMARY - start_runner=false - fi - echo "start_runner=$start_runner" >> $GITHUB_OUTPUT - - - name: ▶️ Start EC2 Runner - if: ${{ steps.runner-check.outputs.start_runner == 'true' }} - id: start-ec2-runner - uses: dvsa/aws-github-runner@develop - with: - mode: start - github-token: ${{ inputs.cvs_ops_pat }} - ec2-image-id: ${{ env.CVS_WMS_ENV_AWS_EC2_AMI }} - ec2-instance-type: ${{ env.CVS_WMS_ENV_AWS_EC2_SIZE }} - subnet-id: ${{ env.CVS_WMS_ENV_AWS_SUBNET_ID }} - security-group-id: ${{ env.CVS_WMS_ENV_AWS_SECURITY_GROUP }} - iam-role-name: ${{ env.CVS_WMS_ENV_AWS_EC2_PROFILE }} - aws-resource-tags: > - [ - {"Key": "Name", "Value": "GHA Runner"}, - {"Key": "GitHubRepository", "Value": "${{ github.repository }}"}, - {"Key": "StartedBy", "Value": "${{ github.actor }}"}, - {"Key": "RunID", "Value": "${{ github.run_id }}"}, - {"Key": "Type", "Value": "GHA Runner"} - ] - pre-runner-script: | - echo test - - - name: 🏷️ Update Tags - if: ${{ steps.start-ec2-runner.outcome == 'success' }} - env: - GH_TOKEN: ${{ inputs.cvs_ops_pat }} - shell: bash - run: | - aws ec2 create-tags --resources ${{ steps.start-ec2-runner.outputs.ec2-instance-id }} --region ${{ inputs.aws-region }} --tags Key=GHA_Runner_Tag,Value=${{ steps.start-ec2-runner.outputs.label }} - runner_id=$(gh api /repos/${{ github.repository }}/actions/runners | jq '.runners[] | select(.labels[].name == "${{ steps.start-ec2-runner.outputs.label }}") .id') - gh api --method POST /repos/${{ github.repository }}/actions/runners/$runner_id/labels -f "labels[]=EC2"