Skip to content

Commit

Permalink
Merge pull request #212 from NASA-IMPACT/develop
Browse files Browse the repository at this point in the history
Release base infrastructure and dashboard postgres schema fixes
  • Loading branch information
anayeaye authored Aug 15, 2023
2 parents e0f6572 + a885d0f commit f93c2e2
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 53 deletions.
23 changes: 19 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,27 @@ To retrieve the variables for a stage that has been previously deployed, the sec
### Deploying to the cloud

#### Install pre-requisites
#### Install deployment pre-requisites
- [Node](https://nodejs.org/)
- [NVM](https://github.com/nvm-sh/nvm#node-version-manager---)
- [jq](https://jqlang.github.io/jq/) (used for exporting environment variable secrets to `.env` in [scripts/sync-env-local.sh](/scripts/sync-env-local.sh))

These can be installed with [homebrew](https://brew.sh/) on MacOS
```
brew install node
brew install nvm
brew install jq
```

#### Virtual environment example
```
python3 -m venv .venv
source .venv/bin/activate
```

#### Install requirements
```bash
nvm install 17
nvm use 17
node --version
nvm use --lts
npm install --location=global aws-cdk
python3 -m pip install --upgrade pip
python3 -m pip install -e ".[dev,deploy,test]"
Expand Down
52 changes: 5 additions & 47 deletions database/runtime/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ def create_collection_search_functions(cursor) -> None:

def create_collection_summaries_functions(cursor) -> None:
"""
Functions to summarize datetimes and raster statistics for 'default' collections of items with single band COG assets
Functions to summarize datetimes and raster statistics for 'default' collections of items
"""

periodic_datetime_summary_sql = """
Expand All @@ -264,7 +264,7 @@ def create_collection_summaries_functions(cursor) -> None:
SELECT to_jsonb(
array[
to_char(min(datetime) at time zone 'Z', 'YYYY-MM-DD"T"HH24:MI:SS"Z"'),
to_char(max(datetime) at time zone 'Z', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')
to_char(max(end_datetime) at time zone 'Z', 'YYYY-MM-DD"T"HH24:MI:SS"Z"')
])​
FROM items WHERE collection=$1;
;
Expand All @@ -287,23 +287,6 @@ def create_collection_summaries_functions(cursor) -> None:
"""
cursor.execute(sql.SQL(distinct_datetime_summary_sql))

cog_default_summary_sql = """
CREATE OR REPLACE FUNCTION dashboard.cog_default_summary(id text) RETURNS jsonb
LANGUAGE sql
IMMUTABLE PARALLEL SAFE
SET search_path TO 'pgstac', 'public'
AS $function$
SELECT jsonb_build_object(
'min', min((items."content"->'assets'->'cog_default'->'raster:bands'-> 0 ->'statistics'->>'minimum')::float),
'max', max((items."content"->'assets'->'cog_default'->'raster:bands'-> 0 ->'statistics'->>'maximum')::float)
)
FROM items WHERE collection=$1;
;
$function$
;
"""
cursor.execute(sql.SQL(cog_default_summary_sql))

update_collection_default_summaries_sql = """
CREATE OR REPLACE FUNCTION dashboard.update_collection_default_summaries(id text)
RETURNS void
Expand All @@ -320,13 +303,6 @@ def create_collection_summaries_functions(cursor) -> None:
THEN dashboard.periodic_datetime_summary(collections.id)
ELSE dashboard.discrete_datetime_summary(collections.id)
END
),
'cog_default', (
CASE
WHEN collections."content"->'item_assets' ? 'cog_default'
THEN dashboard.cog_default_summary(collections.id)
ELSE NULL
END
)
)
)
Expand All @@ -343,27 +319,9 @@ def create_collection_summaries_functions(cursor) -> None:
LANGUAGE sql
SET search_path TO 'pgstac', 'public'
AS $function$
UPDATE collections SET
"content" = "content" ||
jsonb_build_object(
'summaries', jsonb_build_object(
'datetime', (
CASE
WHEN (collections."content"->>'dashboard:is_periodic')::boolean
THEN dashboard.periodic_datetime_summary(collections.id)
ELSE dashboard.discrete_datetime_summary(collections.id)
END
),
'cog_default', (
CASE
WHEN collections."content"->'item_assets' ? 'cog_default'
THEN dashboard.cog_default_summary(collections.id)
ELSE NULL
END
)
)
)
WHERE collections."content" ?| array['item_assets', 'dashboard:is_periodic']
SELECT dashboard.update_collection_default_summaries(collections.id)
FROM collections
WHERE collections."content" ?| array['dashboard:is_periodic']
;
$function$
;
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ services:
database:
container_name: veda.db
platform: linux/amd64
image: ghcr.io/stac-utils/pgstac:v0.7.6
image: ghcr.io/stac-utils/pgstac:v0.7.10
environment:
- POSTGRES_USER=username
- POSTGRES_PASSWORD=password
Expand Down
18 changes: 17 additions & 1 deletion standalone_base_infrastructure/network_construct.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def __init__(
)

nat_provider_instance = aws_ec2.NatProvider.instance(
instance_type=aws_ec2.InstanceType("t3.nano")
instance_type=aws_ec2.InstanceType("t3.nano"),
)

vpc = aws_ec2.Vpc(
Expand All @@ -40,6 +40,22 @@ def __init__(
nat_gateways=base_settings.vpc_nat_gateways,
)

nat_sg = nat_provider_instance.security_group

# Allow all outbound traffic
nat_sg.add_egress_rule(
aws_ec2.Peer.any_ipv4(),
aws_ec2.Port.all_traffic(),
"Allow all outbound traffic",
)

# Allow inbound traffic from the VPC's CIDR
nat_sg.add_ingress_rule(
aws_ec2.Peer.ipv4(vpc.vpc_cidr_block),
aws_ec2.Port.all_traffic(),
"Allow inbound traffic from the VPCs CIDR block",
)

vpc_endpoints = {
"secretsmanager": aws_ec2.InterfaceVpcEndpointAwsService.SECRETS_MANAGER,
"cloudwatch-logs": aws_ec2.InterfaceVpcEndpointAwsService.CLOUDWATCH_LOGS,
Expand Down

0 comments on commit f93c2e2

Please sign in to comment.