Skip to content

Commit

Permalink
Merge commit '872be79ec5117572af915758f00892130b5f64f7' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Nov 28, 2021
2 parents ce37923 + 872be79 commit af4f6e8
Show file tree
Hide file tree
Showing 20 changed files with 103 additions and 223 deletions.
11 changes: 8 additions & 3 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ on:
jobs:
build:
runs-on: ubuntu-latest
container: registry.gitlab.com/dealmore/dealmore-build-images/lambda:nodejs14.x

container: public.ecr.aws/sam/build-nodejs14.x:latest
steps:
- name: Install yarn
run: npm install --global yarn@1.22.17

- uses: actions/checkout@v2

- name: Cache
Expand All @@ -38,7 +40,7 @@ jobs:

test-integration:
runs-on: ubuntu-latest
container: registry.gitlab.com/dealmore/dealmore-build-images/lambda:nodejs14.x
container: public.ecr.aws/sam/build-nodejs14.x:latest

services:
s3:
Expand All @@ -48,6 +50,9 @@ jobs:
MINIO_SECRET_KEY: testtest

steps:
- name: Install yarn
run: npm install --global yarn@1.22.17

- uses: actions/checkout@v2

- name: Cache
Expand Down
15 changes: 12 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,18 @@ jobs:
with:
fetch-depth: 0

- uses: dealmore/gh-action-release-branch@v1.1.0
- uses: milliHQ/gh-action-release-branch@v2.0.0
with:
upstream-branch: main
release-branch: release
release-tag: ${{ github.event.inputs.tag }}
exclude: '["lib/**/*", "test/**/*", "package.json", "yarn.lock"]'
exclude: |
.vscode/**/*
lib/**/*
scripts/**/*
test/**/*
docker-compose.yml
buildimage.Dockerfile
jest.config.js
package.json
tsconfig.json
yarn.lock
33 changes: 0 additions & 33 deletions .vscode/launch.json

This file was deleted.

39 changes: 39 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,44 @@
# Changelog

## 12.0.0 (November 28, 2021)

This release introduces a new package called [Pixel](https://github.com/milliHQ/pixel) that abstracts the image optimization stuff and makes it usable with platforms other than AWS Lambda.
We plan to offer multiple flavors of it, like express middleware or docker images.

⚠️ **Breaking Changes** ⚠️

We have [removed](https://github.com/milliHQ/terraform-aws-next-js-image-optimization/issues/78) the output variable `cloudfront_origin_image_optimizer` that was deprecated since the v11.0.0 release.
To upgrade, please use the output variable `cloudfront_origin` from now on.

E.g. when using the ["With existing CloudFront distribution example"](https://registry.terraform.io/modules/milliHQ/next-js-image-optimization/aws/latest/examples/with-existing-cloudfront) you should make the following changes:

```diff
module "next_image_optimizer" {
source = "milliHQ/next-js-image-optimization/aws"
...
}

resource "aws_cloudfront_distribution" "distribution" {
...

dynamic "origin" {
- for_each = [module.next_image_optimizer.cloudfront_origin_image_optimizer]
+ for_each = [module.next_image_optimizer.cloudfront_origin]
...
}
}
```

---

- Uses Image Optimizer module of [Next.js 12.0.0](https://github.com/vercel/next.js/releases/tag/v12.0.0) ([#80](https://github.com/milliHQ/terraform-aws-next-js-image-optimization/pull/80))
- Add support for AVIF ([#73](https://github.com/milliHQ/terraform-aws-next-js-image-optimization/issues/73), [#92](https://github.com/milliHQ/terraform-aws-next-js-image-optimization/pull/92))
- Fixes "Error while trying to add new domain" bug ([#68](https://github.com/milliHQ/terraform-aws-next-js-image-optimization/issues/68), [#69](https://github.com/milliHQ/terraform-aws-next-js-image-optimization/pull/69))
- Remove random strings from resource names ([#72](https://github.com/milliHQ/terraform-aws-next-js-image-optimization/issues/72), [#77](https://github.com/milliHQ/terraform-aws-next-js-image-optimization/pull/77))
- Bump sharp from 0.29.1 to 0.29.3 ([#79](https://github.com/milliHQ/terraform-aws-next-js-image-optimization/pull/79), [#85](https://github.com/milliHQ/terraform-aws-next-js-image-optimization/pull/85))
- Remove deprecated output `cloudfront_origin_image_optimizer` ([#78](https://github.com/milliHQ/terraform-aws-next-js-image-optimization/issues/78), [#82](https://github.com/milliHQ/terraform-aws-next-js-image-optimization/pull/82))
- Remove referer header from cache key when S3 is used ([#87](https://github.com/milliHQ/terraform-aws-next-js-image-optimization/issues/87), [#91](https://github.com/milliHQ/terraform-aws-next-js-image-optimization/pull/91))

## 11.1.2 (September 14, 2021)

- Uses Image Optimizer module of [Next.js 11.1.2](https://github.com/vercel/next.js/releases/tag/v11.1.2) ([#63](https://github.com/milliHQ/terraform-aws-next-js-image-optimization/pull/63))
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,12 @@ Then rebuild and redeploy your Next.js application to make use of the changed co
|------|---------|
| terraform | >= 0.13 |
| aws | >= 3.43.0 |
| random | >= 2.3.0 |

## Providers

| Name | Version |
|------|---------|
| aws | >= 3.43.0 |
| random | >= 2.3.0 |

## Inputs

Expand All @@ -129,16 +127,17 @@ Then rebuild and redeploy your Next.js application to make use of the changed co
| cloudfront\_origin\_shield\_region | Override the region choosen for the CloudFront origin shield. Use `auto` to automatically determine the optimal region. | `string` | `"auto"` | no |
| cloudfront\_price\_class | Price class for the CloudFront distribution. One of PriceClass\_All, PriceClass\_200, PriceClass\_100. | `string` | `"PriceClass_100"` | no |
| debug\_use\_local\_packages | (Debug) Use local packages instead of downloading them from npm. | `bool` | `false` | no |
| deployment\_name | Identifier for the deployment group (alphanumeric characters, underscores, hyphens, slashes, hash signs and dots are allowed). | `string` | `"tf-next-image"` | no |
| deployment\_name | Identifier for the deployment group (only lowercase alphanumeric characters and hyphens are allowed). | `string` | `"tf-next-image"` | no |
| lambda\_attach\_policy\_json | Controls whether lambda\_policy\_json should be added to IAM role for Lambda function. | `bool` | `false` | no |
| lambda\_memory\_size | Amount of memory in MB the worker Lambda Function can use. Valid value between 128 MB to 10,240 MB, in 1 MB increments. | `number` | `1024` | no |
| lambda\_policy\_json | Additional policy document as JSON to attach to the Lambda Function role. | `string` | `""` | no |
| lambda\_role\_permissions\_boundary | ARN of IAM policy that scopes aws\_iam\_role access for the lambda. | `string` | `null` | no |
| lambda\_timeout | Max amount of time the worker Lambda Function has to return a response in seconds. Should not be more than 30 (Limited by API Gateway). | `number` | `30` | no |
| next\_image\_device\_sizes | Allowed device sizes that should be used for image optimization. | `list(number)` | `null` | no |
| next\_image\_domains | Allowed origin domains that can be used for fetching images. | `list(string)` | `[]` | no |
| next\_image\_formats | If the Accept head matches more than one of the configured formats, the first match in the array is used. Therefore, the array order matters. If there is no match, the Image Optimization API will fallback to the original image's format. | `list(string)` | <pre>[<br> "image/webp"<br>]</pre> | no |
| next\_image\_image\_sizes | Allowed image sizes that should be used for image optimization. | `list(number)` | `null` | no |
| next\_image\_version | Next.js version from where you want to use the image optimizer from. Supports semver ranges. | `string` | `"11.1.2"` | no |
| next\_image\_version | Next.js version from where you want to use the image optimizer from. Supports semver ranges. | `string` | `"12.0.0"` | no |
| source\_bucket\_id | When your static files are deployed to a Bucket (e.g. with Terraform Next.js) the optimizer can pull the source from the bucket rather than over the internet. | `string` | `null` | no |
| tags | Tag metadata to label AWS resources that support tags. | `map(string)` | `{}` | no |

Expand All @@ -152,7 +151,6 @@ Then rebuild and redeploy your Next.js application to make use of the changed co
| cloudfront\_hosted\_zone\_id | Zone id of the internal CloudFront distribution. |
| cloudfront\_origin | Predefined CloudFront origin. Can be used to embed the image optimizer into an existing CloudFront resource. |
| cloudfront\_origin\_id | Id of the custom origin used for image optimization. |
| cloudfront\_origin\_image\_optimizer | Deprecated, please use cloudfront\_origin instead. |
| cloudfront\_origin\_request\_policy\_id | Request policy id used for image optimization. |

<!--- END_TF_DOCS --->
Expand All @@ -172,6 +170,11 @@ Please note that we only publish versions `>=10.0.5`, for a full list of availab
Contributions are welcome!
If you want to improve this module, please take a look at our [contributing guide](https://github.com/milliHQ/terraform-aws-next-js-image-optimization/blob/main/CONTRIBUTING.md).

## About

This project is maintained by [milliVolt infrastructure](https://milli.is).
We build custom infrastructure solutions for any cloud provider.

## License

Apache-2.0 - see [LICENSE](https://github.com/milliHQ/terraform-aws-next-js-image-optimization/blob/main/LICENSE) for details.
Expand Down
15 changes: 0 additions & 15 deletions buildimage.Dockerfile

This file was deleted.

18 changes: 0 additions & 18 deletions docker-compose.yml

This file was deleted.

Binary file modified docs/assets/architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion examples/with-existing-cloudfront/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ resource "aws_cloudfront_distribution" "distribution" {
# This is a generic dynamic to create an origin
dynamic "origin" {
for_each = [module.next_image_optimizer.cloudfront_origin_image_optimizer]
for_each = [module.next_image_optimizer.cloudfront_origin]
content {
domain_name = origin.value["domain_name"]
Expand Down
2 changes: 1 addition & 1 deletion examples/with-existing-cloudfront/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ resource "aws_cloudfront_distribution" "distribution" {

# This is a generic dynamic to create an origin
dynamic "origin" {
for_each = [module.next_image_optimizer.cloudfront_origin_image_optimizer]
for_each = [module.next_image_optimizer.cloudfront_origin]

content {
domain_name = origin.value["domain_name"]
Expand Down
4 changes: 2 additions & 2 deletions examples/with-next-js/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
},
"dependencies": {
"next": "latest",
"react": "^16.13.1",
"react-dom": "^16.13.1"
"react": "latest",
"react-dom": "latest"
},
"license": "MIT"
}
6 changes: 0 additions & 6 deletions jest.config.js

This file was deleted.

39 changes: 19 additions & 20 deletions main.tf
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
###############
# Worker Lambda
###############

module "lambda_content" {
source = "milliHQ/download/npm"
version = "1.1.0"
version = "2.0.0"

module_name = "@millihq/tf-next-image-optimization"
module_version = var.next_image_version
Expand All @@ -12,27 +13,23 @@ module "lambda_content" {
local_cwd = path.module
}

resource "random_id" "function_name" {
prefix = "${var.deployment_name}-"
byte_length = 4
}

module "image_optimizer" {
source = "terraform-aws-modules/lambda/aws"
version = "2.17.0"

function_name = random_id.function_name.hex
description = var.deployment_name
function_name = var.deployment_name
description = "Managed by Terraform Next.js image optimizer"
handler = "handler.handler"
runtime = "nodejs14.x"
memory_size = var.lambda_memory_size
timeout = var.lambda_timeout
publish = true

environment_variables = {
NODE_ENV = "production",
NODE_ENV = "production"
TF_NEXTIMAGE_DOMAINS = jsonencode(var.next_image_domains)
TF_NEXTIMAGE_DEVICE_SIZES = var.next_image_device_sizes != null ? jsonencode(var.next_image_device_sizes) : null
TF_NEXTIMAGE_FORMATS = jsonencode(var.next_image_formats)
TF_NEXTIMAGE_IMAGE_SIZES = var.next_image_image_sizes != null ? jsonencode(var.next_image_image_sizes) : null
TF_NEXTIMAGE_SOURCE_BUCKET = var.source_bucket_id
}
Expand All @@ -59,12 +56,13 @@ module "image_optimizer" {
#########################
# API Gateway integration
#########################

module "api_gateway" {
source = "terraform-aws-modules/apigateway-v2/aws"
version = "1.1.0"

name = var.deployment_name
description = "Managed by Terraform-next.js image optimizer"
description = "Managed by Terraform Next.js image optimizer"
protocol_type = "HTTP"

create_api_domain_name = false
Expand Down Expand Up @@ -139,7 +137,13 @@ locals {
cloudfront_allowed_query_string_keys = sort(["url", "w", "q"])

# Headers that are used by the image optimizer
cloudfront_allowed_headers = sort(["accept", "referer"])
# - Accept: Header is used to determine the supported image formats from the
# client.
# - Referer: Header is used to determine the host for absolute image paths,
# e.g. example.com/_next/image?url=/image.png, would fetch the
# image from example.com/image.png.name
# Not used if the images are fetched from S3 bucket.
cloudfront_allowed_headers = var.source_bucket_id != null ? ["accept"] : sort(["accept", "referer"])


# CloudFront origin
Expand Down Expand Up @@ -173,14 +177,9 @@ locals {
}
}

resource "random_id" "policy_name" {
prefix = "${var.deployment_name}-"
byte_length = 4
}

resource "aws_cloudfront_origin_request_policy" "this" {
name = "${random_id.policy_name.hex}-request"
comment = "Managed by Terraform-next.js image optimizer"
name = "${var.deployment_name}_request"
comment = "Managed by Terraform Next.js image optimizer"

cookies_config {
cookie_behavior = "none"
Expand All @@ -202,8 +201,8 @@ resource "aws_cloudfront_origin_request_policy" "this" {
}

resource "aws_cloudfront_cache_policy" "this" {
name = "${random_id.policy_name.hex}-cache"
comment = "Managed by Terraform-next.js image optimizer"
name = "${var.deployment_name}_image-cache"
comment = "Managed by Terraform Next.js image optimizer"

# Default values (Should be provided by origin)
min_ttl = 0
Expand Down
5 changes: 0 additions & 5 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@ output "cloudfront_origin" {
value = local.cloudfront_origin
}

output "cloudfront_origin_image_optimizer" {
description = "Deprecated, please use cloudfront_origin instead."
value = local.cloudfront_origin
}

output "cloudfront_cache_behavior" {
description = "Predefined CloudFront cache behavior. Can be used to embed the image optimizer into an existing CloudFront resource."
value = local.cloudfront_cache_behavior
Expand Down
12 changes: 0 additions & 12 deletions scripts/build-local.sh

This file was deleted.

Loading

0 comments on commit af4f6e8

Please sign in to comment.