Guide Notebooks Regression - EC2 #62
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Guide Notebooks Regression - EC2 | |
run-name: Guide Notebooks Regression - EC2 | |
on: [push] | |
jobs: | |
start_ec2_runner: | |
runs-on: ubuntu-latest | |
env: | |
AWS_KEY_ID: ${{ secrets.AWS_KEY_ID }} | |
AWS_KEY_SECRET: ${{ secrets.AWS_KEY_SECRET }} | |
AWS_INSTANCE_TYPE: ${{ vars.AWS_INSTANCE_TYPE }} | |
AWS_IMAGE_ID: ${{ vars.AWS_IMAGE_ID }} | |
AWS_SECURITY_GROUP: ${{ vars.AWS_SECURITY_GROUP }} | |
outputs: | |
EC2_INSTANCE_ID: ${{ steps.start_runner.outputs.EC2_INSTANCE_ID }} | |
steps: | |
- name: configure_aws | |
run: | | |
set -xe | |
sudo apt update | |
sudo apt install -y awscli jq | |
mkdir ${HOME}/.aws | |
echo "[default]" > ${HOME}/.aws/credentials | |
echo "aws_access_key_id = ${AWS_KEY_ID}" >> ${HOME}/.aws/credentials | |
echo "aws_secret_access_key = ${AWS_KEY_SECRET}" >> ${HOME}/.aws/credentials | |
echo "region = us-east-1" >> ${HOME}/.aws/credentials | |
cat ${HOME}/.aws/credentials | |
- name: start_runner | |
id: start_runner | |
run: | | |
set -xe | |
output=$(aws ec2 run-instances \ | |
--instance-type ${AWS_INSTANCE_TYPE} \ | |
--image-id ${AWS_IMAGE_ID} \ | |
--security-group-ids ${AWS_SECURITY_GROUP} \ | |
--count 1) | |
EC2_INSTANCE_ID=$(echo ${output} | jq -r ".Instances[0].InstanceId") | |
echo "EC2_INSTANCE_ID=${EC2_INSTANCE_ID}" >> "$GITHUB_OUTPUT" | |
guide_notebooks_regression_ec2: | |
runs-on: [self-hosted, nobrainer-ci-ec2-gpu] | |
needs: start_ec2_runner | |
steps: | |
- name: clone | |
uses: actions/checkout@v3 | |
- name: install | |
run: | | |
set -xe | |
cd ${{ github.workspace }} | |
python -m venv env | |
source env/bin/activate | |
pip install --upgrade pip | |
pip install matplotlib nilearn | |
pip install -e . | |
nobrainer info | |
- name: run | |
run: | | |
set -xe | |
cd ${{ github.workspace }} | |
git clone https://github.com/neuronets/nobrainer-book.git | |
cd nobrainer-book | |
# if there is a matching book branch, switch to it | |
if [ $(git ls-remote --heads https://github.com/neuronets/nobrainer-book.git ${{ github.ref_name }} | wc -l) -ne 0 ]; then | |
echo "Checking out branch ${{ github.ref_name }}" | |
git checkout ${{ github.ref_name }}; | |
else | |
echo "No matching branch found, sticking with the default" | |
fi | |
cd ${{ github.workspace }} | |
source env/bin/activate | |
for notebook_script in $(ls nobrainer-book/docs/nobrainer-guides/scripts/*.py); do | |
echo "running ${notebook_script}" | |
python ${notebook_script} | |
done | |
stop_ec2_runner: | |
if: always() | |
runs-on: ubuntu-latest | |
needs: [start_ec2_runner, guide_notebooks_regression_ec2] | |
env: | |
AWS_KEY_ID: ${{ secrets.AWS_KEY_ID }} | |
AWS_KEY_SECRET: ${{ secrets.AWS_KEY_SECRET }} | |
steps: | |
- name: configure_aws | |
run: | | |
set -xe | |
sudo apt update | |
sudo apt install -y awscli | |
mkdir ${HOME}/.aws | |
echo "[default]" > ${HOME}/.aws/credentials | |
echo "aws_access_key_id = ${AWS_KEY_ID}" >> ${HOME}/.aws/credentials | |
echo "aws_secret_access_key = ${AWS_KEY_SECRET}" >> ${HOME}/.aws/credentials | |
echo "region = us-east-1" >> ${HOME}/.aws/credentials | |
cat ${HOME}/.aws/credentials | |
- name: stop_runner | |
env: | |
EC2_INSTANCE_ID: ${{ needs.start_ec2_runner.outputs.EC2_INSTANCE_ID }} | |
run: | | |
set -xe | |
aws ec2 terminate-instances --instance-ids ${EC2_INSTANCE_ID} |