diff --git a/ecspresso/reviewapps/weaver-92/cleanup.sh b/ecspresso/reviewapps/weaver-92/cleanup.sh new file mode 100644 index 000000000..c0d377094 --- /dev/null +++ b/ecspresso/reviewapps/weaver-92/cleanup.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash + +cd $(dirname $0) +find . -name "ecspresso.yml" | xargs -I{} -P10 ecspresso --config={} delete --force --terminate +sleep 10 # wait for ECS Services to be deleted +aws servicediscovery delete-service --id srv-f7pduvwkh3v4bzmb +aws elbv2 delete-rule --rule-arn arn:aws:elasticloadbalancing:us-west-2:607167088920:listener-rule/app/dreamkast-dev/122c5b4a47b64f9d/bc86e7b2e4bca8f5/678d5b2700079b81 +aws elbv2 delete-target-group --target-group-arn arn:aws:elasticloadbalancing:us-west-2:607167088920:targetgroup/dev-weaver-92/3f7edd641e0d4ea3 diff --git a/ecspresso/reviewapps/weaver-92/const.libsonnet b/ecspresso/reviewapps/weaver-92/const.libsonnet new file mode 100644 index 000000000..2ce6916b0 --- /dev/null +++ b/ecspresso/reviewapps/weaver-92/const.libsonnet @@ -0,0 +1,32 @@ +{ + "PR_NAME": "weaver-92", + "externalEndpoints": { }, + "imageTags": { + "dreamkast_weaver": "87bcd4cb0f2d8d26449a2cc0a1feb9197607b39a", + "mysql": "8.0.33" + }, + "internalEndpoints": { + "dk": "http://dreamkast.development.local:3000", + "rdb": "mysql-weaver-92.development.local" + }, + "privateSubnetIDs": [ + "subnet-05d0a81dafd9409f9", + "subnet-042770b2f29661e8e", + "subnet-0d95068828df7cc3e" + ], + "publicSubnetIDs": [ + "subnet-00709135a42bf907e", + "subnet-0d07831c8fc073511", + "subnet-033491d41490494b6" + ], + "region": "us-west-2", + "secretManager": { + "rds": "dreamkast-stg-rds-secret-0dsVhM" + }, + "serviceDiscovery": { + "mysql": "srv-f7pduvwkh3v4bzmb" + }, + "targetGroupArn": { + "dkWeaver": "arn:aws:elasticloadbalancing:us-west-2:607167088920:targetgroup/dev-weaver-92/3f7edd641e0d4ea3" + } +} diff --git a/ecspresso/reviewapps/weaver-92/dreamkast-weaver/ecspresso.yml b/ecspresso/reviewapps/weaver-92/dreamkast-weaver/ecspresso.yml new file mode 100644 index 000000000..bd9c1679b --- /dev/null +++ b/ecspresso/reviewapps/weaver-92/dreamkast-weaver/ecspresso.yml @@ -0,0 +1,6 @@ +region: us-west-2 +cluster: dreamkast-dev +service: weaver-92-dreamkast-weaver +service_definition: service-def.jsonnet +task_definition: task-def.jsonnet +timeout: 5m diff --git a/ecspresso/reviewapps/weaver-92/dreamkast-weaver/service-def.jsonnet b/ecspresso/reviewapps/weaver-92/dreamkast-weaver/service-def.jsonnet new file mode 100644 index 000000000..ee488728b --- /dev/null +++ b/ecspresso/reviewapps/weaver-92/dreamkast-weaver/service-def.jsonnet @@ -0,0 +1,9 @@ +local dreamkast_weaver = import '../../../base/dreamkast-weaver.libsonnet'; +local const = import '../const.libsonnet'; + +dreamkast_weaver.serviceDef( + region=const.region, + subnetIDs=const.privateSubnetIDs, + securityGroupID='sg-0af84e950ec9eb4f4', // dreamkast-dev-ecs-dreamkast-weaver + targetGroupArn=const.targetGroupArn.dkWeaver, +) diff --git a/ecspresso/reviewapps/weaver-92/dreamkast-weaver/task-def.jsonnet b/ecspresso/reviewapps/weaver-92/dreamkast-weaver/task-def.jsonnet new file mode 100644 index 000000000..b47547c62 --- /dev/null +++ b/ecspresso/reviewapps/weaver-92/dreamkast-weaver/task-def.jsonnet @@ -0,0 +1,17 @@ +local dreamkast_weaver = import '../../../base/dreamkast-weaver.libsonnet'; +local const = import '../const.libsonnet'; + +dreamkast_weaver.taskDef( + family='dreamkast-dev-%s-ui' % [const.PR_NAME], + taskRoleName='dreamkast-dev-ecs-dreamkast-weaver', + imageTag=const.imageTags.dreamkast_weaver, + + region=const.region, + dkInternalEndpoint=const.internalEndpoints.dk, + rdbInternalEndpoint=const.internalEndpoints.rdb, + + rdsSecretManagerName=const.secretManager.rds, + + enableLogging=true, + reviewapp=true, +) diff --git a/ecspresso/reviewapps/weaver-92/initialize.sh b/ecspresso/reviewapps/weaver-92/initialize.sh new file mode 100755 index 000000000..c287a60d9 --- /dev/null +++ b/ecspresso/reviewapps/weaver-92/initialize.sh @@ -0,0 +1,88 @@ +#!/usr/bin/env bash + +cd $(dirname $0) + +# required the following commands: +# * aws +# * jq +# * jsonnet + +# variables +PR_NAME=${PR_NAME:?"PR_NAME must be specified"} +PR_NUMBER=${PR_NUMBER:?"PR_NUMBER must be specified"} +IMAGE_TAG=${IMAGE_TAG:?"IMAGE_TAG must be specified"} +LISTENER_RULE_PRIORITY_BASE=30000 +LISTENER_RULE_PRIORITY=$(( LISTENER_RULE_PRIORITY_BASE + PR_NUMBER )) + +VPC_ID="vpc-0f0d012967c635f34" +LISTENER_ARN="arn:aws:elasticloadbalancing:us-west-2:607167088920:listener/app/dreamkast-dev/122c5b4a47b64f9d/bc86e7b2e4bca8f5" +SERVICE_DISCOVERY_NAMESPACE="ns-53ijjrlltqf5r2gm" + + +if [ ! -f "cleanup.sh" ]; then +# create TargetGroup +TARGET_GROUP_ARN=$(aws elbv2 create-target-group \ + --name "dev-${PR_NAME}" \ + --target-type ip \ + --protocol HTTP \ + --port 3000 \ + --vpc-id ${VPC_ID} \ + --ip-address-type ipv4 \ + | jq -r ".TargetGroups[0].TargetGroupArn") + +# create ALB ListenerRule +LISTENER_RULE_ARN=$(aws elbv2 create-rule --listener-arn ${LISTENER_ARN} \ + --priority ${LISTENER_RULE_PRIORITY} \ + --conditions Field=host-header,Values="dreamkast-${PR_NAME}.dev.cloudnativedays.jp" \ + --actions Type=forward,TargetGroupArn=${TARGET_GROUP_ARN} \ + | jq -r ".Rules[] | select(.Priority == \"${LISTENER_RULE_PRIORITY}\") | .RuleArn") + +# create ServiceDiscovery Services +SERVICE_ID_MYSQL=$(aws servicediscovery create-service \ + --name "mysql-${PR_NAME}" \ + --dns-config "NamespaceId="${SERVICE_DISCOVERY_NAMESPACE}",DnsRecords=[{Type="A",TTL="10"}]" \ + --health-check-custom-config FailureThreshold=1 \ + | jq -r ".Service.Id") + +# replace variables in each ecspresso.yml +find . -name ecspresso.yml | xargs -I{} sed -i -e 's/__PR_NAME__/'${PR_NAME}'/g' {} + +# replace variables in const.libsonnet +cat << _EOL_ | jsonnet - > ./const.libsonnet.tmp +local const = import './const.libsonnet'; + +const + { + PR_NAME: "${PR_NAME}", + targetGroupArn: { + dkWeaver: "${TARGET_GROUP_ARN}", + }, + serviceDiscovery: { + mysql: "${SERVICE_ID_MYSQL}", + }, + imageTags: const.imageTags + { + dreamkast_weaver: "${IMAGE_TAG}", + }, +} +_EOL_ +mv const.libsonnet.tmp const.libsonnet + +# create cleanup.sh +cat << _EOF_ > ./cleanup.sh +#!/usr/bin/env bash + +cd \$(dirname \$0) +find . -name "ecspresso.yml" | xargs -I{} -P10 ecspresso --config={} delete --force --terminate +sleep 10 # wait for ECS Services to be deleted +aws servicediscovery delete-service --id ${SERVICE_ID_MYSQL} +aws elbv2 delete-rule --rule-arn ${LISTENER_RULE_ARN} +aws elbv2 delete-target-group --target-group-arn ${TARGET_GROUP_ARN} +_EOF_ + +else +# update imageTags +jsonnet const.libsonnet \ + | jq ".imageTags.dreamkast_weaver|=\"${IMAGE_TAG}\"" \ + > const.libsonnet.tmp +mv const.libsonnet.tmp const.libsonnet + +fi diff --git a/ecspresso/reviewapps/weaver-92/mysql/ecspresso.yml b/ecspresso/reviewapps/weaver-92/mysql/ecspresso.yml new file mode 100644 index 000000000..7b7a074e2 --- /dev/null +++ b/ecspresso/reviewapps/weaver-92/mysql/ecspresso.yml @@ -0,0 +1,6 @@ +region: us-west-2 +cluster: dreamkast-dev +service: weaver-92-mysql +service_definition: service-def.jsonnet +task_definition: task-def.jsonnet +timeout: 5m diff --git a/ecspresso/reviewapps/weaver-92/mysql/service-def.jsonnet b/ecspresso/reviewapps/weaver-92/mysql/service-def.jsonnet new file mode 100644 index 000000000..cdc371858 --- /dev/null +++ b/ecspresso/reviewapps/weaver-92/mysql/service-def.jsonnet @@ -0,0 +1,9 @@ +local redis = import '../../../base/mysql.libsonnet'; +local const = import '../const.libsonnet'; + +redis.serviceDef( + region=const.region, + subnetIDs=const.privateSubnetIDs, + securityGroupID='sg-0e0029eb49f4d0455', // dreamkast-dev-ecs-mysql + serviceDiscoveryID=const.serviceDiscovery.mysql, +) diff --git a/ecspresso/reviewapps/weaver-92/mysql/task-def.jsonnet b/ecspresso/reviewapps/weaver-92/mysql/task-def.jsonnet new file mode 100644 index 000000000..f48b1e476 --- /dev/null +++ b/ecspresso/reviewapps/weaver-92/mysql/task-def.jsonnet @@ -0,0 +1,12 @@ +local mysql = import '../../../base/mysql.libsonnet'; +local const = import '../const.libsonnet'; + +mysql.taskDef( + family='dreamkast-stg-%s-mysql' % [const.PR_NAME], + taskRoleName='dreamkast-dev-ecs-mysql', + imageTag=const.imageTags.mysql, + + region=const.region, + + enableLogging=false, +)