Julian Risch 70ca1e9fc6
Smaller demo instance type (#2564)
This PR changes the instance type of the public Haystack demo from p3.2xlarge to g4dn.2xlarge.
g4dn.2xlarge has 1 GPU, 8 vCPUs, 32 GiB of memory
p3.2xlarge had 1 GPU, 8 vCPUs, 61 GiB of memory
which results in 75% lower costs with g4dn.2xlarge.

I also tried out the even smaller g4dn.xlarge, which has 1 GPU, 4 vCPUs, 16 GiB of memory. However, the memory was not enough to run the demo. I tried out multiple requests at the same time and it worked well with g4dn.2xlarge. Requests are slightly slower as with the more powerful instance type but it's hard to notice.
2022-05-17 12:47:15 +02:00

93 lines
3.6 KiB
YAML

name: Demo
on:
workflow_dispatch:
push:
branches:
- master
paths:
- ".github/workflows/demo**"
env:
AWS_REGION: eu-west-1
STACK_NAME: haystack-demo-production-instance
ENVIRONMENT: production
TEMPLATE_FILE: .github/workflows/demo/ec2-autoscaling-group.yaml
VPC_STACK: haystack-demo-production-vpc
INSTANCE_TYPE: g4dn.2xlarge
permissions:
id-token: write
contents: read
jobs:
deploy:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v2
- name: AWS Authentication
uses: aws-actions/configure-aws-credentials@master
with:
aws-region: ${{ env.AWS_REGION }}
role-to-assume: ${{ secrets.DEMO_AWS_DEPLOY_ROLE }}
- name: Deploy demo
env:
CF_KEY_NAME: ${{ secrets.DEMO_CF_KEY_NAME }}
CF_IMAGE_ID: ${{ secrets.DEMO_CF_IMAGE_ID }}
CF_IAM_INSTANCE_PROFILE: ${{ secrets.DEMO_CF_IAM_INSTANCE_PROFILE }}
run: |
echo -e "\n* Deploying CloudFormation Stack ${STACK_NAME}"
start_ts=$(date +"%s")
# Deploy the CloudFormation stack as a background process
aws cloudformation deploy \
--template-file "${TEMPLATE_FILE}" \
--stack-name ${STACK_NAME} \
--parameter-overrides \
"Environment=${ENVIRONMENT}" \
"VPCStack=${VPC_STACK}" \
"GitRepositoryURL=${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}.git" \
"GitBranchName=${GITHUB_REF_NAME}" \
"GitCommitHash=${{ github.sha }}" \
"InstanceType=${INSTANCE_TYPE}" \
"KeyName=${CF_KEY_NAME}" \
"ImageId=${CF_IMAGE_ID}" \
"IamInstanceProfile=${CF_IAM_INSTANCE_PROFILE}" \
--capabilities CAPABILITY_IAM > /dev/null &
# Save the pid for the background deploy process
deploy_pid=$!
echo -e "\n** Progress of deployment for CloudFormation Stack ${STACK_NAME}"
# Show stack events while the background deploy process is still running
touch stack-events.prev
while kill -0 $deploy_pid 2>/dev/null
do
sleep 2
aws cloudformation describe-stack-events --stack-name ${STACK_NAME} 2>/dev/null \
| jq -r --arg start_ts ${start_ts} '.StackEvents[] | (.Timestamp | sub("(?<x>T\\d+:\\d+:\\d+).*$"; "\(.x)Z") | fromdate) as $dt | select($dt >= ($start_ts|tonumber)) | "\($dt|todateiso8601)\t\(.LogicalResourceId)\t\(.ResourceStatus)\t\(.ResourceStatusReason // "")"' \
| column -t -s $'\t' \
| tac > stack-events.new
# describe-stack-events dumps all the events history but
# we are only interested in printing only the new ones on each iteration
tail -n $(($(wc -l < stack-events.new) - $(wc -l < stack-events.prev))) stack-events.new
mv stack-events.new stack-events.prev
done
LogGroupName=$(aws cloudformation describe-stacks \
--stack-name ${STACK_NAME} \
--query 'Stacks[0].Outputs[?OutputKey==`LogGroupName`].OutputValue' \
--output text)
LogGroupURL="https://${AWS_REGION}.console.aws.amazon.com/cloudwatch/home?region=${AWS_REGION}#logsV2:log-groups/log-group/$(echo ${LogGroupName} | sed 's#/#$252F#g')"
echo -e "\n* EC2 instance CloudWatch logs can be found at ${LogGroupURL}"
# wait will exit whith the same exit code as the background deploy process
# so we pass or fail the CI job based on the result of the deployment
wait $deploy_pid