From 4f33c5ceda92625b51bbb6591ca270b3250cbc01 Mon Sep 17 00:00:00 2001 From: GitHub Action Date: Sun, 20 Oct 2024 06:31:10 +0000 Subject: [PATCH] Bump docker tag by https://github.com/cloudnativedaysjp/dreamkast/pull/2419 commit: https://github.com/cloudnativedaysjp/dreamkast/commit/c4b43b17443ffc9de5ac17004764d2e6659eaf05 --- ecspresso/reviewapps/dk-2419/cleanup.sh | 11 ++ ecspresso/reviewapps/dk-2419/const.libsonnet | 45 ++++++++ .../dreamkast-fifo-worker/ecspresso.yml | 6 ++ .../dreamkast-fifo-worker/service-def.jsonnet | 8 ++ .../dreamkast-fifo-worker/task-def.jsonnet | 26 +++++ .../dk-2419/dreamkast/ecspresso.yml | 6 ++ .../dk-2419/dreamkast/service-def.jsonnet | 9 ++ .../dk-2419/dreamkast/task-def.jsonnet | 28 +++++ ecspresso/reviewapps/dk-2419/initialize.sh | 101 ++++++++++++++++++ .../reviewapps/dk-2419/mysql/ecspresso.yml | 6 ++ .../dk-2419/mysql/service-def.jsonnet | 9 ++ .../reviewapps/dk-2419/mysql/task-def.jsonnet | 12 +++ .../reviewapps/dk-2419/redis/ecspresso.yml | 6 ++ .../dk-2419/redis/service-def.jsonnet | 9 ++ .../reviewapps/dk-2419/redis/task-def.jsonnet | 12 +++ 15 files changed, 294 insertions(+) create mode 100644 ecspresso/reviewapps/dk-2419/cleanup.sh create mode 100644 ecspresso/reviewapps/dk-2419/const.libsonnet create mode 100644 ecspresso/reviewapps/dk-2419/dreamkast-fifo-worker/ecspresso.yml create mode 100644 ecspresso/reviewapps/dk-2419/dreamkast-fifo-worker/service-def.jsonnet create mode 100644 ecspresso/reviewapps/dk-2419/dreamkast-fifo-worker/task-def.jsonnet create mode 100644 ecspresso/reviewapps/dk-2419/dreamkast/ecspresso.yml create mode 100644 ecspresso/reviewapps/dk-2419/dreamkast/service-def.jsonnet create mode 100644 ecspresso/reviewapps/dk-2419/dreamkast/task-def.jsonnet create mode 100755 ecspresso/reviewapps/dk-2419/initialize.sh create mode 100644 ecspresso/reviewapps/dk-2419/mysql/ecspresso.yml create mode 100644 ecspresso/reviewapps/dk-2419/mysql/service-def.jsonnet create mode 100644 ecspresso/reviewapps/dk-2419/mysql/task-def.jsonnet create mode 100644 ecspresso/reviewapps/dk-2419/redis/ecspresso.yml create mode 100644 ecspresso/reviewapps/dk-2419/redis/service-def.jsonnet create mode 100644 ecspresso/reviewapps/dk-2419/redis/task-def.jsonnet diff --git a/ecspresso/reviewapps/dk-2419/cleanup.sh b/ecspresso/reviewapps/dk-2419/cleanup.sh new file mode 100644 index 000000000..b45597ca8 --- /dev/null +++ b/ecspresso/reviewapps/dk-2419/cleanup.sh @@ -0,0 +1,11 @@ +#!/usr/bin/env bash +set -e -o pipefail +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 get-service --id srv-dd7axudjrtpvkdho &>/dev/null && aws servicediscovery delete-service --id srv-dd7axudjrtpvkdho +aws servicediscovery get-service --id srv-fm4s4u4qfga3b2va &>/dev/null && aws servicediscovery delete-service --id srv-fm4s4u4qfga3b2va +aws elbv2 describe-rules --rule-arn arn:aws:elasticloadbalancing:us-west-2:607167088920:listener-rule/app/dreamkast-dev/122c5b4a47b64f9d/bc86e7b2e4bca8f5/3dc35c00f5be46a0 &>/dev/null && aws elbv2 delete-rule --rule-arn arn:aws:elasticloadbalancing:us-west-2:607167088920:listener-rule/app/dreamkast-dev/122c5b4a47b64f9d/bc86e7b2e4bca8f5/3dc35c00f5be46a0 +aws elbv2 describe-target-groups --target-group-arn arn:aws:elasticloadbalancing:us-west-2:607167088920:targetgroup/dev-dk-2419/627d14921fe18ebe &>/dev/null && aws elbv2 delete-target-group --target-group-arn arn:aws:elasticloadbalancing:us-west-2:607167088920:targetgroup/dev-dk-2419/627d14921fe18ebe +: diff --git a/ecspresso/reviewapps/dk-2419/const.libsonnet b/ecspresso/reviewapps/dk-2419/const.libsonnet new file mode 100644 index 000000000..fa5c0beb3 --- /dev/null +++ b/ecspresso/reviewapps/dk-2419/const.libsonnet @@ -0,0 +1,45 @@ +{ + PR_NAME: 'dk-2419', + externalEndpoints: { + dkApi: 'https://api.dev.cloudnativedays.jp', + dkWeaver: 'https://dkw.dev.cloudnativedays.jp', + }, + imageTags: { + dreamkast_ecs: 'c4b43b17443ffc9de5ac17004764d2e6659eaf05', + mysql: '8.0.33', + redis: '6.0', + }, + internalEndpoints: { + rdb: 'mysql-dk-2419.development.local', + redis: 'redis://redis-dk-2419.development.local', + }, + publicSubnetIDs: [ + 'subnet-00709135a42bf907e', + 'subnet-0d07831c8fc073511', + 'subnet-033491d41490494b6', + ], + region: 'us-west-2', + s3: { + dreamkast: { + name: 'dreamkast-dev-bucket', + region: 'us-west-2', + }, + }, + secretManager: { + dk: 'dreamkast/reviewapp-env-yGJKrj', + railsApp: 'dreamkast/rails-app-secret-SqidNC', + }, + sentry: { + dsn: 'TODO', + }, + serviceDiscovery: { + mysql: 'srv-dd7axudjrtpvkdho', + redis: 'srv-fm4s4u4qfga3b2va', + }, + sqs: { + fifo: 'dreamkast-stg-fifo-queue', + }, + targetGroupArn: { + dk: 'arn:aws:elasticloadbalancing:us-west-2:607167088920:targetgroup/dev-dk-2419/627d14921fe18ebe', + }, +} diff --git a/ecspresso/reviewapps/dk-2419/dreamkast-fifo-worker/ecspresso.yml b/ecspresso/reviewapps/dk-2419/dreamkast-fifo-worker/ecspresso.yml new file mode 100644 index 000000000..97de379e2 --- /dev/null +++ b/ecspresso/reviewapps/dk-2419/dreamkast-fifo-worker/ecspresso.yml @@ -0,0 +1,6 @@ +region: us-west-2 +cluster: dreamkast-dev +service: dk-2419-dreamkast-fifo-worker +service_definition: service-def.jsonnet +task_definition: task-def.jsonnet +timeout: 10m diff --git a/ecspresso/reviewapps/dk-2419/dreamkast-fifo-worker/service-def.jsonnet b/ecspresso/reviewapps/dk-2419/dreamkast-fifo-worker/service-def.jsonnet new file mode 100644 index 000000000..e5a4be2c2 --- /dev/null +++ b/ecspresso/reviewapps/dk-2419/dreamkast-fifo-worker/service-def.jsonnet @@ -0,0 +1,8 @@ +local dreamkast_fifo_worker = import '../../../base/dreamkast-fifo-worker.libsonnet'; +local const = import '../const.libsonnet'; + +dreamkast_fifo_worker.serviceDef( + region=const.region, + subnetIDs=const.publicSubnetIDs, + securityGroupID='sg-0140d2aeaaa5d6d07', // dreamkast-dev-ecs-dreamkast-fifo-worker +) diff --git a/ecspresso/reviewapps/dk-2419/dreamkast-fifo-worker/task-def.jsonnet b/ecspresso/reviewapps/dk-2419/dreamkast-fifo-worker/task-def.jsonnet new file mode 100644 index 000000000..5b6b01021 --- /dev/null +++ b/ecspresso/reviewapps/dk-2419/dreamkast-fifo-worker/task-def.jsonnet @@ -0,0 +1,26 @@ +local dreamkast_fifo_worker = import '../../../base/dreamkast-fifo-worker.libsonnet'; +local const = import '../const.libsonnet'; + +dreamkast_fifo_worker.taskDef( + family='dreamkast-dev-%s-fifo-worker' % [const.PR_NAME], + taskRoleName='dreamkast-dev-ecs-dreamkast-fifo-worker', + imageTag=const.imageTags.dreamkast_ecs, + + region=const.region, + rdbInternalEndpoint=const.internalEndpoints.rdb, + redisInternalEndpoint=const.internalEndpoints.redis, + + s3BucketName=const.s3.dreamkast.name, + s3BucketRegion=const.s3.dreamkast.region, + + sqsFifoQueueName=const.sqs.fifo, + + sentryDsn=const.sentry.dsn, + + railsAppSecretManagerName=const.secretManager.railsApp, + rdsSecretManagerName=const.secretManager.rds, + dreamkastSecretManagerName=const.secretManager.dk, + + enableLogging=true, + reviewapp=true, +) diff --git a/ecspresso/reviewapps/dk-2419/dreamkast/ecspresso.yml b/ecspresso/reviewapps/dk-2419/dreamkast/ecspresso.yml new file mode 100644 index 000000000..f3e85580a --- /dev/null +++ b/ecspresso/reviewapps/dk-2419/dreamkast/ecspresso.yml @@ -0,0 +1,6 @@ +region: us-west-2 +cluster: dreamkast-dev +service: dk-2419-dreamkast +service_definition: service-def.jsonnet +task_definition: task-def.jsonnet +timeout: 10m diff --git a/ecspresso/reviewapps/dk-2419/dreamkast/service-def.jsonnet b/ecspresso/reviewapps/dk-2419/dreamkast/service-def.jsonnet new file mode 100644 index 000000000..8ee603369 --- /dev/null +++ b/ecspresso/reviewapps/dk-2419/dreamkast/service-def.jsonnet @@ -0,0 +1,9 @@ +local dreamkast_dk = import '../../../base/dreamkast.libsonnet'; +local const = import '../const.libsonnet'; + +dreamkast_dk.serviceDef( + region=const.region, + subnetIDs=const.publicSubnetIDs, + securityGroupID='sg-00e734fea020b954d', // dreamkast-dev-ecs-dreamkast + targetGroupArn=const.targetGroupArn.dk, +) diff --git a/ecspresso/reviewapps/dk-2419/dreamkast/task-def.jsonnet b/ecspresso/reviewapps/dk-2419/dreamkast/task-def.jsonnet new file mode 100644 index 000000000..fba481657 --- /dev/null +++ b/ecspresso/reviewapps/dk-2419/dreamkast/task-def.jsonnet @@ -0,0 +1,28 @@ +local dreamkast = import '../../../base/dreamkast.libsonnet'; +local const = import '../const.libsonnet'; + +dreamkast.taskDef( + family='dreamkast-dev-%s-dk' % [const.PR_NAME], + taskRoleName='dreamkast-dev-ecs-dreamkast', + imageTag=const.imageTags.dreamkast_ecs, + + region=const.region, + dkApiEndpoint=const.externalEndpoints.dkApi, + dkWeaverEndpoint=const.externalEndpoints.dkWeaver, + rdbInternalEndpoint=const.internalEndpoints.rdb, + redisInternalEndpoint=const.internalEndpoints.redis, + + s3BucketName=const.s3.dreamkast.name, + s3BucketRegion=const.s3.dreamkast.region, + + sqsFifoQueueName=const.sqs.fifo, + + sentryDsn=const.sentry.dsn, + + railsAppSecretManagerName=const.secretManager.railsApp, + rdsSecretManagerName=const.secretManager.rds, + dreamkastSecretManagerName=const.secretManager.dk, + + enableLogging=true, + reviewapp=true, +) diff --git a/ecspresso/reviewapps/dk-2419/initialize.sh b/ecspresso/reviewapps/dk-2419/initialize.sh new file mode 100755 index 000000000..019521331 --- /dev/null +++ b/ecspresso/reviewapps/dk-2419/initialize.sh @@ -0,0 +1,101 @@ +#!/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=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") + +SERVICE_ID_REDIS=$(aws servicediscovery create-service \ + --name "redis-${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: { + dk: "${TARGET_GROUP_ARN}", + }, + serviceDiscovery: { + mysql: "${SERVICE_ID_MYSQL}", + redis: "${SERVICE_ID_REDIS}", + }, + imageTags: const.imageTags + { + dreamkast_ecs: "${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.yml" | xargs -I{} -P10 ecspresso --config={} delete --force --terminate ||: +sleep 10 # wait for ECS Services to be deleted +aws servicediscovery get-service --id ${SERVICE_ID_MYSQL} &>/dev/null && aws servicediscovery delete-service --id ${SERVICE_ID_MYSQL} +aws servicediscovery get-service --id ${SERVICE_ID_REDIS} &>/dev/null && aws servicediscovery delete-service --id ${SERVICE_ID_REDIS} +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_ecs|=\"${IMAGE_TAG}\"" \ + > const.libsonnet.tmp +mv const.libsonnet.tmp const.libsonnet + +fi + +jsonnetfmt -i const.libsonnet diff --git a/ecspresso/reviewapps/dk-2419/mysql/ecspresso.yml b/ecspresso/reviewapps/dk-2419/mysql/ecspresso.yml new file mode 100644 index 000000000..c25556733 --- /dev/null +++ b/ecspresso/reviewapps/dk-2419/mysql/ecspresso.yml @@ -0,0 +1,6 @@ +region: us-west-2 +cluster: dreamkast-dev +service: dk-2419-mysql +service_definition: service-def.jsonnet +task_definition: task-def.jsonnet +timeout: 10m diff --git a/ecspresso/reviewapps/dk-2419/mysql/service-def.jsonnet b/ecspresso/reviewapps/dk-2419/mysql/service-def.jsonnet new file mode 100644 index 000000000..9dab2c6cf --- /dev/null +++ b/ecspresso/reviewapps/dk-2419/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.publicSubnetIDs, + securityGroupID='sg-0e0029eb49f4d0455', // dreamkast-dev-ecs-mysql + serviceDiscoveryID=const.serviceDiscovery.mysql, +) diff --git a/ecspresso/reviewapps/dk-2419/mysql/task-def.jsonnet b/ecspresso/reviewapps/dk-2419/mysql/task-def.jsonnet new file mode 100644 index 000000000..e8a42b6ab --- /dev/null +++ b/ecspresso/reviewapps/dk-2419/mysql/task-def.jsonnet @@ -0,0 +1,12 @@ +local mysql = import '../../../base/mysql.libsonnet'; +local const = import '../const.libsonnet'; + +mysql.taskDef( + family='dreamkast-dev-%s-mysql' % [const.PR_NAME], + taskRoleName='dreamkast-dev-ecs-mysql', + imageTag=const.imageTags.mysql, + + region=const.region, + + enableLogging=false, +) diff --git a/ecspresso/reviewapps/dk-2419/redis/ecspresso.yml b/ecspresso/reviewapps/dk-2419/redis/ecspresso.yml new file mode 100644 index 000000000..2587d3665 --- /dev/null +++ b/ecspresso/reviewapps/dk-2419/redis/ecspresso.yml @@ -0,0 +1,6 @@ +region: us-west-2 +cluster: dreamkast-dev +service: dk-2419-redis +service_definition: service-def.jsonnet +task_definition: task-def.jsonnet +timeout: 10m diff --git a/ecspresso/reviewapps/dk-2419/redis/service-def.jsonnet b/ecspresso/reviewapps/dk-2419/redis/service-def.jsonnet new file mode 100644 index 000000000..d70462f23 --- /dev/null +++ b/ecspresso/reviewapps/dk-2419/redis/service-def.jsonnet @@ -0,0 +1,9 @@ +local redis = import '../../../base/redis.libsonnet'; +local const = import '../const.libsonnet'; + +redis.serviceDef( + region=const.region, + subnetIDs=const.publicSubnetIDs, + securityGroupID='sg-0ab649652e2dd6c9c', // dreamkast-dev-ecs-redis + serviceDiscoveryID=const.serviceDiscovery.redis, +) diff --git a/ecspresso/reviewapps/dk-2419/redis/task-def.jsonnet b/ecspresso/reviewapps/dk-2419/redis/task-def.jsonnet new file mode 100644 index 000000000..e2ed63cba --- /dev/null +++ b/ecspresso/reviewapps/dk-2419/redis/task-def.jsonnet @@ -0,0 +1,12 @@ +local redis = import '../../../base/redis.libsonnet'; +local const = import '../const.libsonnet'; + +redis.taskDef( + family='dreamkast-dev-%s-redis' % [const.PR_NAME], + taskRoleName='dreamkast-dev-ecs-redis', + imageTag=const.imageTags.redis, + + region=const.region, + + enableLogging=false, +)