Sign inSign up

kexpress/louis

By kexpress

Updated almost 7 years ago

Autobild for louis

Image
1

3.2K

kexpress/louis repository overview

Louis

Build Status Coverage Status

Service for uploading images to any S3 compatible storage inspired from ospry and cloudinary.

How it works

The upload flow lets developers make cross-browser uploads directly to configured S3 cloud storage. When an image and it's transformations successfully uploaded, Louis sends back metadata about the image. The metadata can be used immediately, or sent up to your own server for claiming. In future version, unclaimed images will be deleted.

louis

API docs
Uploading image

Request:

POST /upload
Headers:
    Authorization: LOUIS_PUBLIC_KEY
    Content-Type: multipart/form-data
Multipart body:
    file: image
    tags: tag1, tag2, tag3
    key: "name of image[optional/usefull on migration]"

Response:

{
    "error": "",
    "payload": {
        "key": "bdaqolfvn27g83tpe1s0",
        "originalUrl": "https://bucketname.hb.bizmrg.com/bdaqolfvn27g83tpe1s0/original.jpg",
        "transformations": {
            "original": "https://bucketname.hb.bizmrg.com/bdaqolfvn27g83tpe1s0/original.jpg",
            "super_transform": "https://bucketname.hb.bizmrg.com/bdaqolfvn27g83tpe1s0/super_transform.jpg"
        }
    }
}
Claming image

Request:

POST /claim
Headers:
    Authorization: LOUIS_SECRET_KEY
    Content-Type: application/json
Body:
    {
        "keys": ["bd35b7n03vdv2aen0", "oeuaoeuhstbksu234"]
    }

Response:

{
    "error": "",
    "payload": "ok"
}
Upload image with claim

Request:

POST /uploadWithClaim
Headers:
    Authorization: LOUIS_SECRET_KEY
    Content-Type: multipart/form-data
Multipart body:
    file: image
    tags: tag1, tag2, tag3
    key: "name of image[optional/usefull on migration]"

Response the same as in /upload

Command line arguments

./louis --env=<default: .env | path to file with environment variables> \
        --transforms-path=<default: ensure-transforms.json | path to file containing json description of transforms> \
        --initdb=<default: true | ensure needed tables in database>

Running with docker

docker run kexpress/louis

Environment variables

S3_BUCKET=<name of S3 bucket>
S3_ENDPOINT=https://hb.bizmrg.com <url to S3 api server; if not set used AWS endpoint by default>
AWS_REGION=ru-msk<region where s3 is stored>
AWS_ACCESS_KEY_ID=<your S3 access key id>
AWS_SECRET_ACCESS_KEY=<your S3 secret key>
LOUIS_PUBLIC_KEY=<key used for uploading images>
LOUIS_SECRET_KEY=<key used for claiming images>
REDIS_URL=:6379
CLEANUP_DELAY=1 <delay in minutes after which not claimed images will be deleted>
CLEANUP_POOL_CONCURRENCY=10 <number of concurrent cleanup gorutines>
POSTGRES_ADDRESS=127.0.0.1:5432
POSTGRES_USER=postgres
POSTGRES_PASSWORD=1234
POSTGRES_DATABASE=postgres
POSTGRES_SSL_MODE=disable <disable/enable>
MAX_IMAGE_SIZE=5242880 <in bytes>
CORS_ALLOW_ORIGIN=*
CORS_ALLOW_HEADERS=Authorization,Content-Type,Access-Content-Allow-Origin
THROTTLER_QUEUE_LENGTH=10 <max parallel uploads>
THROTTLER_TIMEOUT=15s <queued request will be rejected after this delay with 503 status code>
MEMORY_WATCHER_ENABLED=false <if true then once in interval debug.FreeOsMemory() will be called if current RSS is more than limit>
MEMORY_WATCHER_LIMIT_BYTES=1610612736 <maximum memory amount ignored by watcher, default is 1.5GB>
MEMORY_WATCHER_CHECK_INTERVAL=10m

Development

If you have problems with installing dependencies or building project. It's highly probably that they caused by h2non/bimg. Please check prerequisites and installation guides for these libs.

# libvips is needed in order to install bimg
go get -v ./...

go build ./cmd/louis
./louis
Databases

For development purposes(e.g. for running test) is better to use docker containers with databases:

docker run -d --rm -v $(PWD)/data/pg:/var/lib/postgresql/data -e POSTGRES_PASSWORD=1234 -e POSTGRES_USER=postgres -p 5433:5432 --name pg-app postgres
docker run -d --rm -v $(PWD)/data/rd:/data -p 6379:6379 --name rds redis

Monitoring with Prometheus

Metrics are exposed in port 8001 and route /metrics

Tag summary

Content type

Image

Digest

Size

97.6 MB

Last updated

almost 7 years ago

docker pull kexpress/louis