Skip to content

Commit

Permalink
Fix instance_id variable
Browse files Browse the repository at this point in the history
  • Loading branch information
c-bordon committed Sep 5, 2024
1 parent 46505ce commit f6483ab
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions .github/workflows/builder_OVA.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,10 @@ on:
- -vvv

env:
COMPOSITE_NAME: "linux-amazon-2-amd64"
OVA_BASE_AMI: "ami-0d4bd55523ee67aa4"
INSTANCE_TYPE: "t2.xlarge"
SECURITY_GROUP: "sg-0471247ce289c863c"
SUBNET: "subnet-064e4e7b320dc5c2d"
TEMPORAL_S3_BUCKET: "warehouse.wazuh.com"
S3_BUCKET: "packages-dev.wazuh.com"
OVA_ENVIRONMENT: "vmware"
Expand Down Expand Up @@ -99,30 +102,29 @@ jobs:
- name: Create OVA VM
id: alloc_vm_ova
run: |
instance=$(aws ec2 run-instances --image-id ami-0d4bd55523ee67aa4 --count 1 --instance-type t2.xlarge --key-name Ephemeral --security-group-ids sg-0471247ce289c863c --subnet-id subnet-064e4e7b320dc5c2d)
instance_id=$(echo $instance | jq -r '.Instances[0].InstanceId')
aws ec2 create-tags --resources ${instance_id} --tags Key=Name,Value=gha_${{ github.run_id }}_ova_build
aws ec2 create-tags --resources ${instance_id} --tags Key=team,Value=devops
echo "instance_id=${instance_id}" >> $GITHUB_ENV
instance=$(aws ec2 run-instances --image-id ${{ OVA_BASE_AMI }} --count 1 --instance-type ${{ INSTANCE_TYPE }} --key-name Ephemeral --security-group-ids ${{ SECURITY_GROUP }} --subnet-id ${{ SUBNET }} \
--tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=gha_${{ github.run_id }}_ova_build},{Key=team,Value=devops}]')
INSTANCE_ID=$(echo $instance | jq -r '.Instances[0].InstanceId')
echo "INSTANCE_ID=${INSTANCE_ID}" >> $GITHUB_ENV
- name: Wait for instance to be running
run: |
MAX_RETRIES=40
NUM_RETRIES=0
while true; do
STATUS=$(aws ec2 describe-instances --instance-ids ${{ instance_id }} | jq -r '.Reservations[0].Instances[0].State.Name')
STATUS=$(aws ec2 describe-instances --instance-ids ${{ INSTANCE_ID }} | jq -r '.Reservations[0].Instances[0].State.Name')
if [ "${STATUS}" == "running" ]; then
break
fi
sleep 30
NUM_RETRIES=$((NUM_RETRIES+1))
if [ ${NUM_RETRIES} -eq ${MAX_RETRIES} ]; then
echo "Error creating OVA VM"
aws ec2 terminate-instances --instance-ids ${{ instance_id }}
aws ec2 terminate-instances --instance-ids ${{ INSTANCE_ID }}
exit 1
fi
done
ansible_host=$(aws ec2 describe-instances --instance-ids $instance_id | jq -r '.Reservations[0].Instances[0].PublicIpAddress')
ansible_host=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID | jq -r '.Reservations[0].Instances[0].PublicIpAddress')
mkdir -p /tmp/allocatorvm_ova
echo "[gha_instance]" > /tmp/allocatorvm_ova/inventory
echo "$ansible_host ansible_user=wazuh-user ansible_password=wazuh ansible_ssh_common_args='-o StrictHostKeyChecking=no'" >> /tmp/allocatorvm_ova/inventory
Expand Down Expand Up @@ -194,4 +196,4 @@ jobs:
- name: Delete allocated VM
if: always() && steps.alloc_vm_ova.outcome == 'success'
run: |
aws ec2 terminate-instances --instance-ids ${{ instance_id }}
aws ec2 terminate-instances --instance-ids ${{ INSTANCE_ID }}

0 comments on commit f6483ab

Please sign in to comment.