Skip to content

Commit

Permalink
Add mcp-production-deployment
Browse files Browse the repository at this point in the history
Also, add HLS_LANDSAT_SNS_TOPIC_ENABLED env var (default: "true") to allow disabling of trigger.
  • Loading branch information
chuckwondo committed Feb 12, 2024
1 parent f7c04b1 commit b4072dd
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 15 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/mcp_production_deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: MCP production deployment

on:
release:
types: [ published ]

env:
AWS_DEFAULT_REGION: us-west-2

# See https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/configuring-openid-connect-in-amazon-web-services#updating-your-github-actions-workflow
permissions:
id-token: write # required for requesting the JWT
contents: read # required for actions/checkout

jobs:
unit-tests:
runs-on: ubuntu-20.04
strategy:
matrix:
python: [3.8]
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install Tox
run: pip install tox
- name: Run Tox test environment
# Run tox using the version of Python in `PATH`
run: tox -e py
mcp-production-deployment:
strategy:
matrix:
python: [3.8]
runs-on: ubuntu-20.04
needs: [unit-tests]
environment:
name: mcp-production
steps:
- uses: actions/checkout@v4
- name: Setup Python
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python }}
- name: Install tox
run: pip install tox
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v3
with:
role-to-assume: ${{ vars.AWS_ROLE_TO_ASSUME_ARN }}
role-session-name: ${{ github.actor }}
aws-region: us-west-2
- name: Convert secrets to environment variables
env:
SECRETS_JSON: ${{ toJson(secrets) }}
run: |
while read -rd $'' line; do
echo "$line" >> $GITHUB_ENV
done < <(
jq -r <<<"$SECRETS_JSON" 'to_entries|map("\(.key)=\(.value)\u0000")[]'
)
- name: Convert vars to environment variables
env:
VARS_JSON: ${{ toJson(vars) }}
run: |
while read -rd $'' line; do
echo "$line" >> $GITHUB_ENV
done < <(
jq -r <<<"$VARS_JSON" 'to_entries|map("\(.key)=\(.value)\u0000")[]'
)
- name: Deploy with tox
run: tox -v -e dev -r -- deploy --require-approval never
- name: Run DB setup
run: |
setupdb=$(aws cloudformation describe-stacks \
--stack-name $HLS_STACKNAME \
--query "Stacks[0].Outputs[?OutputKey=='setupdbexport'].OutputValue" \
--output=text
)
aws lambda invoke --function-name=$setupdb response.json
34 changes: 19 additions & 15 deletions stack/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ def getenv(key, default):
LANDSAT_SNS_TOPIC = getenv(
"HLS_LANDSAT_SNS_TOPIC", "arn:aws:sns:us-west-2:673253540267:public-c2-notify-v2"
)
LANDSAT_SNS_TOPIC_ENABLED = (
getenv("HLS_LANDSAT_SNS_TOPIC_ENABLED", "true").lower() == "true"
)

DOWNLOADER_FUNCTION_ARN = getenv("HLS_DOWNLOADER_FUNCTION_ARN", None)
LAADS_BUCKET_BOOTSTRAP = getenv(
Expand Down Expand Up @@ -752,23 +755,24 @@ def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
input_bucket=self.sentinel_input_bucket_historic,
)

self.landsat_sns_topic = aws_sns.Topic.from_topic_arn(
self, "LandsatSNSTopc", topic_arn=LANDSAT_SNS_TOPIC
)
if LANDSAT_SNS_TOPIC_ENABLED:
self.landsat_sns_topic = aws_sns.Topic.from_topic_arn(
self, "LandsatSNSTopc", topic_arn=LANDSAT_SNS_TOPIC
)

self.landsat_historic_sns_topic = aws_sns.Topic.from_topic_arn(
self, "LandsatHistoricSNSTopic", topic_arn=LANDSAT_HISTORIC_SNS_TOPIC
)
self.landsat_step_function_trigger = StepFunctionTrigger(
self,
"LandsatStepFunctionTrigger",
state_machine=self.landsat_step_function.state_machine.ref,
code_file="execute_landsat_step_function.py",
timeout=180,
input_sns=self.landsat_sns_topic,
layers=[self.hls_lambda_layer],
)

self.landsat_step_function_trigger = StepFunctionTrigger(
self,
"LandsatStepFunctionTrigger",
state_machine=self.landsat_step_function.state_machine.ref,
code_file="execute_landsat_step_function.py",
timeout=180,
input_sns=self.landsat_sns_topic,
layers=[self.hls_lambda_layer],
)
# self.landsat_historic_sns_topic = aws_sns.Topic.from_topic_arn(
# self, "LandsatHistoricSNSTopic", topic_arn=LANDSAT_HISTORIC_SNS_TOPIC
# )

# self.landsat_step_function_historic_trigger = StepFunctionTrigger(
# self,
Expand Down

0 comments on commit b4072dd

Please sign in to comment.