Skip to content

Commit

Permalink
Rejig
Browse files Browse the repository at this point in the history
Signed-off-by: lloydmeta <[email protected]>
  • Loading branch information
lloydmeta committed Nov 1, 2024
1 parent b8e1298 commit 0f856b5
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 27 deletions.
21 changes: 21 additions & 0 deletions LICENCE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2024 by Lloyd Chan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
44 changes: 17 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Tiny HTTP image resizer.
* Being fast can help minimise costs
* Scalable: can handle lots of requests
* Thumbor-ish
* A good net citizen (don’t make requests to third parties if we have it in cache)
* Fetch from remote urls, but be good net citizen (don’t make requests to third parties if we have it in cache)
* Debuggable

To fulfil the above:
Expand All @@ -32,7 +32,9 @@ An example Terraform config in `terraform/prod` is provided to show how to deplo
We only support resizing at the moment

1. An "image" endpoint [a la Thumbor](https://thumbor.readthedocs.io/en/latest/usage.html#image-endpoint)
* `GET /{HMAC_signature}/-Wx-H/{image_url}`
2. A "metadata" endpoint [a la Thumbor](https://thumbor.readthedocs.io/en/latest/usage.html#metadata-endpoint)
* `GET /{HMAC_signature}/meta/-Wx-H/{image_url}`
* Difference: target image size is _not_ returned (might change in the future)

### Confguration
Expand All @@ -52,6 +54,8 @@ miniaturs relies on environment variables for configuration. These include

## Flow

Flow for an image resize request. The CDN/WAF graph is included since it's an important part of keeping costs low (and included in the prod terraform example), but is not a _must_.

```mermaid
flowchart
imageReq(("Image request"))
Expand Down Expand Up @@ -87,52 +91,44 @@ flowchart
subgraph Lambda
lambdaRequest[\"Request"\]
sigCheck{"Signature OK"?}
toOps[To Operations]
opsCheck{"Operations OK?"}
rawCache[("Unprocessed cache")]
processedCache[("Processed cache")]
lambdaRequest[\"Request"\]
lambdaResponse[\"Ok/Error Response"\]
fetchCachedResult["Fetch cached result"]
opsResultCached{"Operations Result Cached?"}
fetchCachedResult["Fetch cached result"]
rawCached{"Unprocessed image Cached?"}
rawCache[("Unprocessed cache")]
fetchCachedRaw["Fetch cached unprocessed image"]
rawCached{"Unprocessed image Cached?"}
fetchRaw["Fetch unprocessed image from remote"]
rawImageValidation{"Unprocessed image validations pass?"}
cacheRaw["Cache unprocessed image"]
processImage["Process image according to operations"]
cacheResult["Cache processed result"]
cacheResult["Cache processed result"]
lambdaResponse[\"Ok/Error Response"\]
cdnCached -->|no| lambdaRequest
lambdaRequest --> sigCheck
sigCheck -->|no| lambdaResponse
sigCheck -->|yes| toOps
toOps --> opsCheck
opsCheck -->|no| lambdaResponse
opsCheck -->|yes| fetchCachedResult
fetchCachedResult <-->|fetch| processedCache
fetchCachedResult --> opsResultCached
opsResultCached -->|yes| lambdaResponse
opsResultCached -->|no| fetchCachedRaw
opsResultCached -->|no| fetchCachedRaw
fetchCachedRaw <-->|fetch| rawCache
fetchCachedRaw --> rawCached
rawCached -->|no| fetchRaw
fetchRaw --> rawImageValidation
rawImageValidation -->|no| lambdaResponse
Expand All @@ -145,9 +141,7 @@ flowchart
processImage --> cacheResult
cacheResult -->|cache| processedCache
cacheResult --> lambdaResponse
cacheResult --> lambdaResponse
lambdaResponse --> cache
end
Expand Down Expand Up @@ -208,10 +202,6 @@ Use `Makefile` targets.
* `make provision_prod` to apply changes
* `TO_SIGN="200x-100/https://beachape.com/images/octopress_with_container.png" make signature_for_prod` to get a signed path

## To Explore
## To explore

* Image resizing
* https://imgproxy.net/blog/almost-free-image-processing-with-imgproxy-and-aws-lambda/
* https://zenn.dev/devneko/articles/0a6fb5c9ea5689
* https://crates.io/crates/image
* [Logs, tracing](https://github.com/tokio-rs/tracing?tab=readme-ov-file#in-applications)

0 comments on commit 0f856b5

Please sign in to comment.