Skip to content

Commit 4acf3ea

Browse files
authored
Build new ECS cluster in stage; move celery; launch flower (#617)
* Get up to date with main, start in on new configs * Build accounts-stage megacluster * Move Redis cluster def after Fargate clusters, use SGs * Add new AFC in stage, get Celery working there * Add Flower service to accounts-stage * Tidy up * Update stage image * Turn off the old celery cluster; update CI accordingly * Use variablized images * Update celery scale * Flower should never need to scale past 1 container * Try to dry out the stage config * Remove bastion * Tidy up * Tidy up * Tidy up
1 parent 378ccb8 commit 4acf3ea

File tree

5 files changed

+433
-208
lines changed

5 files changed

+433
-208
lines changed

.github/workflows/merge.yml

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,7 @@ jobs:
162162
# Create a YAML config stump containing only the nested tree leading to the image tag update
163163
cat << EOF > newimage.yaml
164164
resources:
165-
tb:fargate:FargateClusterWithLogging:
166-
accounts:
167-
task_definition:
168-
container_definitions:
169-
accounts:
170-
image: "$ECR_TAG"
171-
accounts-celery:
172-
task_definition:
173-
container_definitions:
174-
accounts:
175-
image: "$ECR_TAG"
165+
.accounts_image: &ACCOUNTS_IMAGE $ECR_TAG
176166
EOF
177167
178168
# Use yq to merge the stump into the main config
@@ -183,7 +173,8 @@ jobs:
183173
pulumi stack select thunderbird/stage
184174
pulumi up -y --diff \
185175
--target 'urn:pulumi:stage::accounts::tb:fargate:FargateClusterWithLogging$aws:ecs/taskDefinition:TaskDefinition::accounts-stage-fargate-accounts-taskdef' \
186-
--target 'urn:pulumi:stage::accounts::tb:fargate:FargateClusterWithLogging$aws:ecs/taskDefinition:TaskDefinition::accounts-stage-fargate-accounts-celery-taskdef' \
176+
--target 'urn:pulumi:stage::accounts::aws:ecs/taskDefinition:TaskDefinition::accounts-stage-afc-accounts-taskdef-celery' \
177+
--target 'urn:pulumi:stage::accounts::aws:ecs/taskDefinition:TaskDefinition::accounts-stage-afc-accounts-taskdef-flower' \
187178
--target-dependents
188179
189180
# When accounts changes are merged in, build and push a new Docker image
@@ -296,12 +287,7 @@ jobs:
296287
# Create a YAML config stump containing only the nested tree leading to the image tag update
297288
cat << EOF > newimage.yaml
298289
resources:
299-
tb:fargate:FargateClusterWithLogging:
300-
keycloak:
301-
task_definition:
302-
container_definitions:
303-
keycloak:
304-
image: "$ECR_TAG"
290+
keycloak_image: &KEYCLOAK_IMAGE $ECR_TAG
305291
EOF
306292
307293
# Use yq to merge the stump into the main config

.github/workflows/validate.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,6 @@ jobs:
104104

105105
run-e2e-tests-local:
106106
needs: detect-changes
107-
# if: needs.detect-changes.outputs.iac-changed
108107
if: false
109108
runs-on: ubuntu-latest
110109
environment: staging

pulumi/__main__.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,16 +77,17 @@
7777
**instance_opts,
7878
)
7979

80-
# Build an ElastiCache Redis cluster allowing access from the Accounts containers
81-
redis_opts = resources['tb:elasticache:ElastiCacheReplicaGroup']['accounts']
82-
redis = tb_pulumi.elasticache.ElastiCacheReplicationGroup(
83-
name=f'{project.name_prefix}-redis',
84-
project=project,
85-
source_sgids=[container_sgs['accounts'].resources['sg'].id, container_sgs['accounts-celery'].resources['sg'].id],
86-
subnets=vpc.resources['subnets'],
87-
opts=pulumi.ResourceOptions(depends_on=[vpc, container_sgs['accounts']]),
88-
**redis_opts,
89-
)
80+
# Build a single Fargate cluster to run and scale all our accounts-related services
81+
autoscaling_fargate_clusters = {
82+
cluster_name: tb_pulumi.fargate.AutoscalingFargateCluster(
83+
f'{project.name_prefix}-afc-{cluster_name}',
84+
project=project,
85+
subnets=vpc.resources['subnets'],
86+
**cluster_config,
87+
)
88+
for cluster_name, cluster_config in resources.get('tb:fargate:AutoscalingFargateCluster', {}).items()
89+
}
90+
9091

9192
# Build Fargate clusters to run our containers
9293
autoscalers = {}
@@ -125,6 +126,24 @@
125126
**autoscaler_opts,
126127
)
127128

129+
# Build an ElastiCache Redis cluster allowing access from the Accounts containers
130+
redis_opts = resources['tb:elasticache:ElastiCacheReplicaGroup']['accounts']
131+
redis_source_sgids = [
132+
container_sgs['accounts'].resources['sg'].id,
133+
container_sgs['accounts-celery'].resources['sg'].id,
134+
]
135+
for afc_name, afc in autoscaling_fargate_clusters.items():
136+
for container_name, lbs in afc.resources['container_security_groups'].items():
137+
redis_source_sgids.extend([sg.resources['sg'].id for sg in lbs.values()])
138+
redis = tb_pulumi.elasticache.ElastiCacheReplicationGroup(
139+
name=f'{project.name_prefix}-redis',
140+
project=project,
141+
source_sgids=redis_source_sgids,
142+
subnets=vpc.resources['subnets'],
143+
opts=pulumi.ResourceOptions(depends_on=[vpc, container_sgs['accounts']]),
144+
**redis_opts,
145+
)
146+
128147

129148
cloudflare_backend_record = cloudflare.Record(
130149
f'{project.name_prefix}-dns-backend',

0 commit comments

Comments
 (0)