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

implement tgtm suggestions to apigw custom domain sample #246

Merged
merged 6 commits into from
Jun 10, 2024

Conversation

HarshCasper
Copy link
Member

This PR:

  • Adds a passing CI badge to the sample.
  • Ensures the latest dependencies are used, except for the Serverless framework.
  • Adds a precheck target to the Makefile to ensure prerequisites are available.
  • Conceptualizes deployment and testing in a run.sh script with a --ci flag for smoke tests.
  • Updates the Node runtime to 18.x since newer runtimes (like 20.x) are locked behind a paywall.

Overall, this PR serves as a testbed to reach an agreement with TGTM, Support, and Engineering on establishing standard consistency across the sample. Please provide suggestions or thoughts to improve this further! :)

apigw-custom-domain/Makefile Outdated Show resolved Hide resolved
apigw-custom-domain/Makefile Show resolved Hide resolved
Serverless Domain Manager: Domain Name: test.example.com
Serverless Domain Manager: Target Domain: test.example.com
Serverless Domain Manager: Hosted Zone Id: Z2FDTNDATAQYW2
./run.sh

Choose a reason for hiding this comment

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

is there a reason to invoke this script directly, instead of using the make run command?

Copy link
Member Author

Choose a reason for hiding this comment

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

make run invokes the smoke test as well with it.

Copy link
Member Author

Choose a reason for hiding this comment

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

I envision that for local testing, we should rely more on shell scripts and use make targets for CI testing

Copy link
Contributor

Choose a reason for hiding this comment

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

I have the same comment as @bartsdev here.

For consistency and discoverability, I think there is value in sticking to make as the single entry point. For example, users get confused if they leverage make usage and don't see a run target (which seems like one of the most important ones). I am always looking out for a Makefile or write one. It helps me tremendously when dealing with so many different repositories, languages, and frameworks.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm in agreement with @bartsdev and @joe4dev here.

apigw-custom-domain/Makefile Show resolved Hide resolved
apigw-custom-domain/Makefile Outdated Show resolved Hide resolved
apigw-custom-domain/serverless.yml Show resolved Hide resolved
Copy link
Contributor

@steffyP steffyP left a comment

Choose a reason for hiding this comment

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

thanks for improving the sample, @HarshCasper 👍

Copy link
Contributor

@joe4dev joe4dev left a comment

Choose a reason for hiding this comment

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

Great initiative 🚀

My main comments are regarding:

  • ⚠️ Interpreting the exit code of bash script correctly when adopting them for CI
  • Migrating away from using make as entrypoint, but just for the run command
  • Supporting configuration options, such as regions, properly if we provide them as parameter

apigw-custom-domain/README.md Outdated Show resolved Hide resolved

## Prerequisites

* LocalStack
* [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli) with [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/getting-started/auth-token/)
Copy link
Contributor

Choose a reason for hiding this comment

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

Generally important to clarify Pro vs. non-Pro image 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Given @robertlcx comment — The prerequisites that are required for every sample would be moved to the root README while project-level READMEs would document any other prerequisite the particular sample needs.

Copy link
Contributor

Choose a reason for hiding this comment

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

Valid point @robertlcx 👍 In general, it's often a balance between easier maintenance/consistency while being self-contained enough. I think we need to add an explicit link to the parent README, otherwise the dependency list could be misleading here.

apigw-custom-domain/README.md Outdated Show resolved Hide resolved
apigw-custom-domain/README.md Outdated Show resolved Hide resolved
Serverless Domain Manager: Domain Name: test.example.com
Serverless Domain Manager: Target Domain: test.example.com
Serverless Domain Manager: Hosted Zone Id: Z2FDTNDATAQYW2
./run.sh
Copy link
Contributor

Choose a reason for hiding this comment

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

I have the same comment as @bartsdev here.

For consistency and discoverability, I think there is value in sticking to make as the single entry point. For example, users get confused if they leverage make usage and don't see a run target (which seems like one of the most important ones). I am always looking out for a Makefile or write one. It helps me tremendously when dealing with so many different repositories, languages, and frameworks.

@@ -0,0 +1,39 @@
#!/bin/bash

Copy link
Contributor

Choose a reason for hiding this comment

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

Bash scripts are hard to get right.

⚠️ If we want to use bash for CI testing, it is crucial to get the return value right because if it only considers the last command. If we have an echo "done" at the end, the CI never fails even if all other commands fail ⚡ .
That oneliner can help set -euo pipefail (if we want to keep it short and strict).

See "Writing robust scripts and debugging" in Bash best practices

👉 I recommend running shellcheck when using Bash script

Copy link
Contributor

Choose a reason for hiding this comment

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

All good points brought up by @joe4dev. I really like shellcheck too. Good practices.

Copy link

Choose a reason for hiding this comment

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

@joe4dev , do we have a bash script standard/best practices documented in our engineering docs? I'd even say that this is something we could add as pre-commit -> https://github.com/koalaman/shellcheck-precommit

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we have a documented standard for Bash.
Pre-commit hook + CI linting would be ideal moving forward 👍

apigw-custom-domain/run.sh Outdated Show resolved Hide resolved
apigw-custom-domain/run.sh Outdated Show resolved Hide resolved

if [[ "$1" == "--ci" ]]; then
invoke_endpoints
else
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Make supports such dry runs out of the box: https://unix.stackexchange.com/a/275843

‘-n’

‘--just-print’

‘--dry-run’

‘--recon’

apigw-custom-domain/serverless.yml Outdated Show resolved Hide resolved
apigw-custom-domain/run.sh Show resolved Hide resolved
apigw-custom-domain/Makefile Outdated Show resolved Hide resolved
apigw-custom-domain/Makefile Outdated Show resolved Hide resolved

## Prerequisites

* LocalStack
* [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli) with [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/getting-started/auth-token/)
Copy link
Contributor

Choose a reason for hiding this comment

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

Valid point @robertlcx 👍 In general, it's often a balance between easier maintenance/consistency while being self-contained enough. I think we need to add an explicit link to the parent README, otherwise the dependency list could be misleading here.

Copy link
Contributor

@joe4dev joe4dev left a comment

Choose a reason for hiding this comment

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

These are great improvements @HarshCasper. The user experience is so much better 👏👏👏 🚀

The run command is currently broken in non-CI mode and should be fixed, ideally by using the same code path to ensure it's tested. Otherwise, it's looking good.

I replied to some other comments, but they are not blocking. I think having an explicit "force pro" flag upon LocalStack start would be very useful.

Copy link

@bartsdev bartsdev left a comment

Choose a reason for hiding this comment

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

approved

@HarshCasper HarshCasper merged commit a20710d into master Jun 10, 2024
1 check passed
@HarshCasper HarshCasper deleted the apigw-custom-domain branch June 10, 2024 07:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants