Skip to content

Merge branch 'main' into ASReview2-rf #28

Merge branch 'main' into ASReview2-rf

Merge branch 'main' into ASReview2-rf #28

Workflow file for this run

name: Deploy ASReview Optuna Environment
on:
push:
tags:
- "*"
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v3
- name: Install Dependencies
run: |
sudo apt update
sudo apt install -y ansible jq curl
- name: Setup Exoscale CLI
uses: nhedger/setup-exoscale@v3
with:
account: github-actions
zone: de-fra-1
key: ${{ secrets.EXOSCALE_API_KEY }}
secret: ${{ secrets.EXOSCALE_API_SECRET }}
- name: Find and Start Stopped Instance
id: start-instance
run: |
set +e
INSTANCE_NAME=""
COUNT=0
while [ $COUNT -lt 5 ]; do
INSTANCE_NAME=$(exo compute instance list --output-format=json | \
jq -r '.[] | select(.name | test("^asreview2-optuna-")) | select(.state == "stopped") | .name' | head -n 1)
if [ -n "$INSTANCE_NAME" ]; then
echo "Found stopped instance: $INSTANCE_NAME"
break
fi
COUNT=$((COUNT + 1))
echo "Attempt $COUNT of 5 to find a stopped instance failed. Retrying in 5 seconds..."
sleep 5
done
if [ -z "$INSTANCE_NAME" ]; then
echo "Failed to find any stopped instances after 5 attempts."
exit 1
fi
echo "instance_name=$INSTANCE_NAME" >> $GITHUB_ENV
- name: Start the Instance
run: |
set +e
COUNT=0
SUCCESS=false
while [ $COUNT -lt 5 ]; do
echo "Attempting to start instance: ${{ env.instance_name }}"
exo compute instance start -f "${{ env.instance_name }}"
if [ $? -eq 0 ]; then
SUCCESS=true
break
fi
COUNT=$((COUNT + 1))
echo "Attempt $COUNT of 5 to start instance failed. Retrying in 5 seconds..."
sleep 5
done
if [ "$SUCCESS" != "true" ]; then
echo "Failed to start the instance after 5 attempts."
exit 1
fi
- name: Retrieve Instance IP
run: |
set +e
COUNT=0
INSTANCE_IP=""
while [ $COUNT -lt 5 ]; do
INSTANCE_IP=$(exo compute instance show "${{ env.instance_name }}" --output-format=json | jq -r '.ip_address')
if [ -n "$INSTANCE_IP" ]; then
echo "Retrieved IP: $INSTANCE_IP"
break
fi
COUNT=$((COUNT + 1))
echo "Attempt $COUNT of 5 to retrieve instance IP failed. Retrying in 5 seconds..."
sleep 5
done
if [ -z "$INSTANCE_IP" ]; then
echo "Failed to retrieve IP address for instance after 5 attempts."
exit 1
fi
echo "instance_ip=$INSTANCE_IP" >> $GITHUB_ENV
- name: Set Up SSH Private Key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
- name: Create Ansible Inventory File
run: |
echo "[asreview2]" > inventory.ini
echo "${{ env.instance_ip }}" >> inventory.ini
- name: Deploy Ansible Playbook
env:
ANSIBLE_HOST_KEY_CHECKING: "False"
run: |
echo "Sleeping to ensure instance is ready..."
sleep 20
ansible-playbook ./asreview2-optuna/ansible/ansible_optuna_playbook.yml \
--extra-vars "branch_name=${{ github.ref_name }} db_uri=${{ secrets.DB_API }}" \
-u ubuntu --private-key ~/.ssh/id_rsa -i inventory.ini