diff --git a/ecspresso/reviewapps/ui-534/cleanup.sh b/ecspresso/reviewapps/ui-534/cleanup.sh new file mode 100644 index 000000000..a7a22ca57 --- /dev/null +++ b/ecspresso/reviewapps/ui-534/cleanup.sh @@ -0,0 +1,8 @@ +#!/usr/bin/env bash +set -e -o pipefail +cd $(dirname $0) + +find . -name "ecspresso.jsonnet" | xargs -I{} -P10 ecspresso --config={} delete --force --terminate ||: +aws elbv2 describe-rules --rule-arn arn:aws:elasticloadbalancing:us-west-2:607167088920:listener-rule/app/dreamkast-dev/122c5b4a47b64f9d/bc86e7b2e4bca8f5/6d9440fe2a56004b &>/dev/null && aws elbv2 delete-rule --rule-arn arn:aws:elasticloadbalancing:us-west-2:607167088920:listener-rule/app/dreamkast-dev/122c5b4a47b64f9d/bc86e7b2e4bca8f5/6d9440fe2a56004b +aws elbv2 describe-target-groups --target-group-arn arn:aws:elasticloadbalancing:us-west-2:607167088920:targetgroup/dev-ui-534/df068e28ed5ed6a9 &>/dev/null && aws elbv2 delete-target-group --target-group-arn arn:aws:elasticloadbalancing:us-west-2:607167088920:targetgroup/dev-ui-534/df068e28ed5ed6a9 +: diff --git a/ecspresso/reviewapps/ui-534/const.libsonnet b/ecspresso/reviewapps/ui-534/const.libsonnet new file mode 100644 index 000000000..ca6c006cd --- /dev/null +++ b/ecspresso/reviewapps/ui-534/const.libsonnet @@ -0,0 +1,26 @@ +{ + PR_NAME: 'ui-534', + cluster: 'dreamkast-dev', + executionRoleName: 'dreamkast-dev-ecs-task-execution-role', + externalEndpoints: { + dk: 'https://development.dev.cloudnativedays.jp', + dkWeaver: 'https://dkw.dev.cloudnativedays.jp', + }, + imageTags: { + dreamkast_ui: '9e3897a6d78cdd6b1f80278e473932efda8002c2', + }, + internalEndpoints: {}, + publicSubnetIDs: [ + 'subnet-00709135a42bf907e', + 'subnet-0d07831c8fc073511', + 'subnet-033491d41490494b6', + ], + region: 'us-west-2', + secretManager: { + dkUi: 'dreamkast-ui/reviewapp-env-Cytidj', + }, + targetGroupArn: { + dkUi: 'arn:aws:elasticloadbalancing:us-west-2:607167088920:targetgroup/dev-ui-534/df068e28ed5ed6a9', + }, + taskTargetRoleName: 'dreamkast-dev-ecs-scheduled-task-target-role', +} diff --git a/ecspresso/reviewapps/ui-534/dreamkast-ui/ecspresso.jsonnet b/ecspresso/reviewapps/ui-534/dreamkast-ui/ecspresso.jsonnet new file mode 100644 index 000000000..efe977b9c --- /dev/null +++ b/ecspresso/reviewapps/ui-534/dreamkast-ui/ecspresso.jsonnet @@ -0,0 +1,9 @@ +local const = import '../const.libsonnet'; +{ + region: const.region, + cluster: const.cluster, + service: '%s-dreamkast-ui' % [const.PR_NAME], + service_definition: 'service-def.jsonnet', + task_definition: 'task-def.jsonnet', + timeout: '10m', +} diff --git a/ecspresso/reviewapps/ui-534/dreamkast-ui/service-def.jsonnet b/ecspresso/reviewapps/ui-534/dreamkast-ui/service-def.jsonnet new file mode 100644 index 000000000..835ebb326 --- /dev/null +++ b/ecspresso/reviewapps/ui-534/dreamkast-ui/service-def.jsonnet @@ -0,0 +1,9 @@ +local dreamkast_ui = import '../../../base/dreamkast-ui.libsonnet'; +local const = import '../const.libsonnet'; + +dreamkast_ui.serviceDef( + region=const.region, + subnetIDs=const.publicSubnetIDs, + securityGroupID='sg-026faf401f03b7bd4', // dreamkast-dev-ecs-dreamkast-ui + targetGroupArn=const.targetGroupArn.dkUi, +) diff --git a/ecspresso/reviewapps/ui-534/dreamkast-ui/task-def.jsonnet b/ecspresso/reviewapps/ui-534/dreamkast-ui/task-def.jsonnet new file mode 100644 index 000000000..95178bf7f --- /dev/null +++ b/ecspresso/reviewapps/ui-534/dreamkast-ui/task-def.jsonnet @@ -0,0 +1,18 @@ +local dreamkast_ui = import '../../../base/dreamkast-ui.libsonnet'; +local const = import '../const.libsonnet'; + +dreamkast_ui.taskDef( + family='dreamkast-dev-%s-ui' % [const.PR_NAME], + taskRoleName='dreamkast-dev-ecs-dreamkast-ui', + executionRoleName=const.executionRoleName, + imageTag=const.imageTags.dreamkast_ui, + + region=const.region, + dkEndpoint=const.externalEndpoints.dk, + dkWeaverEndpoint=const.externalEndpoints.dkWeaver, + + dkUiSecretManagerName=const.secretManager.dkUi, + + enableLogging=true, + reviewapp=true, +) diff --git a/ecspresso/reviewapps/ui-534/initialize.sh b/ecspresso/reviewapps/ui-534/initialize.sh new file mode 100755 index 000000000..e2f72ccc6 --- /dev/null +++ b/ecspresso/reviewapps/ui-534/initialize.sh @@ -0,0 +1,79 @@ +#!/usr/bin/env bash +set -e -o pipefail +cd $(dirname $0) + +# required the following commands: +# * aws +# * jq +# * jsonnet +# * jsonnetfmt + +# 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=10000 +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 \ + --health-check-path "/cndw2024/ui" \ + | 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") + +# replace variables in const.libsonnet +cat << _EOL_ | jsonnet - > ./const.libsonnet.tmp +local const = import './const.libsonnet'; + +const + { + PR_NAME: "${PR_NAME}", + targetGroupArn: { + dkUi: "${TARGET_GROUP_ARN}", + }, + imageTags: const.imageTags + { + dreamkast_ui: "${IMAGE_TAG}", + }, +} +_EOL_ +mv const.libsonnet.tmp const.libsonnet + +# create cleanup.sh +cat << _EOF_ > ./cleanup.sh +#!/usr/bin/env bash +set -e -o pipefail +cd \$(dirname \$0) + +find . -name "ecspresso.jsonnet" | xargs -I{} -P10 ecspresso --config={} delete --force --terminate ||: +aws elbv2 describe-rules --rule-arn ${LISTENER_RULE_ARN} &>/dev/null && aws elbv2 delete-rule --rule-arn ${LISTENER_RULE_ARN} +aws elbv2 describe-target-groups --target-group-arn ${TARGET_GROUP_ARN} &>/dev/null && aws elbv2 delete-target-group --target-group-arn ${TARGET_GROUP_ARN} +: +_EOF_ + +else +# update imageTags +jsonnet const.libsonnet \ + | jq ".imageTags.dreamkast_ui|=\"${IMAGE_TAG}\"" \ + > const.libsonnet.tmp +mv const.libsonnet.tmp const.libsonnet + +fi + +jsonnetfmt -i const.libsonnet