Skip to content

Commit bb24ded

Browse files
authored
chore: simplify deployment (#96)
* PR template improvement readme * add vector, simplify deployment files * use short commit sha to name test deployment stacks to avoid concurrency problems * update package-lock.json to fix cloud formation bug
1 parent d96cb0e commit bb24ded

File tree

9 files changed

+159
-131
lines changed

9 files changed

+159
-131
lines changed

.github/pull_request_template.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
## :warning: Checklist if your PR is changing anything else than documentation
2-
- [ ] The manual deployment workflow ran successfully
2+
- [ ] Posted the link to a successful manually triggered deployment workflow (successful including the resources destruction)
3+
4+
## Merge request description

.github/workflows/deploy.yaml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,16 @@ jobs:
4444
deactivate
4545
cd -
4646
47+
# use short commit SHA to name stacks
48+
- uses: benjlevesque/[email protected]
49+
id: short-sha
50+
with:
51+
length: 6
4752

4853
- name: Deploy test stack
4954
id: deploy_step
55+
env:
56+
PROJECT_ID: ${{ steps.short-sha.outputs.sha }}
5057
run: |
5158
source .deployment_venv/bin/activate
5259
@@ -61,6 +68,8 @@ jobs:
6168
6269
- name: Tear down any infrastructure
6370
if: always()
71+
env:
72+
PROJECT_ID: ${{ steps.short-sha.outputs.sha }}
6473
run: |
6574
cd integration_tests/cdk
6675
# run this only if we find a 'cdk.out' directory, which means there might be things to tear down

integration_tests/cdk/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
# Deployment CDK code for eoapi-cdk deployment tests
33

4-
This is a wrapper CDK code that is used to test a deployment of the `eoapi-cdk` constructs before a release happens.
4+
This is a wrapper CDK code that is used to test a deployment of the `eoapi-cdk` constructs.
55

66
## Requirements
77

integration_tests/cdk/app.py

Lines changed: 142 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,154 @@
1-
from aws_cdk import App
1+
from config import build_app_config, AppConfig
2+
from aws_cdk import (
3+
Stack,
4+
aws_ec2,
5+
aws_rds,
6+
App,
7+
RemovalPolicy
8+
)
9+
from constructs import Construct
10+
from eoapi_cdk import (
11+
PgStacApiLambda,
12+
PgStacDatabase,
13+
TitilerPgstacApiLambda,
14+
TiPgApiLambda,
15+
)
16+
17+
18+
class VpcStack(Stack):
19+
def __init__(self, scope: Construct, app_config: AppConfig, id: str, **kwargs) -> None:
20+
super().__init__(
21+
scope,
22+
id=id,
23+
tags=app_config.tags,
24+
**kwargs
25+
)
26+
27+
self.vpc = aws_ec2.Vpc(
28+
self,
29+
"vpc",
30+
subnet_configuration=[
31+
aws_ec2.SubnetConfiguration(
32+
name="ingress", subnet_type=aws_ec2.SubnetType.PUBLIC, cidr_mask=24
33+
),
34+
]
35+
)
36+
37+
self.vpc.add_interface_endpoint(
38+
"SecretsManagerEndpoint",
39+
service=aws_ec2.InterfaceVpcEndpointAwsService.SECRETS_MANAGER,
40+
)
41+
42+
self.vpc.add_interface_endpoint(
43+
"CloudWatchEndpoint",
44+
service=aws_ec2.InterfaceVpcEndpointAwsService.CLOUDWATCH_LOGS,
45+
)
46+
47+
self.vpc.add_gateway_endpoint(
48+
"S3", service=aws_ec2.GatewayVpcEndpointAwsService.S3
49+
)
50+
51+
self.export_value(
52+
self.vpc.select_subnets(subnet_type=aws_ec2.SubnetType.PUBLIC)
53+
.subnets[0]
54+
.subnet_id
55+
)
56+
self.export_value(
57+
self.vpc.select_subnets(subnet_type=aws_ec2.SubnetType.PUBLIC)
58+
.subnets[1]
59+
.subnet_id
60+
)
61+
62+
63+
class pgStacInfraStack(Stack):
64+
def __init__(
65+
self,
66+
scope: Construct,
67+
vpc: aws_ec2.Vpc,
68+
id: str,
69+
app_config: AppConfig,
70+
**kwargs,
71+
) -> None:
72+
super().__init__(
73+
scope,
74+
id=id,
75+
tags=app_config.tags,
76+
**kwargs,
77+
)
78+
79+
pgstac_db = PgStacDatabase(
80+
self,
81+
"pgstac-db",
82+
vpc=vpc,
83+
engine=aws_rds.DatabaseInstanceEngine.postgres(
84+
version=aws_rds.PostgresEngineVersion.VER_14
85+
),
86+
vpc_subnets=aws_ec2.SubnetSelection(
87+
subnet_type=aws_ec2.SubnetType.PUBLIC,
88+
),
89+
allocated_storage=app_config.db_allocated_storage,
90+
instance_type=aws_ec2.InstanceType(app_config.db_instance_type),
91+
removal_policy=RemovalPolicy.DESTROY
92+
)
93+
94+
pgstac_db.db.connections.allow_default_port_from_any_ipv4()
95+
96+
PgStacApiLambda(
97+
self,
98+
"pgstac-api",
99+
api_env={
100+
"NAME": app_config.build_service_name("STAC API"),
101+
"description": f"{app_config.stage} STAC API",
102+
},
103+
db=pgstac_db.db,
104+
db_secret=pgstac_db.pgstac_secret
105+
)
106+
107+
TitilerPgstacApiLambda(
108+
self,
109+
"titiler-pgstac-api",
110+
api_env={
111+
"NAME": app_config.build_service_name("titiler pgSTAC API"),
112+
"description": f"{app_config.stage} titiler pgstac API",
113+
},
114+
db=pgstac_db.db,
115+
db_secret=pgstac_db.pgstac_secret,
116+
buckets=[],
117+
lambda_function_options={
118+
"allow_public_subnet": True,
119+
},
120+
)
121+
122+
TiPgApiLambda(
123+
self,
124+
"tipg-api",
125+
db=pgstac_db.db,
126+
db_secret=pgstac_db.pgstac_secret,
127+
api_env={
128+
"NAME": app_config.build_service_name("tipg API"),
129+
"description": f"{app_config.stage} tipg API",
130+
},
131+
lambda_function_options={
132+
"allow_public_subnet": True,
133+
},
134+
)
2135

3-
from config import build_app_config
4-
from eoapi_template import pgStacInfra, vpc
5136

6137
app = App()
7138

8139
app_config = build_app_config()
9140

10-
vpc_stack = vpc.VpcStack(scope=app, app_config=app_config)
141+
vpc_stack_id = f"vpc{app_config.project_id}"
142+
143+
vpc_stack = VpcStack(scope=app, app_config=app_config, id=vpc_stack_id)
11144

12-
pgstac_infra_stack = pgStacInfra.pgStacInfraStack(
145+
pgstac_infra_stack_id = f"pgstac{app_config.project_id}"
146+
147+
pgstac_infra_stack = pgStacInfraStack(
13148
scope=app,
14149
vpc=vpc_stack.vpc,
15150
app_config=app_config,
151+
id=pgstac_infra_stack_id
16152
)
153+
17154
app.synth()

integration_tests/cdk/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AppConfig(BaseSettings):
1414
description="AWS account ID"
1515
)
1616
project_id: str = pydantic.Field(
17-
description="Project ID", default="eoapi-cdk"
17+
description="Project ID", default="eoapicdk"
1818
)
1919
stage: str = pydantic.Field(description="Stage of deployment", default="test")
2020
# because of its validator, `tags` should always come after `project_id` and `stage`

integration_tests/cdk/eoapi_template/__init__.py

Whitespace-only changes.

integration_tests/cdk/eoapi_template/pgStacInfra.py

Lines changed: 0 additions & 71 deletions
This file was deleted.

integration_tests/cdk/eoapi_template/vpc.py

Lines changed: 0 additions & 49 deletions
This file was deleted.

integration_tests/cdk/package-lock.json

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)