Git Product home page Git Product logo

dragonfly-server's Introduction

Dragonfly server

Build Status

This application can be used to serve Dragonfly urls.

Limitations

  • Doesn't support the full Dragonfly feature set (for now).
  • Limited to Imagemagick.

Setup

Dependencies

Erlang

IMPORTANT: Due to a known bug in Erlang 17.3, fetching urls with an https scheme are not processed correctly and throw an exception.

Please use Erlang >= 17.4, available at https://www.erlang-solutions.com/downloads/download-erlang-otp.

Elixir

To install elixir on a Mac, brew install elixir (you may need to brew update first).

Alternatively, you can follow these instructions.

Imagemagick

To install Imagemagick with png support, run brew install jpeg libpng imagemagick.

Goon

Communication with Imagemagick is managed by Goon, a middleman needed to polyfill the incomplete Port implementation provided by Erlang (see here for more information).

Download the binary and add it to a directory available in your $PATH.

App setup

$ mix deps.get

This will install all needed packages.

Then, copy the example environment file and make the necessary adjustments.

$ cp .env.example .env

Run the app in development

$ iex -S mix

Starts the app and opens a console.

Run tests

$ mix test

General api

Images are served at the entry point defined in config.exs, set as default at /media/:payload/:filename.

Note that both params in the url scheme are needed by the application.

Admin api

The app exposes an admin api that can be used to programmatically expire an image and all its associated resources. Endpoints are:

  • GET image (shows steps necessary to generate image)
  • DELETE image (expires all caches involved in the generation of the image)

Given an image url in the form of:

http://example.com/media/12345/untitled.jpg

It can be deleted by sending a DELETE request to the following endpoint:

http://example.com/admin/media/12345/untitled.jpg

From the command line:

$ curl -XDELETE http://example.com/admin/media/12345/untitled.jpg

The expected response is a 202, which indicates that the cache expiry has been scheduled and will be performed asyncronously.

The steps necessary to generate the image can also be examined at:

http://example.com/admin/media/12345/untitled.jpg

From the command line:

$ curl http://example.com/admin/media/12345

Deploy on Heroku

The app runs only on Cedar-14 and requires the multi-buildpack as it uses a custom Elixir buildback (it includes Goon).

Buildpacks are defined in .buildpacks.

Please follow instructions at https://github.com/ddollar/heroku-buildpack-multi.

dragonfly-server's People

Contributors

cloud8421 avatar felixbuenemann avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

dragonfly-server's Issues

Format not handled per step

While reading the step tests, I noticed that the format is stored globally instead of for each convert step. So if multiple processing steps are given, the format from the last step is used for all intermediate steps. This is not such a good idea if the format is lossy, like jpeg.

Maybe it would be better to store the format with every intermediate step or force a lossless format for intermediate steps.

In most cases this should be avoidable, because pretty much all transformations can be done in a single convert call.

One test that shows the problem:

  test "works with local files" do
    steps = [["ff", "/app/foo.jpg"],
             ["p", "convert", "-thumbnail 273x273^^ -gravity center -crop 273x273+0+0 +repage -draw 'polygon 0,0 273,273 273,0 fill none matte 135,135 floodfill'", "png"],
             ["p", "thumb", "892x320#"],
             ["e", "jpg"]]
    commands = %Steps{file: "/app/foo.jpg",
                convert: "#{Config.convert_command} -'[0]' -thumbnail 273x273^^ -gravity center -crop 273x273+0+0 +repage -draw 'polygon 0,0 273,273 273,0 fill none matte 135,135 floodfill' jpg:- | #{Config.convert_command} - -resize 892x320^^ -gravity center -crop 892x320+0+0 +repage -strip jpg:-",
                format: "jpg"}
    assert(commands == Steps.deserialize(steps))
  end

In the first processing step, png is specified as format, but the convert command used jpg instead.

Different encode step syntax than dragonfly gem

The current version of the dragonfly gem serialized the encode processor as:

 ["p", "encode", "jpg", "-quality 50"]

But dragonfly-server uses:

 ["e", "jpg", "-quality 50"]

Is there a reason for the different syntax or is it a bug in the elixir implementation?

I already have a fix for this locally, which currently supports both variants, but I'd like to know wether I should keep or drop support for the "e" syntax.

Idea: Cache backend fetches

There are many scenarios, in which the same images are requested from the backend multiple times in a short period:

  • Same file fetched as download and for thumbnail (eg. PDF thumb)
  • Master/detail/zoom: In ecommerce applications it's common to have the same image as a thumb on the list page, than another thumb and small image on the detail page and maybe even a large/original size image for a zoom view
  • Generating smaller images for different screen resolutions (eg. generating smaller images for phones than desktops)
  • Generating different formats for different user agents (eg. jpeg, webp, jpeg2000)

If a new original is added, it is likely to stay "hot" for some time, until all of the common variants are generated.

My idea is to transform the fetch operations into the same job syntax and cache them the same way as generated versions. There are some caveats when generating cache keys, eg. signed urls would need their cache keys to be generated without signing or they'd be useless. Ideally there would also be the same cache key used for a simple fetch/download job from a client and the same operation cached as part of eg. a thumbnail job.

It would probably also be a good idea to be able to configure a different cache server for backend fetches to avoid cache trashing and be able to allocate cache size separately for originals.

What do you think about the idea?

I'm a bit undecided, because in many cases this can just as well be built using a simple reverse proxy in nginx and pointing the http_engine_host at that proxy. Then again the same can be said for the caching of job results. In my current deployments of the rack dragonfly I've just put an nginx proxy in front of it, so the rack app is idle unless new images are added.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.