diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 83f7ab9c..f40d72fb 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -24,9 +24,34 @@ on: workflow_dispatch: -jobs: +jobs: + 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: us-west-2 + - 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: ami-079a0c9425d45e778 + ec2-instance-type: t3.xlarge + subnet-id: subnet-0c4a81ef57cf2ebe3 + security-group-id: sg-01cb8c0cb0de3ba00 + docker-pipeline: - runs-on: self-hosted + needs: start-runner # required to start the main job when the runner is ready + runs-on: ${{ needs.start-runner.outputs.label }} if: > !contains(github.event.head_commit.message , 'skip ci') && !contains(github.event.pull_request.title, 'skip ci') @@ -45,16 +70,26 @@ jobs: run: | docker image prune -a -f docker container prune -f + sudo rm -rf /usr/local/lib/android + sudo rm -rf /usr/share/dotnet + sudo rm -rf /opt/ghc + sudo rm -rf "/usr/local/share/boost" + sudo rm -rf "$AGENT_TOOLSDIRECTORY" - name: Check Free Space 1 run: | echo "Free space:" df -h + - name: Set up Python 3.8 + uses: actions/setup-python@v3 + with: + python-version: 3.8 + - name: Install pip dependencies run: | - python3 -m pip install --upgrade pip - python3 -m pip install -r scripts/requirements.txt + python -m pip install --upgrade pip + pip install -r scripts/requirements.txt - name: Install selenium dependecies for r studio run: | @@ -64,7 +99,7 @@ jobs: - name: Install pydoit fixed run: | git clone https://github.com/davidzyx/doit - python3 -m pip install ./doit + pip install ./doit rm -rf ./doit mkdir -p logs manifests touch logs/run.log @@ -104,7 +139,7 @@ jobs: GRPC_CERT: ${{ secrets.GRPC_CERT }} PREPUSH_IMAGES: '["ghcr.io/ucsd-ets/scipy-ml-notebook"]' run: | - sudo python3 scripts/main.py + python3 scripts/main.py - name: Check Free Space 3 run: | @@ -133,3 +168,24 @@ jobs: artifacts logs manifests + stop-runner: + name: Stop self-hosted EC2 runner + needs: + - start-runner # required to get output from the start-runner job + - docker-pipeline # 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@v1 + with: + aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} + aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + aws-region: us-west-2 + - 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 }}