Skip to content

Commit

Permalink
Progress on docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mosnar committed May 4, 2020
1 parent 55731dd commit 46b486d
Show file tree
Hide file tree
Showing 9 changed files with 209 additions and 2 deletions.
21 changes: 21 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Introduction

## What is Serverless Sharp?
Serverless Sharp is a self-hosted image processing solution that uses [Sharp](https://sharp.pixelplumbing.com/) by
Pixel Plumbing. Serverless Sharp requires no database, no server, and no additional services beyond those offered by
AWS.

## Who is this for?
This software is for people who want to optimize and run basic transformations (crop, scale, convert, etc) on images
from an existing S3 bucket without running computationally expensive processes or servers or paying for expensive
third-party services.

## How does it work?
After deploying this solution, you'll find yourself with a number of AWS resources (all priced based on usage rather
than monthly cost). The most important of which are:
- **AWS Lambda**: Pulls images from your S3 bucket, runs the transforms, and outputs the image from memory
- **API Gateway**: Acts as a public gateway for requests to your Lambda function
- **Cloudfront Distribution**: Caches the responses from your API Gateway so the Lambda function doesn't re-execute

Once deployed, a Cloudfront distribution is generated that is directed to the generated API Gateway. This distribution
ensures the Lambda function does not get run multiple times for the same image request.
133 changes: 133 additions & 0 deletions docs/configuration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Configuration
Serverless Sharp stores its settings in YAML files. When deploying the application, you specify the YAML file and the
stage (your environment). For example:

```sh
serverless deploy --settings mysite.com.yml --stage prod
```

## Settings File Structure
We use YML files to make use of their inheritance. This allows us to define some defaults and then branch environment
-specific changes off of them. For example:


```yml
defaults: &defaults
serviceName: image-handler-test
offlinePort: 80
region: 'us-east-1'
environment: &defaults.environment
DEFAULT_QUALITY: 75
DEFAULT_COMPRESS_QUALITY: 45
SLS_IGNORE: favicon.ico
SLS_VALID_PATH_REGEX: '.*'
MAX_IMAGE_WIDTH: 2000
MAX_IMAGE_HEIGHT: 1000
PNGQUANT_SPEED: 10
DEFAULT_CACHE_CONTROL: 'max-age=2592000'

stages:
dev:
<<: *defaults
environment:
<<: *defaults.environment
SOURCE_BUCKET: 'my-bucket/prefix/path'
SECURITY_KEY: ''
CUSTOM_DOMAIN: ''
prod:
<<: *defaults
environment:
<<: *defaults.environment
SOURCE_BUCKET: 'random-string-here'
SECURITY_KEY: ''
CUSTOM_DOMAIN: 'my.domain.com'

```

## Environment Settings
The majority of the application and environment specific settings are configured as environment variables that are
passed into the Lambda service handler.

### `DEFAULT_QUALITY`

- Type: `integer`
- Default: `75`

A number between 1 and 100 representing the default image quality.

### `DEFAULT_COMPRESS_QUALITY`

- Type: `integer`
- Default: `75`

A number between 1 and 100 for the default quality when an image is requested to be compressed

### `SLS_IGNORE`

- Type: `string`
- Default: ``

A comma-delineated string of paths that should be ignored (for example, `favicon.ico`)

### `SLS_VALID_PATH_REGEX`

- Type: `Regular Expression`
- Default: `.*`

A regular expression for path validation. Allows you to explicitly control what assets may be handled by the Lambda
function. If the request path fails this test, a 404 response will be served.

Example:
```yaml
# All requests must start with /images/
SLS_VALID_PATH_REGEX: ^\/images\/.*`
```
### `MAX_IMAGE_WIDTH`

- Type: `integer`
- Default: `2000`

Images may not be requested with a width larger than this value

### `MAX_IMAGE_HEIGHT`

- Type: `integer`
- Default: `2000`

Images may not be requested with a height larger than this value

### `PNGQUANT_SPEED`

- Type: `integer`
- Default: `10`

The speed value to pass to the `pngquant` optimization program. From the [pngquant website](https://pngquant.org/):

> Speed/quality trade-off from 1 (brute-force) to 10 (fastest). The default is 3. Speed 10 has 5% lower quality, but is 8 times faster than the default.

### `DEFAULT_CACHE_CONTROL`

- Type: `string`
- Default: ``

By default, Serverless Sharp will serve responses with the same Cache-Control header as the object being served. If
the Cache-Control header is not set, this value will be used.


### `SOURCE_BUCKET`

- Type: `string`
- Default: ``

### `SECURITY_KEY`

- Type: `string`
- Default: ``

### `CUSTOM_DOMAIN`

- Type: `string`
- Default: ``

> **NOTE:** This requires deployment in the `us-east-1` region!
1 change: 1 addition & 0 deletions docs/deployment.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Deployment
48 changes: 48 additions & 0 deletions docs/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Serverless Sharp</title>
<link rel="stylesheet" href="https://unpkg.com/docute@4/dist/docute.css">
</head>
<body>
<div id="docute"></div>
<script src="https://unpkg.com/docute@4/dist/docute.js"></script>
<script>
new Docute({
title: 'Serverless Sharp',
target: '#docute',
nav: [
{
title: 'Home',
link: '/'
},
{
title: 'GitHub',
link: 'https://github.com/venveo/serverless-sharp'
}
],
sidebar: [
// A sidebar item, with child links
{
title: 'Introduction',
link: '/'
},
{
title: 'Configuration',
link: '/configuration'
},
{
title: 'Deployment',
link: '/deployment'
},
{
title: 'Changelog',
link: 'https://github.com/venveo/serverless-sharp/blob/master/CHANGELOG.md'
}
]
})
</script>
</body>
</html>
1 change: 1 addition & 0 deletions docs/usage/integration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Integration
1 change: 1 addition & 0 deletions docs/usage/parameters.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Parameters
1 change: 1 addition & 0 deletions docs/usage/security.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Security
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"email": "[email protected]"
},
"scripts": {
"test": "jest"
"test": "jest",
"docs": "serve ./docs"
},
"version": "1.0.0",
"private": false,
Expand Down
2 changes: 1 addition & 1 deletion src/helpers/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const settings = {
type: TYPE_INTEGER
},
DEFAULT_COMPRESS_QUALITY: {
default: 45,
default: 75,
type: TYPE_INTEGER
},
SLS_IGNORE: {
Expand Down

0 comments on commit 46b486d

Please sign in to comment.