--- version: 0.2 phases: install: commands: - curl -sS -o aws-iam-authenticator https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-07-26/bin/linux/amd64/aws-iam-authenticator - curl -sS -o kubectl https://amazon-eks.s3.us-west-2.amazonaws.com/1.17.7/2020-07-08/bin/linux/amd64/kubectl - curl --silent --location https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz | tar xz -C . - chmod +x ./kubectl ./aws-iam-authenticator - export PATH=$PWD/:$PATH - apt-get update && apt-get -y install jq - curl https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip -o awscliv2.zip && unzip awscliv2.zip && ./aws/install pre_build: commands: - export KUBECONFIG=$HOME/.kube/config build: commands: post_build: commands: - REGION=$(aws cloudformation describe-stacks --stack-name RootStack --query "Stacks[0].Outputs[?OutputKey=='AWSRegion'].OutputValue" --output text) - APPLICATIONECR=$(aws cloudformation describe-stacks --stack-name RootStack --query "Stacks[0].Outputs[?OutputKey=='ApplicationECR'].OutputValue" --output text) - ORDERECR=$(aws cloudformation describe-stacks --stack-name RootStack --query "Stacks[0].Outputs[?OutputKey=='OrderServiceECR'].OutputValue" --output text) - PRODUCTECR=$(aws cloudformation describe-stacks --stack-name RootStack --query "Stacks[0].Outputs[?OutputKey=='ProductServiceECR'].OutputValue" --output text) - ORDERTABLE=$(aws cloudformation describe-stacks --stack-name RootStack --query "Stacks[0].Outputs[?OutputKey=='OrderTable'].OutputValue" --output text) - PRODUCTTABLE=$(aws cloudformation describe-stacks --stack-name RootStack --query "Stacks[0].Outputs[?OutputKey=='ProductTable'].OutputValue" --output text) - TENANTSTACKTABLE=$(aws cloudformation describe-stacks --stack-name RootStack --query "Stacks[0].Outputs[?OutputKey=='TenantStackMappingTable'].OutputValue" --output text) - CREDENTIALS=$(aws sts assume-role --role-arn $CodeBuildArn --role-session-name codebuild-kubectl --duration-seconds 900) - echo "${CREDENTIALS}" - export AWS_ACCESS_KEY_ID="$(echo ${CREDENTIALS} | jq -r '.Credentials.AccessKeyId')" - export AWS_SECRET_ACCESS_KEY="$(echo ${CREDENTIALS} | jq -r '.Credentials.SecretAccessKey')" - export AWS_SESSION_TOKEN="$(echo ${CREDENTIALS} | jq -r '.Credentials.SessionToken')" - export AWS_EXPIRATION=$(echo ${CREDENTIALS} | jq -r '.Credentials.Expiration') - aws eks update-kubeconfig --name eksworkshop-eksctl - kubectl version - cat $HOME/.kube/config - kubectl config view - echo "${TenantName}" - kubectl create ns ${TenantName} - echo "Create Silo Tenant Product table" - CREATE_PRODUCT_TABLE=$(aws dynamodb create-table --table-name Products-silo-$TenantName --attribute-definitions AttributeName=tenant_id,AttributeType=S AttributeName=product_id,AttributeType=S --key-schema AttributeName=tenant_id,KeyType=HASH AttributeName=product_id,KeyType=RANGE --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5) - PRODUCTTABLE="$(echo ${CREATE_PRODUCT_TABLE} | jq -r '.TableDescription.TableName')" - echo "Create Silo Tenant Order table" - CREATE_ORDER_TABLE=$(aws dynamodb create-table --table-name Orders-silo-$TenantName --attribute-definitions AttributeName=tenant_id,AttributeType=S AttributeName=order_id,AttributeType=S --key-schema AttributeName=tenant_id,KeyType=HASH AttributeName=order_id,KeyType=RANGE --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5) - ORDERTABLE="$(echo ${CREATE_ORDER_TABLE} | jq -r '.TableDescription.TableName')" - sed -i -e 's,APPLICATION_ECR_REPO,'$APPLICATIONECR',g' client/web/application/k8s/template.yaml - sed -i -e 's,ELB_URL,'$ElbUrl',g' client/web/application/k8s/template.yaml - sed -i -e 's,TENANT_PATH,'$TenantName',g' client/web/application/k8s/template.yaml - kubectl apply -f client/web/application/k8s/template.yaml -n ${TenantName} - sed -i -e 's,ORDER_SERVICE_ECR_REPO,'$ORDERECR',g' services/application/apps/order/k8s/template.yaml - sed -i -e 's,ELB_URL,'$ElbUrl',g' services/application/apps/order/k8s/template.yaml - sed -i -e 's,INSERT_AWS_REGION,'$REGION',g' services/application/apps/order/k8s/template.yaml - sed -i -e 's,INSERT_IAM_ROLE_ARN,'$IamRoleArn',g' services/application/apps/order/k8s/template.yaml - sed -i -e 's,INSERT_COGNITO_USER_POOL_ID,'$UserPoolId',g' services/application/apps/order/k8s/template.yaml - sed -i -e 's,INSERT_COGNITO_CLIENT_ID,'$AppClientId',g' services/application/apps/order/k8s/template.yaml - sed -i -e 's,INSERT_COGNITO_REGION,'$REGION',g' services/application/apps/order/k8s/template.yaml - sed -i -e 's,INSERT_ORDER_TABLE_NAME,'$ORDERTABLE',g' services/application/apps/order/k8s/template.yaml - sed -i -e 's,TENANT_PATH,'$TenantName',g' services/application/apps/order/k8s/template.yaml - kubectl apply -f services/application/apps/order/k8s/template.yaml -n ${TenantName} - sed -i -e 's,PRODUCT_SERVICE_ECR_REPO,'$PRODUCTECR',g' services/application/apps/product/k8s/template.yaml - sed -i -e 's,ELB_URL,'$ElbUrl',g' services/application/apps/product/k8s/template.yaml - sed -i -e 's,INSERT_AWS_REGION,'$REGION',g' services/application/apps/product/k8s/template.yaml - sed -i -e 's,INSERT_IAM_ROLE_ARN,'$IamRoleArn',g' services/application/apps/product/k8s/template.yaml - sed -i -e 's,INSERT_COGNITO_USER_POOL_ID,'$UserPoolId',g' services/application/apps/product/k8s/template.yaml - sed -i -e 's,INSERT_COGNITO_CLIENT_ID,'$AppClientId',g' services/application/apps/product/k8s/template.yaml - sed -i -e 's,INSERT_COGNITO_REGION,'$REGION',g' services/application/apps/product/k8s/template.yaml - sed -i -e 's,INSERT_PRODUCT_TABLE_NAME,'$PRODUCTTABLE',g' services/application/apps/product/k8s/template.yaml - sed -i -e 's,TENANT_PATH,'$TenantName',g' services/application/apps/product/k8s/template.yaml - kubectl apply -f services/application/apps/product/k8s/template.yaml -n ${TenantName} - chmod +x update-provisioning-status.sh - ./update-provisioning-status.sh $TENANTSTACKTABLE $TenantName