From fbf44635722ae22a961b44e3dccd1d42c8b16161 Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 11:08:14 -0600 Subject: [PATCH 01/28] remove duplicate code in multiple stages --- .gitlab/.gitlab-ci.yml | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/.gitlab/.gitlab-ci.yml b/.gitlab/.gitlab-ci.yml index 4fe913596..9448a0311 100644 --- a/.gitlab/.gitlab-ci.yml +++ b/.gitlab/.gitlab-ci.yml @@ -221,12 +221,6 @@ deploy node for linux amd64: - aws ec2 run-instances --image-id $AMI --instance-type $INSTANCE --security-group-ids $SECURITY_GROUP --subnet-id $SUBNET_ID --key-name gitlab-featurebase-dev --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=linux-amd64-node}]' --profile $PROFILE --user-data file://./qa/scripts/cloud-init.sh --iam-instance-profile Name=featurebase-dev-ssm > config.json - INSTANCE_ID=$(jq '.Instances | .[] |.InstanceId' config.json | tr -d '"') - echo $INSTANCE_ID > linux-amd64-instance.txt - - sleep 120 # Need to wait for the EC2 instance to launch and run the initialization commands passed through user-data - - PUBLIC_IP=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --filters 'Name=instance-state-name, Values=running' --query 'Reservations[*].Instances[*].PublicIpAddress' --output text --profile $PROFILE) - - echo $PUBLIC_IP - - scp -o StrictHostKeyChecking=no -i gitlab-featurebase-dev.pem featurebase_linux_amd64 ec2-user@$PUBLIC_IP:. - - scp -o StrictHostKeyChecking=no -i gitlab-featurebase-dev.pem ./qa/scripts/featurebase.conf ./qa/scripts/featurebase.service ec2-user@$PUBLIC_IP:. - - aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids $INSTANCE_ID --cli-input-json file://./qa/scripts/configureFeatureBase.json --profile $PROFILE --region us-east-2 needs: - job: build for linux amd64 artifacts: @@ -260,8 +254,8 @@ initiate featurebase linux amd64 in node: - INSTANCE_ID=$(cat linux-amd64-instance.txt) script: - for i in {0..24}; do IP=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --filters 'Name=instance-state-name, Values=running' --query 'Reservations[*].Instances[*].PublicIpAddress' --output text --profile $PROFILE); if [ -n "$IP" ]; then break; fi; sleep 5; done - - scp -o StrictHostKeyChecking=no -i gitlab-featurebase-dev.pem featurebase_linux_amd64 .gitlab/featurebase.conf .gitlab/featurebase.service ec2-user@$IP:. - - aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids $INSTANCE_ID --cli-input-json file://.gitlab/configureFeatureBase.json --profile $PROFILE --region us-east-2 + - scp -o StrictHostKeyChecking=no -i gitlab-featurebase-dev.pem featurebase_linux_amd64 ./qa/scripts/featurebase.conf ./qa/scripts/featurebase.service ec2-user@$IP:. + - aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids $INSTANCE_ID --cli-input-json file://./qa/scripts/configureFeatureBase.json --profile $PROFILE --region us-east-2 needs: - job: build for linux amd64 - job: deploy node for linux amd64 From 7e8cbdeb53d891248f5e3e74204db57b6eebb3bb Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 12:09:51 -0600 Subject: [PATCH 02/28] updated a comment to trigger the pipeline for another test --- .gitlab/.gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab/.gitlab-ci.yml b/.gitlab/.gitlab-ci.yml index 9448a0311..c2161df43 100644 --- a/.gitlab/.gitlab-ci.yml +++ b/.gitlab/.gitlab-ci.yml @@ -196,7 +196,7 @@ build container fb: - docker push $tag - echo Created docker featurebase image with tag "$tag" -# deploy EC2 instance and save instance ID +# deploy EC2 instance and save instance ID to a text file deploy node for linux amd64: stage: integration image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest From 692f2f8cb46f48a2241ac0918afcdec3fcd26c58 Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 13:29:56 -0600 Subject: [PATCH 03/28] updated dependency of jobs and made instanceId a global variable --- .gitlab/.gitlab-ci.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitlab/.gitlab-ci.yml b/.gitlab/.gitlab-ci.yml index c2161df43..80796aa3c 100644 --- a/.gitlab/.gitlab-ci.yml +++ b/.gitlab/.gitlab-ci.yml @@ -12,6 +12,7 @@ include: - .go/pkg/mod/ variables: GOVERSION: "1.16.9" + INSTANCE_ID_FILE: ./linux-amd64-instance.txt stages: - lint @@ -220,12 +221,12 @@ deploy node for linux amd64: - SUBNET_ID=$(aws ec2 describe-subnets --filters 'Name=vpc-id,Values=vpc-03a4ba3d5b7c8f978' 'Name=availability-zone,Values=us-east-2a' --query 'Subnets[0].SubnetId' --output text --profile $PROFILE) - aws ec2 run-instances --image-id $AMI --instance-type $INSTANCE --security-group-ids $SECURITY_GROUP --subnet-id $SUBNET_ID --key-name gitlab-featurebase-dev --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=linux-amd64-node}]' --profile $PROFILE --user-data file://./qa/scripts/cloud-init.sh --iam-instance-profile Name=featurebase-dev-ssm > config.json - INSTANCE_ID=$(jq '.Instances | .[] |.InstanceId' config.json | tr -d '"') - - echo $INSTANCE_ID > linux-amd64-instance.txt + - echo $INSTANCE_ID > $INSTANCE_ID_FILE needs: - job: build for linux amd64 artifacts: paths: - - linux-amd64-instance.txt + - $INSTANCE_ID_FILE needs: - job: build for linux amd64 @@ -251,7 +252,7 @@ initiate featurebase linux amd64 in node: - echo "$AWS_SSH_PRIVATE_KEY" | ssh-add - - chmod 700 /root/.ssh - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config' - - INSTANCE_ID=$(cat linux-amd64-instance.txt) + - INSTANCE_ID=$(cat $INSTANCE_ID_FILE) script: - for i in {0..24}; do IP=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --filters 'Name=instance-state-name, Values=running' --query 'Reservations[*].Instances[*].PublicIpAddress' --output text --profile $PROFILE); if [ -n "$IP" ]; then break; fi; sleep 5; done - scp -o StrictHostKeyChecking=no -i gitlab-featurebase-dev.pem featurebase_linux_amd64 ./qa/scripts/featurebase.conf ./qa/scripts/featurebase.service ec2-user@$IP:. @@ -270,10 +271,9 @@ terminate node for linux amd64: - aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID - aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY - aws configure set region "us-east-2" - - INSTANCE_ID=$(cat linux-amd64-instance.txt) + - INSTANCE_ID=$(cat $INSTANCE_ID_FILE) script: - aws ec2 terminate-instances --instance-ids $INSTANCE_ID needs: - - job: deploy node for linux amd64 - job: initiate featurebase linux amd64 in node when: always From cce48a2638c13b28de0c3e9e7790219ea3f91d9e Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 15:24:47 -0600 Subject: [PATCH 04/28] created a shell script for deplooying node and handling error conditions --- .gitlab/.gitlab-ci.yml | 82 ++-------------------------------- qa/scripts/deployNode.sh | 96 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+), 78 deletions(-) create mode 100755 qa/scripts/deployNode.sh diff --git a/.gitlab/.gitlab-ci.yml b/.gitlab/.gitlab-ci.yml index 80796aa3c..656e4e4d5 100644 --- a/.gitlab/.gitlab-ci.yml +++ b/.gitlab/.gitlab-ci.yml @@ -12,13 +12,13 @@ include: - .go/pkg/mod/ variables: GOVERSION: "1.16.9" - INSTANCE_ID_FILE: ./linux-amd64-instance.txt stages: + - integration - lint - test - build - - integration + #before_script: #- echo "before_script" @@ -115,7 +115,7 @@ upload to sonarcloud: - job: run jest tests build for linux amd64: - stage: build + stage: integration image: golang:1.16.10 script: - rm -r lattice @@ -201,79 +201,5 @@ build container fb: deploy node for linux amd64: stage: integration image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest - variables: - AMI: "" - INSTANCE: "t3a.large" - SECURITY_GROUP: "" - SUBNET_ID: "" - PROFILE: "default" - AWS_SSH_PRIVATE_KEY: $AWS_SSH_PRIVATE_KEY - before_script: - - aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID - - aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY - - aws configure set region "us-east-2" - - aws configure set aws_profile $PROFILE - - echo $AWS_SSH_PRIVATE_KEY > gitlab-featurebase-dev.pem - - chmod 400 gitlab-featurebase-dev.pem script: - - AMI=$(aws ssm get-parameters --names /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-ebs --query 'Parameters[0].[Value]' --output text --profile $PROFILE) - - SECURITY_GROUP=$(aws ec2 describe-security-groups --filters Name=vpc-id,Values=vpc-03a4ba3d5b7c8f978 Name=group-name,Values=default --query 'SecurityGroups[*].[GroupId]' --output text --profile $PROFILE) - - SUBNET_ID=$(aws ec2 describe-subnets --filters 'Name=vpc-id,Values=vpc-03a4ba3d5b7c8f978' 'Name=availability-zone,Values=us-east-2a' --query 'Subnets[0].SubnetId' --output text --profile $PROFILE) - - aws ec2 run-instances --image-id $AMI --instance-type $INSTANCE --security-group-ids $SECURITY_GROUP --subnet-id $SUBNET_ID --key-name gitlab-featurebase-dev --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=linux-amd64-node}]' --profile $PROFILE --user-data file://./qa/scripts/cloud-init.sh --iam-instance-profile Name=featurebase-dev-ssm > config.json - - INSTANCE_ID=$(jq '.Instances | .[] |.InstanceId' config.json | tr -d '"') - - echo $INSTANCE_ID > $INSTANCE_ID_FILE - needs: - - job: build for linux amd64 - artifacts: - paths: - - $INSTANCE_ID_FILE - needs: - - job: build for linux amd64 - -# scp featurebase binary, config and service file, and configure featurebase -initiate featurebase linux amd64 in node: - stage: integration - image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest - variables: - IP: "" - PROFILE: "default" - AWS_SSH_PRIVATE_KEY: $AWS_SSH_PRIVATE_KEY - INSTANCE_ID: "" - before_script: - - aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID - - aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY - - aws configure set region "us-east-2" - - aws configure set aws_profile $PROFILE - - echo $AWS_SSH_PRIVATE_KEY > gitlab-featurebase-dev.pem - - chmod 400 gitlab-featurebase-dev.pem - - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )' - - eval `ssh-agent -s` - - mkdir -p ~/.ssh - - echo "$AWS_SSH_PRIVATE_KEY" | ssh-add - - - chmod 700 /root/.ssh - - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config' - - INSTANCE_ID=$(cat $INSTANCE_ID_FILE) - script: - - for i in {0..24}; do IP=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --filters 'Name=instance-state-name, Values=running' --query 'Reservations[*].Instances[*].PublicIpAddress' --output text --profile $PROFILE); if [ -n "$IP" ]; then break; fi; sleep 5; done - - scp -o StrictHostKeyChecking=no -i gitlab-featurebase-dev.pem featurebase_linux_amd64 ./qa/scripts/featurebase.conf ./qa/scripts/featurebase.service ec2-user@$IP:. - - aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids $INSTANCE_ID --cli-input-json file://./qa/scripts/configureFeatureBase.json --profile $PROFILE --region us-east-2 - needs: - - job: build for linux amd64 - - job: deploy node for linux amd64 - -# terminate EC2 instance -terminate node for linux amd64: - stage: integration - image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest - variables: - INSTANCE_ID: "" - before_script: - - aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID - - aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY - - aws configure set region "us-east-2" - - INSTANCE_ID=$(cat $INSTANCE_ID_FILE) - script: - - aws ec2 terminate-instances --instance-ids $INSTANCE_ID - needs: - - job: initiate featurebase linux amd64 in node - when: always + - ./qa/scripts/deployNode.sh diff --git a/qa/scripts/deployNode.sh b/qa/scripts/deployNode.sh new file mode 100755 index 000000000..42af61d20 --- /dev/null +++ b/qa/scripts/deployNode.sh @@ -0,0 +1,96 @@ +#! /bin/bash + +# To run script: ./deployNode.sh AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SSH_PRIVATE_KEY + +function configure_env() { + aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID + aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY + aws configure set region $REGION + aws configure set aws_profile $PROFILE + echo $AWS_SSH_PRIVATE_KEY > gitlab-featurebase-dev.pem + chmod 400 gitlab-featurebase-dev.pem + + # set up ssh permissions + 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )' + eval `ssh-agent -s` + mkdir -p ~/.ssh + echo "$AWS_SSH_PRIVATE_KEY" | ssh-add - + chmod 700 /root/.ssh + + # install jq + apt update && apt -y install jq +} + +function deploy_node() { + # get AMI, security group and subnet ID + AMI=$(aws ssm get-parameters --names /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-ebs --query 'Parameters[0].[Value]' --output text --profile $PROFILE) + SECURITY_GROUP=$(aws ec2 describe-security-groups --filters Name=vpc-id,Values=vpc-03a4ba3d5b7c8f978 Name=group-name,Values=default --query 'SecurityGroups[*].[GroupId]' --output text --profile $PROFILE) + SUBNET_ID=$(aws ec2 describe-subnets --filters 'Name=vpc-id,Values=vpc-03a4ba3d5b7c8f978' 'Name=availability-zone,Values=us-east-2a' --query 'Subnets[0].SubnetId' --output text --profile $PROFILE) + + # launch EC2 instance and get instance ID + aws ec2 run-instances --image-id $AMI --instance-type $INSTANCE --security-group-ids $SECURITY_GROUP --subnet-id $SUBNET_ID --key-name gitlab-featurebase-dev --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=linux-amd64-node}]' --profile $PROFILE --user-data file://./qa/scripts/cloud-init.sh --iam-instance-profile Name=featurebase-dev-ssm > config.json + INSTANCE_ID=$(jq '.Instances | .[] |.InstanceId' config.json | tr -d '"') +} + +function initialize_featurebase() { + # get IP for node + for i in {0..24} + do + IP=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --filters 'Name=instance-state-name, Values=running' --query 'Reservations[*].Instances[*].PublicIpAddress' --output text --profile $PROFILE) + if [ -n "$IP" ]; then + break + fi + + sleep 5 + done + } + + # copy featurebase binary and files to ec2 instance + scp -o StrictHostKeyChecking=no -i gitlab-featurebase-dev.pem featurebase_linux_amd64 ./qa/scripts/featurebase.conf ./qa/scripts/featurebase.service ec2-user@$IP:. + + # execute script to configure featurebase on the EC2 node + aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids $INSTANCE_ID --cli-input-json file://./qa/scripts/configureFeatureBase.json --profile $PROFILE --region $REGION +} + +function terminate_node() { + aws ec2 terminate-instances --instance-ids $INSTANCE_ID +} + +# Pass variables to shell script +AWS_ACCESS_KEY_ID=$1 +shift + +AWS_SECRET_ACCESS_KEY=$1 +shift + +AWS_SSH_PRIVATE_KEY=$1 +shift + +# set some variables +PROFILE="default" +INSTANCE="t3a.large" +REGION="us-east-2" + +# set up environment variables for aws, ssh +# and install needed packages +configure_env +if [ $? > 0 ]; then + exit 1 +fi + +# get AMI, security group and subnet for EC2 instance, +# launch instance, save instance Id and run cloud-init to set up node env +deploy_node +if [ $? > 0 ]; then + exit 1 +fi + +# Get IP for instance, scp featurebase binary, config and service files; +# set up featurebase config in node +initialize_featurebase +if [ $? > 0 ]; then + terminate_node + exit 1 +else + terminate_node +fi \ No newline at end of file From 97841608e01dee30b8d17fe9da1e32f277ca0835 Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 15:26:42 -0600 Subject: [PATCH 05/28] switched stages to make testing faster --- .gitlab/.gitlab-ci.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.gitlab/.gitlab-ci.yml b/.gitlab/.gitlab-ci.yml index 656e4e4d5..cf422fab5 100644 --- a/.gitlab/.gitlab-ci.yml +++ b/.gitlab/.gitlab-ci.yml @@ -14,11 +14,10 @@ variables: GOVERSION: "1.16.9" stages: - - integration - lint - test - build - + - integration #before_script: #- echo "before_script" @@ -115,7 +114,7 @@ upload to sonarcloud: - job: run jest tests build for linux amd64: - stage: integration + stage: lint image: golang:1.16.10 script: - rm -r lattice @@ -199,7 +198,7 @@ build container fb: # deploy EC2 instance and save instance ID to a text file deploy node for linux amd64: - stage: integration + stage: lint image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest script: - ./qa/scripts/deployNode.sh From aac3b0768c6f2c1eaf0fc4e7dcd81b5c2c4e57be Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 15:32:22 -0600 Subject: [PATCH 06/28] fixed syntax error --- qa/scripts/deployNode.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/qa/scripts/deployNode.sh b/qa/scripts/deployNode.sh index 42af61d20..4ffc4720c 100755 --- a/qa/scripts/deployNode.sh +++ b/qa/scripts/deployNode.sh @@ -43,7 +43,6 @@ function initialize_featurebase() { sleep 5 done - } # copy featurebase binary and files to ec2 instance scp -o StrictHostKeyChecking=no -i gitlab-featurebase-dev.pem featurebase_linux_amd64 ./qa/scripts/featurebase.conf ./qa/scripts/featurebase.service ec2-user@$IP:. From 53766f47ca6dfdd97aa5f1eb5e8997d12c981a19 Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 15:38:09 -0600 Subject: [PATCH 07/28] fixed jobs dependencies and added args --- .gitlab/.gitlab-ci.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.gitlab/.gitlab-ci.yml b/.gitlab/.gitlab-ci.yml index cf422fab5..eb4f6b374 100644 --- a/.gitlab/.gitlab-ci.yml +++ b/.gitlab/.gitlab-ci.yml @@ -201,4 +201,6 @@ deploy node for linux amd64: stage: lint image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest script: - - ./qa/scripts/deployNode.sh + - ./qa/scripts/deployNode.sh $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY $AWS_SSH_PRIVATE_KEY + needs: + - job: build for linux amd64 \ No newline at end of file From dbd1e611d0a7bf901bd2d6f2cdea6df982133d86 Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 15:42:12 -0600 Subject: [PATCH 08/28] changed jobs order --- .gitlab/.gitlab-ci.yml | 4 +--- qa/scripts/deployNode.sh | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/.gitlab/.gitlab-ci.yml b/.gitlab/.gitlab-ci.yml index eb4f6b374..6390da8ad 100644 --- a/.gitlab/.gitlab-ci.yml +++ b/.gitlab/.gitlab-ci.yml @@ -114,7 +114,7 @@ upload to sonarcloud: - job: run jest tests build for linux amd64: - stage: lint + stage: build image: golang:1.16.10 script: - rm -r lattice @@ -202,5 +202,3 @@ deploy node for linux amd64: image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest script: - ./qa/scripts/deployNode.sh $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY $AWS_SSH_PRIVATE_KEY - needs: - - job: build for linux amd64 \ No newline at end of file diff --git a/qa/scripts/deployNode.sh b/qa/scripts/deployNode.sh index 4ffc4720c..d790d3e12 100755 --- a/qa/scripts/deployNode.sh +++ b/qa/scripts/deployNode.sh @@ -1,4 +1,4 @@ -#! /bin/bash +#!/bin/bash # To run script: ./deployNode.sh AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SSH_PRIVATE_KEY From a6bc10dec9fb4d2c1338b587701250d47483dad3 Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 15:50:43 -0600 Subject: [PATCH 09/28] removed single quotes --- qa/scripts/deployNode.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qa/scripts/deployNode.sh b/qa/scripts/deployNode.sh index d790d3e12..6455c8ea1 100755 --- a/qa/scripts/deployNode.sh +++ b/qa/scripts/deployNode.sh @@ -11,7 +11,7 @@ function configure_env() { chmod 400 gitlab-featurebase-dev.pem # set up ssh permissions - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )' + which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y ) eval `ssh-agent -s` mkdir -p ~/.ssh echo "$AWS_SSH_PRIVATE_KEY" | ssh-add - From cceb173d5d08daf4a75c60d0a6c27ed8e7843b24 Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 15:55:36 -0600 Subject: [PATCH 10/28] added before script commands --- .gitlab/.gitlab-ci.yml | 3 +++ qa/scripts/deployNode.sh | 6 +----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.gitlab/.gitlab-ci.yml b/.gitlab/.gitlab-ci.yml index 6390da8ad..b72fc4d35 100644 --- a/.gitlab/.gitlab-ci.yml +++ b/.gitlab/.gitlab-ci.yml @@ -200,5 +200,8 @@ build container fb: deploy node for linux amd64: stage: lint image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest + before_script: + - apt update && apt -y install jq + - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )' script: - ./qa/scripts/deployNode.sh $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY $AWS_SSH_PRIVATE_KEY diff --git a/qa/scripts/deployNode.sh b/qa/scripts/deployNode.sh index 6455c8ea1..7ba33a516 100755 --- a/qa/scripts/deployNode.sh +++ b/qa/scripts/deployNode.sh @@ -11,14 +11,10 @@ function configure_env() { chmod 400 gitlab-featurebase-dev.pem # set up ssh permissions - which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y ) eval `ssh-agent -s` mkdir -p ~/.ssh - echo "$AWS_SSH_PRIVATE_KEY" | ssh-add - + echo $AWS_SSH_PRIVATE_KEY | ssh-add - chmod 700 /root/.ssh - - # install jq - apt update && apt -y install jq } function deploy_node() { From 53d7d6b91c2bfbec713a42186f59b3f5b5d91b3b Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 16:04:29 -0600 Subject: [PATCH 11/28] fix for ssh-add error --- .gitlab/.gitlab-ci.yml | 3 --- qa/scripts/deployNode.sh | 7 ++++++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/.gitlab/.gitlab-ci.yml b/.gitlab/.gitlab-ci.yml index b72fc4d35..6390da8ad 100644 --- a/.gitlab/.gitlab-ci.yml +++ b/.gitlab/.gitlab-ci.yml @@ -200,8 +200,5 @@ build container fb: deploy node for linux amd64: stage: lint image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest - before_script: - - apt update && apt -y install jq - - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )' script: - ./qa/scripts/deployNode.sh $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY $AWS_SSH_PRIVATE_KEY diff --git a/qa/scripts/deployNode.sh b/qa/scripts/deployNode.sh index 7ba33a516..b2ad98313 100755 --- a/qa/scripts/deployNode.sh +++ b/qa/scripts/deployNode.sh @@ -11,10 +11,15 @@ function configure_env() { chmod 400 gitlab-featurebase-dev.pem # set up ssh permissions + which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y ) eval `ssh-agent -s` mkdir -p ~/.ssh - echo $AWS_SSH_PRIVATE_KEY | ssh-add - + echo "${AWS_SSH_PRIVATE_KEY}" | ssh-add - chmod 700 /root/.ssh + + # install jq + apt update && apt -y install jq + } function deploy_node() { From 184b93555093444cb3eeb40c306d166dd7aef9fb Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 16:07:22 -0600 Subject: [PATCH 12/28] added print statement --- qa/scripts/deployNode.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/qa/scripts/deployNode.sh b/qa/scripts/deployNode.sh index b2ad98313..5c0694aba 100755 --- a/qa/scripts/deployNode.sh +++ b/qa/scripts/deployNode.sh @@ -14,7 +14,8 @@ function configure_env() { which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y ) eval `ssh-agent -s` mkdir -p ~/.ssh - echo "${AWS_SSH_PRIVATE_KEY}" | ssh-add - + echo "$AWS_SSH_PRIVATE_KEY" + echo "$AWS_SSH_PRIVATE_KEY" | ssh-add - chmod 700 /root/.ssh # install jq From 8a77da0db9162de8f07143fdf7a3cbc075bc0d71 Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 16:14:21 -0600 Subject: [PATCH 13/28] removed ssh keys from shell script --- .gitlab/.gitlab-ci.yml | 10 ++++++++++ qa/scripts/deployNode.sh | 14 -------------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/.gitlab/.gitlab-ci.yml b/.gitlab/.gitlab-ci.yml index 6390da8ad..37506c709 100644 --- a/.gitlab/.gitlab-ci.yml +++ b/.gitlab/.gitlab-ci.yml @@ -200,5 +200,15 @@ build container fb: deploy node for linux amd64: stage: lint image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest + before_script: + - echo $AWS_SSH_PRIVATE_KEY > gitlab-featurebase-dev.pem + - chmod 400 gitlab-featurebase-dev.pem + - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )' + - eval `ssh-agent -s` + - mkdir -p ~/.ssh && + - echo "$AWS_SSH_PRIVATE_KEY" | ssh-add - + - chmod 700 /root/.ssh + - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config' + - apt update && apt -y install jq script: - ./qa/scripts/deployNode.sh $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY $AWS_SSH_PRIVATE_KEY diff --git a/qa/scripts/deployNode.sh b/qa/scripts/deployNode.sh index 5c0694aba..4d89805a2 100755 --- a/qa/scripts/deployNode.sh +++ b/qa/scripts/deployNode.sh @@ -7,20 +7,6 @@ function configure_env() { aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY aws configure set region $REGION aws configure set aws_profile $PROFILE - echo $AWS_SSH_PRIVATE_KEY > gitlab-featurebase-dev.pem - chmod 400 gitlab-featurebase-dev.pem - - # set up ssh permissions - which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y ) - eval `ssh-agent -s` - mkdir -p ~/.ssh - echo "$AWS_SSH_PRIVATE_KEY" - echo "$AWS_SSH_PRIVATE_KEY" | ssh-add - - chmod 700 /root/.ssh - - # install jq - apt update && apt -y install jq - } function deploy_node() { From d781dfb29b4d9754182748f90c289c053b1d825f Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 16:18:14 -0600 Subject: [PATCH 14/28] remove error handling to debug --- qa/scripts/deployNode.sh | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/qa/scripts/deployNode.sh b/qa/scripts/deployNode.sh index 4d89805a2..a850e8403 100755 --- a/qa/scripts/deployNode.sh +++ b/qa/scripts/deployNode.sh @@ -53,6 +53,8 @@ shift AWS_SSH_PRIVATE_KEY=$1 shift +echo $AWS_ACCESS_KEY_ID, $AWS_ACCESS_KEY_ID, $AWS_SSH_PRIVATE_KEY + # set some variables PROFILE="default" INSTANCE="t3a.large" @@ -61,23 +63,23 @@ REGION="us-east-2" # set up environment variables for aws, ssh # and install needed packages configure_env -if [ $? > 0 ]; then - exit 1 -fi +# if [ $? > 0 ]; then +# exit 1 +# fi # get AMI, security group and subnet for EC2 instance, # launch instance, save instance Id and run cloud-init to set up node env deploy_node -if [ $? > 0 ]; then - exit 1 -fi +# if [ $? > 0 ]; then +# exit 1 +# fi # Get IP for instance, scp featurebase binary, config and service files; # set up featurebase config in node initialize_featurebase -if [ $? > 0 ]; then - terminate_node - exit 1 -else - terminate_node -fi \ No newline at end of file +# if [ $? > 0 ]; then +# terminate_node +# exit 1 +# else +terminate_node +# fi \ No newline at end of file From 0030e759da0963274e99c6c778eeb7bce1ea6b76 Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 16:24:56 -0600 Subject: [PATCH 15/28] removed aws config from shell script --- .gitlab/.gitlab-ci.yml | 12 ++++++++++-- qa/scripts/deployNode.sh | 28 +++------------------------- 2 files changed, 13 insertions(+), 27 deletions(-) diff --git a/.gitlab/.gitlab-ci.yml b/.gitlab/.gitlab-ci.yml index 37506c709..f568209b8 100644 --- a/.gitlab/.gitlab-ci.yml +++ b/.gitlab/.gitlab-ci.yml @@ -200,15 +200,23 @@ build container fb: deploy node for linux amd64: stage: lint image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest + variable: + PROFILE: "default" + AWS_SSH_PRIVATE_KEY: $AWS_SSH_PRIVATE_KEY before_script: + - aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID + - aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY + - aws configure set region "us-east-2" + - aws configure set aws_profile $PROFILE + - echo $AWS_SSH_PRIVATE_KEY > gitlab-featurebase-dev.pem - echo $AWS_SSH_PRIVATE_KEY > gitlab-featurebase-dev.pem - chmod 400 gitlab-featurebase-dev.pem - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )' - eval `ssh-agent -s` - - mkdir -p ~/.ssh && + - mkdir -p ~/.ssh - echo "$AWS_SSH_PRIVATE_KEY" | ssh-add - - chmod 700 /root/.ssh - '[[ -f /.dockerenv ]] && echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > ~/.ssh/config' - apt update && apt -y install jq script: - - ./qa/scripts/deployNode.sh $AWS_ACCESS_KEY_ID $AWS_SECRET_ACCESS_KEY $AWS_SSH_PRIVATE_KEY + - ./qa/scripts/deployNode.sh $PROFILE diff --git a/qa/scripts/deployNode.sh b/qa/scripts/deployNode.sh index a850e8403..3f3d4823b 100755 --- a/qa/scripts/deployNode.sh +++ b/qa/scripts/deployNode.sh @@ -1,13 +1,6 @@ #!/bin/bash -# To run script: ./deployNode.sh AWS_ACCESS_KEY_ID AWS_SECRET_ACCESS_KEY AWS_SSH_PRIVATE_KEY - -function configure_env() { - aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID - aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY - aws configure set region $REGION - aws configure set aws_profile $PROFILE -} +# To run script: ./deployNode.sh $PROFILE function deploy_node() { # get AMI, security group and subnet ID @@ -43,30 +36,15 @@ function terminate_node() { aws ec2 terminate-instances --instance-ids $INSTANCE_ID } -# Pass variables to shell script -AWS_ACCESS_KEY_ID=$1 -shift +# Pass variables to shell script -AWS_SECRET_ACCESS_KEY=$1 -shift - -AWS_SSH_PRIVATE_KEY=$1 +PROFILE=$1 shift -echo $AWS_ACCESS_KEY_ID, $AWS_ACCESS_KEY_ID, $AWS_SSH_PRIVATE_KEY - # set some variables -PROFILE="default" INSTANCE="t3a.large" REGION="us-east-2" -# set up environment variables for aws, ssh -# and install needed packages -configure_env -# if [ $? > 0 ]; then -# exit 1 -# fi - # get AMI, security group and subnet for EC2 instance, # launch instance, save instance Id and run cloud-init to set up node env deploy_node From 2de7d2c885e87679b091e63b4ace72ccd17852c4 Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 16:26:09 -0600 Subject: [PATCH 16/28] fixed yaml syntax error --- .gitlab/.gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab/.gitlab-ci.yml b/.gitlab/.gitlab-ci.yml index f568209b8..3fe3e86aa 100644 --- a/.gitlab/.gitlab-ci.yml +++ b/.gitlab/.gitlab-ci.yml @@ -200,7 +200,7 @@ build container fb: deploy node for linux amd64: stage: lint image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest - variable: + variables: PROFILE: "default" AWS_SSH_PRIVATE_KEY: $AWS_SSH_PRIVATE_KEY before_script: From f03720f0a3fb234ffa895014a2c0ea978f7f2da4 Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 16:33:32 -0600 Subject: [PATCH 17/28] error handling --- qa/scripts/deployNode.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/qa/scripts/deployNode.sh b/qa/scripts/deployNode.sh index 3f3d4823b..3511c78b7 100755 --- a/qa/scripts/deployNode.sh +++ b/qa/scripts/deployNode.sh @@ -48,16 +48,16 @@ REGION="us-east-2" # get AMI, security group and subnet for EC2 instance, # launch instance, save instance Id and run cloud-init to set up node env deploy_node -# if [ $? > 0 ]; then -# exit 1 -# fi +if [ $? > 0 ]; then + exit 1 +fi # Get IP for instance, scp featurebase binary, config and service files; # set up featurebase config in node initialize_featurebase -# if [ $? > 0 ]; then -# terminate_node -# exit 1 -# else -terminate_node -# fi \ No newline at end of file +if [ $? > 0 ]; then + terminate_node + exit 1 +else + terminate_node +fi \ No newline at end of file From 88c89749afbf2ce7ac8cca0bcc596c7b82742123 Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 16:37:11 -0600 Subject: [PATCH 18/28] updated job's stage --- .gitlab/.gitlab-ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.gitlab/.gitlab-ci.yml b/.gitlab/.gitlab-ci.yml index 3fe3e86aa..0568256ed 100644 --- a/.gitlab/.gitlab-ci.yml +++ b/.gitlab/.gitlab-ci.yml @@ -198,7 +198,7 @@ build container fb: # deploy EC2 instance and save instance ID to a text file deploy node for linux amd64: - stage: lint + stage: integration image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest variables: PROFILE: "default" From 612e11887f8d58da308ac18152a23c93e15b4ecb Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 16:41:35 -0600 Subject: [PATCH 19/28] added dependency --- .gitlab/.gitlab-ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitlab/.gitlab-ci.yml b/.gitlab/.gitlab-ci.yml index 0568256ed..18e7d76a2 100644 --- a/.gitlab/.gitlab-ci.yml +++ b/.gitlab/.gitlab-ci.yml @@ -220,3 +220,5 @@ deploy node for linux amd64: - apt update && apt -y install jq script: - ./qa/scripts/deployNode.sh $PROFILE + needs: + - job: build for linux amd64 From d13eef4c4b4adf6d79bd30c791ffa742901fd39b Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 17:09:35 -0600 Subject: [PATCH 20/28] echo errors --- .gitlab/.gitlab-ci.yml | 3 +-- qa/scripts/deployNode.sh | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.gitlab/.gitlab-ci.yml b/.gitlab/.gitlab-ci.yml index 18e7d76a2..f2dbeee30 100644 --- a/.gitlab/.gitlab-ci.yml +++ b/.gitlab/.gitlab-ci.yml @@ -198,7 +198,7 @@ build container fb: # deploy EC2 instance and save instance ID to a text file deploy node for linux amd64: - stage: integration + stage: lint image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest variables: PROFILE: "default" @@ -209,7 +209,6 @@ deploy node for linux amd64: - aws configure set region "us-east-2" - aws configure set aws_profile $PROFILE - echo $AWS_SSH_PRIVATE_KEY > gitlab-featurebase-dev.pem - - echo $AWS_SSH_PRIVATE_KEY > gitlab-featurebase-dev.pem - chmod 400 gitlab-featurebase-dev.pem - 'which ssh-agent || ( apt-get update -y && apt-get install openssh-client -y )' - eval `ssh-agent -s` diff --git a/qa/scripts/deployNode.sh b/qa/scripts/deployNode.sh index 3511c78b7..816f87a48 100755 --- a/qa/scripts/deployNode.sh +++ b/qa/scripts/deployNode.sh @@ -49,6 +49,7 @@ REGION="us-east-2" # launch instance, save instance Id and run cloud-init to set up node env deploy_node if [ $? > 0 ]; then + echo "Error: " >&2 exit 1 fi @@ -57,7 +58,9 @@ fi initialize_featurebase if [ $? > 0 ]; then terminate_node + echo "Error: " >&2 exit 1 else terminate_node + exit 0 fi \ No newline at end of file From b243f4b8a3c623a67d9df6121bfdca29467f00f7 Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 17:10:13 -0600 Subject: [PATCH 21/28] fix yaml error --- .gitlab/.gitlab-ci.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.gitlab/.gitlab-ci.yml b/.gitlab/.gitlab-ci.yml index f2dbeee30..19c984175 100644 --- a/.gitlab/.gitlab-ci.yml +++ b/.gitlab/.gitlab-ci.yml @@ -219,5 +219,5 @@ deploy node for linux amd64: - apt update && apt -y install jq script: - ./qa/scripts/deployNode.sh $PROFILE - needs: - - job: build for linux amd64 + # needs: + # - job: build for linux amd64 From afb96f4a9bc727e63f27e1072e51f05ab91bf63d Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 17:17:13 -0600 Subject: [PATCH 22/28] pass error back to gitlab runner --- qa/scripts/deployNode.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qa/scripts/deployNode.sh b/qa/scripts/deployNode.sh index 816f87a48..60a007d93 100755 --- a/qa/scripts/deployNode.sh +++ b/qa/scripts/deployNode.sh @@ -58,7 +58,7 @@ fi initialize_featurebase if [ $? > 0 ]; then terminate_node - echo "Error: " >&2 + echo "Error: " 1>&2 exit 1 else terminate_node From 42b6c2b351bc50a5a46c696e52d08a2d3d7b5443 Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 17:25:10 -0600 Subject: [PATCH 23/28] updated syntax --- qa/scripts/deployNode.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/qa/scripts/deployNode.sh b/qa/scripts/deployNode.sh index 60a007d93..ac3364472 100755 --- a/qa/scripts/deployNode.sh +++ b/qa/scripts/deployNode.sh @@ -11,6 +11,7 @@ function deploy_node() { # launch EC2 instance and get instance ID aws ec2 run-instances --image-id $AMI --instance-type $INSTANCE --security-group-ids $SECURITY_GROUP --subnet-id $SUBNET_ID --key-name gitlab-featurebase-dev --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=linux-amd64-node}]' --profile $PROFILE --user-data file://./qa/scripts/cloud-init.sh --iam-instance-profile Name=featurebase-dev-ssm > config.json INSTANCE_ID=$(jq '.Instances | .[] |.InstanceId' config.json | tr -d '"') + echo "Instance ID: " $INSTANCE_ID } function initialize_featurebase() { @@ -24,6 +25,7 @@ function initialize_featurebase() { sleep 5 done + echo "IP: " $IP # copy featurebase binary and files to ec2 instance scp -o StrictHostKeyChecking=no -i gitlab-featurebase-dev.pem featurebase_linux_amd64 ./qa/scripts/featurebase.conf ./qa/scripts/featurebase.service ec2-user@$IP:. @@ -49,7 +51,7 @@ REGION="us-east-2" # launch instance, save instance Id and run cloud-init to set up node env deploy_node if [ $? > 0 ]; then - echo "Error: " >&2 + echo "Error: " 1>&2 exit 1 fi @@ -57,8 +59,8 @@ fi # set up featurebase config in node initialize_featurebase if [ $? > 0 ]; then - terminate_node echo "Error: " 1>&2 + terminate_node exit 1 else terminate_node From 001678386f26ca2b40fcc760a97a6fc49a2362c5 Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 17:27:57 -0600 Subject: [PATCH 24/28] define ip var --- qa/scripts/deployNode.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/qa/scripts/deployNode.sh b/qa/scripts/deployNode.sh index ac3364472..9bc064beb 100755 --- a/qa/scripts/deployNode.sh +++ b/qa/scripts/deployNode.sh @@ -16,6 +16,7 @@ function deploy_node() { function initialize_featurebase() { # get IP for node + IP="" for i in {0..24} do IP=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --filters 'Name=instance-state-name, Values=running' --query 'Reservations[*].Instances[*].PublicIpAddress' --output text --profile $PROFILE) From 6172f98eaba4d2025dd6a0489b10d1d2bbae0b1c Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 18:32:09 -0600 Subject: [PATCH 25/28] test failed condition --- qa/scripts/deployNode.sh | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/qa/scripts/deployNode.sh b/qa/scripts/deployNode.sh index 9bc064beb..a3b20f6b3 100755 --- a/qa/scripts/deployNode.sh +++ b/qa/scripts/deployNode.sh @@ -10,13 +10,12 @@ function deploy_node() { # launch EC2 instance and get instance ID aws ec2 run-instances --image-id $AMI --instance-type $INSTANCE --security-group-ids $SECURITY_GROUP --subnet-id $SUBNET_ID --key-name gitlab-featurebase-dev --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=linux-amd64-node}]' --profile $PROFILE --user-data file://./qa/scripts/cloud-init.sh --iam-instance-profile Name=featurebase-dev-ssm > config.json - INSTANCE_ID=$(jq '.Instances | .[] |.InstanceId' config.json | tr -d '"') + INSTANCE_ID=$(jq '.Instances | .[0] |.InstanceId' config.json | tr -d '"') echo "Instance ID: " $INSTANCE_ID } function initialize_featurebase() { # get IP for node - IP="" for i in {0..24} do IP=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --filters 'Name=instance-state-name, Values=running' --query 'Reservations[*].Instances[*].PublicIpAddress' --output text --profile $PROFILE) @@ -26,7 +25,8 @@ function initialize_featurebase() { sleep 5 done - echo "IP: " $IP + + sleep 60 # to allow enough time for node to be ready for use # copy featurebase binary and files to ec2 instance scp -o StrictHostKeyChecking=no -i gitlab-featurebase-dev.pem featurebase_linux_amd64 ./qa/scripts/featurebase.conf ./qa/scripts/featurebase.service ec2-user@$IP:. @@ -51,16 +51,14 @@ REGION="us-east-2" # get AMI, security group and subnet for EC2 instance, # launch instance, save instance Id and run cloud-init to set up node env deploy_node -if [ $? > 0 ]; then - echo "Error: " 1>&2 +if [[ $? > 0 ]]; then exit 1 fi # Get IP for instance, scp featurebase binary, config and service files; # set up featurebase config in node initialize_featurebase -if [ $? > 0 ]; then - echo "Error: " 1>&2 +if [[ $? > 0 ]]; then terminate_node exit 1 else From 0e2d71c3030fe31132b339f4162d08e31fc36054 Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 18:48:06 -0600 Subject: [PATCH 26/28] added error handling --- qa/scripts/deployNode.sh | 56 ++++++++++++++++++++++++++++++---------- 1 file changed, 42 insertions(+), 14 deletions(-) diff --git a/qa/scripts/deployNode.sh b/qa/scripts/deployNode.sh index a3b20f6b3..2074d5400 100755 --- a/qa/scripts/deployNode.sh +++ b/qa/scripts/deployNode.sh @@ -5,13 +5,32 @@ function deploy_node() { # get AMI, security group and subnet ID AMI=$(aws ssm get-parameters --names /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-ebs --query 'Parameters[0].[Value]' --output text --profile $PROFILE) + if [[ $? > 0 ]]; then + echo "aws session manager find ami failed" + exit 1 + fi + SECURITY_GROUP=$(aws ec2 describe-security-groups --filters Name=vpc-id,Values=vpc-03a4ba3d5b7c8f978 Name=group-name,Values=default --query 'SecurityGroups[*].[GroupId]' --output text --profile $PROFILE) + if [[ $? > 0 ]]; then + echo "aws session manager find security group failed" + exit 1 + fi + SUBNET_ID=$(aws ec2 describe-subnets --filters 'Name=vpc-id,Values=vpc-03a4ba3d5b7c8f978' 'Name=availability-zone,Values=us-east-2a' --query 'Subnets[0].SubnetId' --output text --profile $PROFILE) + if [[ $? > 0 ]]; then + echo "aws session manager find subnet ID failed" + exit 1 + fi # launch EC2 instance and get instance ID aws ec2 run-instances --image-id $AMI --instance-type $INSTANCE --security-group-ids $SECURITY_GROUP --subnet-id $SUBNET_ID --key-name gitlab-featurebase-dev --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=linux-amd64-node}]' --profile $PROFILE --user-data file://./qa/scripts/cloud-init.sh --iam-instance-profile Name=featurebase-dev-ssm > config.json + if [[ $? > 0 ]]; then + echo "Launching EC2 instance failed" + exit 1 + fi + INSTANCE_ID=$(jq '.Instances | .[0] |.InstanceId' config.json | tr -d '"') - echo "Instance ID: " $INSTANCE_ID + echo "Launched EC2 instance with Instance ID: " $INSTANCE_ID } function initialize_featurebase() { @@ -19,10 +38,17 @@ function initialize_featurebase() { for i in {0..24} do IP=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --filters 'Name=instance-state-name, Values=running' --query 'Reservations[*].Instances[*].PublicIpAddress' --output text --profile $PROFILE) - if [ -n "$IP" ]; then + if [ -n "$IP" ]; then + echo "Public IP for EC2 instance: " $IP break fi + if [[ $? > 0 ]]; then + echo "aws cli describe-instances command failed" + terminate_node + exit 1 + fi + sleep 5 done @@ -30,17 +56,26 @@ function initialize_featurebase() { # copy featurebase binary and files to ec2 instance scp -o StrictHostKeyChecking=no -i gitlab-featurebase-dev.pem featurebase_linux_amd64 ./qa/scripts/featurebase.conf ./qa/scripts/featurebase.service ec2-user@$IP:. + if [[ $? > 0 ]]; then + echo "scp of featurebase binary, service and config files to EC2 instance failed" + terminate_node + exit 1 + fi # execute script to configure featurebase on the EC2 node aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids $INSTANCE_ID --cli-input-json file://./qa/scripts/configureFeatureBase.json --profile $PROFILE --region $REGION + if [[ $? > 0 ]]; then + echo "aws cli session manager command failed" + terminate_node + exit 1 + fi } function terminate_node() { - aws ec2 terminate-instances --instance-ids $INSTANCE_ID + aws ec2 terminate-instances --instance-ids $INSTANCE_ID --profile $PROFILE } # Pass variables to shell script - PROFILE=$1 shift @@ -51,17 +86,10 @@ REGION="us-east-2" # get AMI, security group and subnet for EC2 instance, # launch instance, save instance Id and run cloud-init to set up node env deploy_node -if [[ $? > 0 ]]; then - exit 1 -fi # Get IP for instance, scp featurebase binary, config and service files; # set up featurebase config in node initialize_featurebase -if [[ $? > 0 ]]; then - terminate_node - exit 1 -else - terminate_node - exit 0 -fi \ No newline at end of file + +# terminate node +terminate_node From 02b0f4ffd66bf3f7da3d68f0d41775f91e7d02d9 Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 18:50:47 -0600 Subject: [PATCH 27/28] test standard condition --- .gitlab/.gitlab-ci.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.gitlab/.gitlab-ci.yml b/.gitlab/.gitlab-ci.yml index 19c984175..f75bf268f 100644 --- a/.gitlab/.gitlab-ci.yml +++ b/.gitlab/.gitlab-ci.yml @@ -198,7 +198,7 @@ build container fb: # deploy EC2 instance and save instance ID to a text file deploy node for linux amd64: - stage: lint + stage: integration image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest variables: PROFILE: "default" @@ -219,5 +219,5 @@ deploy node for linux amd64: - apt update && apt -y install jq script: - ./qa/scripts/deployNode.sh $PROFILE - # needs: - # - job: build for linux amd64 + needs: + - job: build for linux amd64 From 65c4fc9cdb88b28a5a4f4008a9863fae7d87f5d0 Mon Sep 17 00:00:00 2001 From: Souhaila Noor Date: Tue, 23 Nov 2021 20:28:14 -0600 Subject: [PATCH 28/28] updated error messages --- .gitlab/.gitlab-ci.yml | 2 +- qa/scripts/deployNode.sh | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.gitlab/.gitlab-ci.yml b/.gitlab/.gitlab-ci.yml index f75bf268f..f0a523e1a 100644 --- a/.gitlab/.gitlab-ci.yml +++ b/.gitlab/.gitlab-ci.yml @@ -196,7 +196,7 @@ build container fb: - docker push $tag - echo Created docker featurebase image with tag "$tag" -# deploy EC2 instance and save instance ID to a text file +# deploy EC2 instance, configure and run featurebase deploy node for linux amd64: stage: integration image: registry.gitlab.com/gitlab-org/cloud-deploy/aws-base:latest diff --git a/qa/scripts/deployNode.sh b/qa/scripts/deployNode.sh index 2074d5400..b928a31e7 100755 --- a/qa/scripts/deployNode.sh +++ b/qa/scripts/deployNode.sh @@ -6,31 +6,31 @@ function deploy_node() { # get AMI, security group and subnet ID AMI=$(aws ssm get-parameters --names /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-ebs --query 'Parameters[0].[Value]' --output text --profile $PROFILE) if [[ $? > 0 ]]; then - echo "aws session manager find ami failed" + echo "aws session manager failed to find AMI" exit 1 fi SECURITY_GROUP=$(aws ec2 describe-security-groups --filters Name=vpc-id,Values=vpc-03a4ba3d5b7c8f978 Name=group-name,Values=default --query 'SecurityGroups[*].[GroupId]' --output text --profile $PROFILE) if [[ $? > 0 ]]; then - echo "aws session manager find security group failed" + echo "aws session manager failed to find security group" exit 1 fi SUBNET_ID=$(aws ec2 describe-subnets --filters 'Name=vpc-id,Values=vpc-03a4ba3d5b7c8f978' 'Name=availability-zone,Values=us-east-2a' --query 'Subnets[0].SubnetId' --output text --profile $PROFILE) if [[ $? > 0 ]]; then - echo "aws session manager find subnet ID failed" + echo "aws session manager failed to find subnet ID" exit 1 fi # launch EC2 instance and get instance ID aws ec2 run-instances --image-id $AMI --instance-type $INSTANCE --security-group-ids $SECURITY_GROUP --subnet-id $SUBNET_ID --key-name gitlab-featurebase-dev --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=linux-amd64-node}]' --profile $PROFILE --user-data file://./qa/scripts/cloud-init.sh --iam-instance-profile Name=featurebase-dev-ssm > config.json if [[ $? > 0 ]]; then - echo "Launching EC2 instance failed" + echo "aws run-instances failed to launch a new EC2 instance" exit 1 fi INSTANCE_ID=$(jq '.Instances | .[0] |.InstanceId' config.json | tr -d '"') - echo "Launched EC2 instance with Instance ID: " $INSTANCE_ID + echo "aws run-instances succeeded in launching a new EC2 instance with instance ID: " $INSTANCE_ID } function initialize_featurebase() { @@ -39,12 +39,12 @@ function initialize_featurebase() { do IP=$(aws ec2 describe-instances --instance-ids $INSTANCE_ID --filters 'Name=instance-state-name, Values=running' --query 'Reservations[*].Instances[*].PublicIpAddress' --output text --profile $PROFILE) if [ -n "$IP" ]; then - echo "Public IP for EC2 instance: " $IP + echo "Public IP for EC2 instance found: " $IP break fi if [[ $? > 0 ]]; then - echo "aws cli describe-instances command failed" + echo "aws cli describe-instances command failed to find public IP" terminate_node exit 1 fi @@ -65,7 +65,7 @@ function initialize_featurebase() { # execute script to configure featurebase on the EC2 node aws ssm send-command --document-name "AWS-RunShellScript" --instance-ids $INSTANCE_ID --cli-input-json file://./qa/scripts/configureFeatureBase.json --profile $PROFILE --region $REGION if [[ $? > 0 ]]; then - echo "aws cli session manager command failed" + echo "aws cli session manager send-command failed" terminate_node exit 1 fi