tests: functional: Simplify GitLabCI configuration

- The GitLab CI Runner no longer directly runs AWS CLI commands
- The Runner calls two AWS Lambda functions for running or terminating the app servers
- The Lambda functions invoke AWS APIs using the Python boto3 library

Signed-off-by: Joseph Nuthalapati <njoseph@riseup.net>
Reviewed-by: Sunil Mohan Adapa <sunil@medhas.org>
This commit is contained in:
Joseph Nuthalapati 2022-06-30 18:57:15 +05:30 committed by Sunil Mohan Adapa
parent 35b50a2c71
commit 77f9037219
No known key found for this signature in database
GPG Key ID: 43EA1CFF0AA7C5F2

View File

@ -9,14 +9,10 @@
script:
- BUILD_JOB_ID=$(curl -s "https://salsa.debian.org/api/v4/projects/$CI_PROJECT_ID/pipelines/$CI_PIPELINE_ID/jobs?scope[]=success" | jq -r '.[] | select(.name==env.BUILD_JOB_NAME) | .id')
- export AWS_DEFAULT_REGION=us-east-1
- LAUNCH_TEMPLATE_ID=$(aws ec2 describe-launch-templates --launch-template-names $LAUNCH_TEMPLATE_NAME | jq -r ".LaunchTemplates[0].LaunchTemplateId")
- |
INSTANCE_ID=$(aws ec2 run-instances --launch-template LaunchTemplateId="$LAUNCH_TEMPLATE_ID" --associate-public-ip-address \
--tag-specifications "ResourceType=instance, Tags=[{Key=salsa:project-id,Value=$CI_PROJECT_ID},{Key=salsa:build-job-id,Value=$BUILD_JOB_ID},{Key=Name,Value=$INSTANCE_NAME}]" | \
jq -r ".Instances[0].InstanceId")
- APP_SERVER_IP=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID | jq -r ".Reservations[0].Instances[0].PublicIpAddress")
- echo "APP_SERVER_IP=$APP_SERVER_IP" >> app-servers.env
- echo "INSTANCE_ID=$INSTANCE_ID" >> app-servers.env
aws lambda invoke --function-name launch_app_server --payload '{"launch_template_name": "'"$LAUNCH_TEMPLATE_NAME"'", "instance_name": "'"$INSTANCE_NAME"'", "ci_project_id": "'"$CI_PROJECT_ID"'", "build_job_id": "'"$BUILD_JOB_ID"'"}' response.json
- echo "APP_SERVER_IP=$(jq -r '.app_server_ip' response.json)" >> app-servers.env
- echo "INSTANCE_ID=$(jq -r '.instance_id' response.json)" >> app-servers.env
tags:
- functional-tests
artifacts:
@ -58,6 +54,8 @@
.terminate-app-server:
stage: functional-tests
script:
- aws ec2 --region us-east-1 terminate-instances --instance-ids $INSTANCE_ID > /dev/null
- export AWS_DEFAULT_REGION=us-east-1
- |
aws lambda invoke --function-name terminate_app_server --payload '{"instance_id": "'"$INSTANCE_ID"'"}' response.json
tags:
- functional-tests