forked from laolongju/aws-saas-factory-eks-saas-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildspec.yaml
79 lines (70 loc) · 6.18 KB
/
buildspec.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
---
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