Contributions are welcome!
As a general advice it is always a good idea to raise an issue before creating a new pull request. This ensures that we don't have to reject pull requests that are not aligning with our roadmap and not wasting your valuable time.
The project is a monorepo which contains both the Terraform module and the code used by AWS Lambda for image processing written in Node.js (called worker component).
For the Terraform part you should have installed:
- Terraform CLI at 0.13+
For the worker component you should have installed:
Note: You should not make changes to the documentation of the Requirements, Providers, Inputs and Outputs sections in the
README.md
when contributing. The values there are auto generated by a GitHub action task once a PR is merged.
We use a GitHub Action to make sure that the committed code is properly formatted. Before submitting a PR, you should make sure that the code is properly formatted.
You can do this by running the Terraform fmt
command in the root of the repository:
terraform fmt -recursive
After cloning the repository, run yarn
to fetch its dependencies.
We use a GitHub Action to make sure that the committed code is properly formatted. Before submitting a PR, you should make sure that the code is properly formatted.
You can do this by running the fix:prettier
command from the root of the repository:
yarn fix:prettier
Automatic testing is only done for the worker component written in Node.js. The Terraform module is not covered by automatic tests.
Since the Terraform module itself is not covered by automatic tests, testing has to be done manually.
The repository contains some examples in the examples/*
folder, that can be used to run a quick acceptance test on your own AWS account.
You may need to change a few settings in the main.tf
file in the root of the example.
To use the local development version instead of downloading it from the Terraform registry you have to replace the source to the local path of the module:
module "next_image_optimizer" {
- source = "milliHQ/next-js-image-optimization/aws"
+ source = "../.."
...
}
Instead of downloading the worker component from npm you can also specify to use a local version (Make sure that you have built it before using!)
module "next_image_optimizer" {
source = "../.."
...
+ debug_use_local_packages = true
}
The end-to-end testing is only used for testing the worker component. A local environment of AWS Lambda is created for this to simulate a execution under the same conditions as it would run in a AWS data center.
In order to run the e2e-tests locally, you need to install the following software:
- Docker Desktop + Docker Compose
(Docker Compose comes bundled with Docker Desktop on MacOS and Windows) - AWS SAM CLI
You should check after install if they are available from your command-line:
docker --version
# > Docker version 20.10.2, build 2291f61
docker-compose --version
# > docker-compose version 1.27.4, build 40524192
sam --version
# > SAM CLI, version 1.17.0
Before running the e2e tests you should create a production-ready build that is used to execute the tests. The build is created inside a Docker build image since some binaries are required for the Lambda execution environment that cannot be installed otherwise.
Creating the production build is done by running the following task in the root of the project:
yarn build:local
When the task finished sucsessfully, you should see a new file dist.zip
in the lib/
subdirectory.
Before running the e2e-tests, make sure that the local S3 emulator from docker-compose is running. From the root of the project run:
docker-compose up -d
After that you should be able to execute the e2e-tests locally by running the test:e2e
task:
yarn test:e2e