Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add integration tests #69

Merged
merged 32 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
3537795
feat: add integration tests
vincentsarago Sep 5, 2023
f1c1d1f
add eoapi-cdk upgrade command and pip cache
emileten Sep 6, 2023
aab0acb
test commit, to revert
emileten Sep 6, 2023
d9749de
Revert "test commit, to revert"
emileten Sep 6, 2023
1300c4e
update workflow
emileten Sep 11, 2023
c47f6d6
update workflow to run when release happens, move tests here
emileten Sep 11, 2023
a63c909
instead of cloning the eoapi-template repo, copy the code here so tha…
emileten Sep 21, 2023
6ebc271
trailing wsp
emileten Sep 21, 2023
80f03ba
run action with push to try
emileten Sep 21, 2023
4ff82c2
move the trigger of integration tests to distribute, right before rel…
emileten Sep 27, 2023
eb20644
feat!: custom runtime for bootstrapper and custom runtimes from Docke…
emileten Oct 5, 2023
385ab1b
fix a couple bugs found in the first changes
emileten Oct 10, 2023
dbcada8
avoid maintaining custom interfaces for configurable lambda propertie…
emileten Oct 12, 2023
7573398
expose bootstrapper props in pgstacdatabase construct constructor
emileten Oct 12, 2023
926a6a1
merge database and boostrapper files to solve casting bug
emileten Oct 17, 2023
f725f28
bump and harmonize pypgstac to 0.7.10 across apps
emileten Oct 27, 2023
f48e334
bump cachetools
emileten Oct 27, 2023
7b62f2a
some changes to allow for less security
emileten Oct 27, 2023
7c75981
bump python to 3.11
emileten Oct 31, 2023
ccfce6b
change base image for bootstrapper to use python 311
emileten Oct 31, 2023
a7aea2b
fix linting issues
emileten Oct 31, 2023
9e886a2
Merge branch 'feat/custom-runtimes' into feat/add-integration-tests
emileten Oct 31, 2023
b973fbc
Merge branch 'main' into feat/add-integration-tests
emileten Feb 19, 2024
64e67b7
move integration tests to step before release, improve naming of work…
emileten Feb 19, 2024
c7904ef
lint
vincentsarago Feb 20, 2024
92b4bf9
fix moto requirement
vincentsarago Feb 20, 2024
97b5a32
test to fix deployment : try adding s3 endpoint and force allow publi…
emileten Feb 21, 2024
4ede0a5
lint and make lambda functions more configurable
emileten Feb 21, 2024
b4de035
moving deploy to a separate workflow
emileten Feb 21, 2024
92cec0d
remove useless dependencies in deployment tests, turn on pull request…
emileten Feb 21, 2024
b4fe0f6
when tearing down the infrastructure, synthesize the cloud formation …
emileten Feb 21, 2024
b08e8b3
update readmes and revive the artifact download in python distribution
emileten Feb 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
name: Deploy & Test Deployment

permissions:
id-token: write # required for requesting the JWT
contents: read # required for actions/checkout

on:
# run this workflow when the `Distribute` workflow completes
workflow_run:
workflows: [Distribute]
types: [completed]
# ... or manually.
workflow_dispatch:

# remove later
push:
branches:
- "feat/add-integration-tests"

jobs:
# run a job on a successful `Workflow` run.
on-successful-release:
runs-on: ubuntu-latest
env:
AWS_DEFAULT_REGION: ${{ secrets.AWS_DEFAULT_REGION_DEPLOY }}
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID_DEPLOY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY_DEPLOY }}


steps:

- name: Checkout repository # for runs after `Distribute`, pulling from main will always give the latest eoapi-cdk.
uses: actions/checkout@v3

- name: Set up python
uses: actions/setup-python@v2
with:
cache: pip

- name: Set up node
uses: actions/setup-node@v3
with:
node-version: '18'

- name: Install deployment environment
working-directory: integration_tests/cdk
run: |
python -m venv .deployment_venv
source .deployment_venv/bin/activate
pip install -r requirements.txt
pip install --upgrade eoapi-cdk # make sure to take the latest version of eoapi-cdk since we're integration-testing the newest release.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we testing the latest available version on pypi or the one in this repo?

It might be dangerous to test the version on pypi because there could be a lag from the push to the publication

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nice catch, I hadn't thought of the lag possibility...

However, I'd have to compile the typescript constructs locally to have access to the python modules.

How about setting up this workflow so that it waits (with a timeout) for the latest pypi to match for the latest github tag?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about setting up this workflow so that it waits (with a timeout) for the latest pypi to match for the latest github tag?

Sure, but then what will it means if the tests fails?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah 🤦‍♂️ doesn't make much sense indeed. We should be doing

build -> integration test -> release

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets see if @sharkinsspatial or @alukach have opinions

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be missing something from the CI logic, but one way to do it could be to add a job named integration-test here that reuses the package job's output. We then add integration-test as a dependency to both subsequent distribute-* jobs so that we're sure releases happen only if integration-tests ran.

Copy link
Contributor

@emileten emileten Sep 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI, to illustrate the idea, I pushed another commit (can always revert). See 4ff82c2

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@emileten I would recommend relying on the local python modules from the output of the TS build from the package output as you outlined in 4ff82c2.

npm install
deactivate

- name: Synthesize the stack
working-directory: integration_tests/cdk
run: |
source .deployment_venv/bin/activate
npx cdk synth --debug --all --require-approval never
deactivate

# deploys and grabs URLs from the output for later tests
- name: Deploy the stack
id: deploy_step
working-directory: integration_tests/cdk
run: |
source .deployment_venv/bin/activate
npx cdk deploy --ci --all --require-approval never
echo "ingestor_url=$(aws cloudformation describe-stacks --stack-name eoapi-template-demo-test-pgSTAC-infra --query "Stacks[0].Outputs[?starts_with(OutputKey, 'stacingestor')].OutputValue | [0]" --output text)" >> $GITHUB_OUTPUT
echo "stac_api_url=$(aws cloudformation describe-stacks --stack-name eoapi-template-demo-test-pgSTAC-infra --query "Stacks[0].Outputs[?starts_with(OutputKey, 'pgstacapi')].OutputValue | [0]" --output text)" >> $GITHUB_OUTPUT
echo "titiler_pgstac_api_url=$(aws cloudformation describe-stacks --stack-name eoapi-template-demo-test-pgSTAC-infra --query "Stacks[0].Outputs[?starts_with(OutputKey, 'titilerpgstac')].OutputValue | [0]" --output text)" >> $GITHUB_OUTPUT
deactivate

- name: Install test environment
working-directory: integration_tests/tests
run: |
python -m venv .tests_venv
source .tests_venv/bin/activate
pip install -r requirements.txt
deactivate

- name: Test the stack
working-directory: integration_tests/tests
env:
ingestor_url: ${{ steps.deploy_step.outputs.ingestor_url }}
stac_api_url: ${{ steps.deploy_step.outputs.stac_api_url }}
titiler_pgstac_api_url: ${{ steps.deploy_step.outputs.titiler_pgstac_api_url }}
run: |
source .tests_venv/bin/activate
pytest eoapi_tests
deactivate

- name: Always tear down the stack
if: always()
working-directory: integration_tests/cdk
run: |
vincentsarago marked this conversation as resolved.
Show resolved Hide resolved
source .deployment_venv/bin/activate
npx cdk destroy --ci --all --force
deactivate
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ docs
__pycache__
.venv
.tox
tests/*.egg*
tests/*venv*
tests/__pycache__
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ Versioning is automatically handled via [Conventional Commits](https://www.conve
_Warning_: If you rebase `main`, you must ensure that the commits referenced by tags point to commits that are within the `main` branch. If a commit references a commit that is no longer on the `main` branch, Semantic Release will fail to detect the correct version of the project. [More information](https://github.com/semantic-release/semantic-release/issues/1121#issuecomment-517945233).


## Tests

Each new release triggers an integration test against a running deployment that uses the newly releases constructs. See the corresponding [github workflow](https://github.com/developmentseed/eoapi-cdk/blob/main/.github/workflows/deploy.yaml) and the [tests definition](https://github.com/developmentseed/eoapi-cdk/blob/main/tests).
49 changes: 49 additions & 0 deletions integration_tests/cdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
This is a non-forked version of [eoapi-template](https://github.com/developmentseed/eoapi-template).

# Deployment CDK code for eoapi-cdk integration tests

This is a wrapper CDK code that provides the `eoapi-cdk` deployment to run integration tests on the latest releases of the `eoapi-cdk` constructs.

## Requirements

- python
- docker
- node
- AWS credentials environment variables configured to point to an account.
- **Optional** a `config.yaml` file to override the default deployment settings defined in `config.py`.

## Installation

Install python dependencies with

```
python -m venv .venv
source .venv/bin/activate
python -m pip install -r requirements.txt
```

Note that `eoapi-cdk` isn't pinned, so that the latest version is always installed. Also install node dependencies with

```
npm install
```

Verify that the `cdk` CLI is available. Since `aws-cdk` is installed as a local dependency, you can use the `npx` node package runner tool, that comes with `npm`.

```
npx cdk --version
```

## Deployment

First, synthesize the app

```
npx cdk synth --all
```

Then, deploy

```
npx cdk deploy --all --require-approval never
```
17 changes: 17 additions & 0 deletions integration_tests/cdk/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from aws_cdk import App

from config import build_app_config
from eoapi_template import pgStacInfra, vpc

app = App()

app_config = build_app_config()

vpc_stack = vpc.VpcStack(scope=app, app_config=app_config)

pgstac_infra_stack = pgStacInfra.pgStacInfraStack(
scope=app,
vpc=vpc_stack.vpc,
app_config=app_config,
)
app.synth()
32 changes: 32 additions & 0 deletions integration_tests/cdk/cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"app": "python3 app.py",
"watch": {
"include": [
"**"
],
"exclude": [
"README.md",
"cdk*.json",
"requirements*.txt",
"source.bat",
"**/*.pyc",
"**/*.tmp",
"**/__pycache__",
"tests",
"scripts",
"*venv"
]
},
"context": {
"@aws-cdk/aws-apigateway:usagePlanKeyOrderInsensitiveId": true,
"@aws-cdk/core:stackRelativeExports": true,
"@aws-cdk/aws-rds:lowercaseDbIdentifier": true,
"@aws-cdk/aws-lambda:recognizeVersionProps": true,
"@aws-cdk/aws-cloudfront:defaultSecurityPolicyTLSv1.2_2021": true,
"@aws-cdk-containers/ecs-service-extensions:enableDefaultLogDriver": true,
"@aws-cdk/core:target-partitions": [
"aws",
"aws-cn"
]
}
}
Loading
Loading