Skip to content

Commit

Permalink
Merge branch 'master' of github.com:aldor007/mort
Browse files Browse the repository at this point in the history
  • Loading branch information
aldor007 committed Jul 22, 2018
2 parents f8b446a + 426ff95 commit e96e980
Show file tree
Hide file tree
Showing 11 changed files with 1,965 additions and 10 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ An S3-compatible image processing server written in Go. Still in active developm

* HTTP server
* Resize, Rotate, SmartCrop
* Convert (JPEG, , PNG , BMP, TIFF, ...)
* Convert (JPEG, PNG , BMP, Webp)
* Multiple storage backends (disk, S3, http)
* Fully modular
* S3 API for listing and uploading files
* Request collapsing
* Requests collapsing
* Build in rate limiter
* HTTP Range and Conditional request
* HTTP Range and Conditional requests
* Compression (gzip, brotli)

And more see [changelog](CHANGELOG.md) for more info
Expand Down Expand Up @@ -213,6 +213,8 @@ Run docker
docker run -p 8080:8080 myusername/mort
```

Full example you can find [here](example/)

# Development
1. Make sure you have a Go language compiler >= 1.9 (required) and git installed.
2. Install libvips like described on [bimg page](https://github.com/h2non/bimg)
Expand Down
3 changes: 1 addition & 2 deletions cmd/mort/mort.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ func startServer(s *http.Server, ln net.Listener) {

func main() {
configPath := flag.String("config", "/etc/mort/mort.yml", "Path to configuration")
debug := flag.Bool("debug", false, "enable debug mode")
version := flag.Bool("version", false, "get mort version")
flag.Parse()

Expand All @@ -162,7 +161,7 @@ func main() {
}

fmt.Printf(BANNER, "v"+Version)
fmt.Printf("Config file %s listen addr %s debug: %t pid: %d \n", *configPath, imgConfig.Server.Listen, *debug, os.Getpid())
fmt.Printf("Config file %s listen addr %s montoring: and debug listen %s pid: %d \n", *configPath, imgConfig.Server.Listen, imgConfig.Server.InternalListen, os.Getpid())

rp := processor.NewRequestProcessor(imgConfig.Server, lock.NewMemoryLock(), throttler.NewBucketThrottler(10))
s3Auth := mortMiddleware.NewS3AuthMiddleware(imgConfig)
Expand Down
3 changes: 3 additions & 0 deletions example/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM aldor007/mort
ADD config.yml /etc/mort/mort.yml
RUN mkdir -p /var/run/mort
37 changes: 37 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Mort behind nginx

## Scheme

```apple js
|==============|
| Dark World |
|==============|
||||
|==============|
| nginx
|==============|
|
|
/-----------\
| mort |
\-----------/
```
## Assumptions
* Object will be stored in /var/mort/data
* You will use nginx with slice module
* nginx will terminate SSL
* prometheus job for mort has name "mort"

## Files structure

* config.yml - mort configuration file (copy of demo config)
* deploy-mort.sh - bash script for building and running mort instance
* Dockerfile - simple docker file with configuration for mort
* mort-nginx.config - full nginx configuration that can be easy extanded for any use case
* monitoring.json - example monitoring dashboard

## Grafana dashboard

<a href="https://mort.mkaciuba.com/demo/dashboard.png"><img src="https://mort.mkaciuba.com/demo/medium/dashboard.png" width="500px"/></a>

118 changes: 118 additions & 0 deletions example/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
server:
listens:
- ":8080"
- "unix:/var/run//mort.sock"
monitoring: "prometheus"
plugins:
webp: ~
compress:
gzip:
types:
- text/plain
- text/css
- application/json
- application/javascript
- text/xml
- application/xml
- application/xml+rss
- text/javascript
- text/html;
level: 4
brotli:
types:
- text/plain
- text/css
- application/json
- application/javascript
- text/xml
- application/xml
- application/xml+rss
- text/javascript
- text/html;
level: 4

headers:
- statusCodes: [200]
values:
"cache-control": "max-age=84000, public"
- statusCodes: [404, 400]
values:
"cache-control": "max-age=60, public"
- statusCodes: [500, 503]
values:
"cache-control": "max-age=10, public"

buckets:
media:
keys:
- accessKey: "acc"
secretAccessKey: "sec"
transform:
path: "\\/(?P<presetName>[a-z0-9_]+)\\/(?P<parent>.*)"
kind: "presets"
parentBucket: "media"
resultKey: "hash"
presets:
small:
quality: 75
filters:
thumbnail:
width: 150
blur:
quality: 80
filters:
thumbnail:
width: 700
blur:
sigma: 5.0
webp:
quality: 100
format: webp
filters:
thumbnail:
width: 1000
watermark:
quality: 100
filters:
thumbnail:
width: 1300
watermark:
image: "https://upload.wikimedia.org/wikipedia/commons/thumb/e/e9/Imgur_logo.svg/150px-Imgur_logo.svg.png"
position: "center-center"
opacity: 0.5
storages:
basic:
kind: "http"
url: "https://i.imgur.com/<item>"
headers:
"x--key": "sec"
transform:
kind: "local-meta"
rootPath: "/data/buckets"
pathPrefix: "transforms"

query:
keys:
- accessKey: "acc"
secretAccessKey: "sec"
transform:
kind: "query"
resultKey: "hash"
storages:
basic:
kind: "http"
url: "https://i.imgur.com/<item>"
headers:
"x--key": "sec"
transform:
kind: "local-meta"
rootPath: "/data/buckets/"
pathPrefix: "transforms"
local:
keys:
- accessKey: "acc"
secretAccessKey: "sec"
storages:
basic:
kind: "local-meta"
rootPath: "/data/buckets/"
Binary file added example/dashboard.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 7 additions & 0 deletions example/deploy-mort.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
docker pull aldor007/mort
docker build . -t mort
docker ps | grep mort | awk '{print $1 }' | xargs docker stop
docker ps -a | grep mort | awk '{print $1 }' | xargs docker rm
rm -rf /var/run/mort/mort.sock
docker run --name mort -d -p "127.0.0.1:8080:8080" -p "127.0.0.1:8081:8081" -v /var/mort/data/:/data/buckets -v /var/run/mort/:/var/run/mort mort
Loading

0 comments on commit e96e980

Please sign in to comment.