Version: 3.0.0

Deployments

Introduction

Caravaggio can be deployed easily on any platform. You can run it from its cli or run inside docker. Here we focus on how to deploy in some function as a service platform, such as AWS Lambda or Vercel.

TL;DR: there is a repository that contains a collection of ready-made examples to deploy Caravaggio on several FaaS platforms and you can find it here.

When you run Caravaggio, you basically have a complete webservice, but the core of Caravaggio is not a server, instead it's a simple function. It has been designed like that with the explicit purpose of making it easily deployable on FaaS platforms. Often these platform have their own entry point and provide their own web server solution.

Vercel (formerly Zeit, Now)

To deploy on Vercel, you can just click on the button below and follow instructions.
This will create a deployment on Vercel with the correct configuration.

Deploy with Vercel

If you want to handle code by yourself instead, just create a new node project and install caravaggio as dependency.

Create a folder called api

mkdir api

Inside it create a file called index.js and put this content inside

import { caravaggio } from 'caravaggio';
const ONE_DAY = 60 * 60 * 24;
/**
* This is the configuration for Caravaggio
* Refer to
* https://gitlab.com/ramiel/caravaggio/-/blob/master/src/config/default.ts
* for the available values
*
*/
const config = {
caches: {
input: {
type: 'memory',
options: {
limit: 100,
}
},
output: {
type: 'none',
options: {},
},
},
browserCache: `s-maxage=${ONE_DAY}`,
whitelist: [],
errors: 'html',
logger: {
options: {
level: 'info',
prettyPrint: true,
},
destination: process.stdout,
},
}
export default async (req, res) => {
const handler = caravaggio(config);
const result = await handler(req, res);
return result;
};

Vercel is able to put a cache in front of your service and Caravaggio is able to take advantage of this by setting browserCache: s-maxage=N. Now everytime the same image is asked, the caravaggio function is not run anymore and the result will come directly from Vercel cache. To know more about Vercel cache, read its documentation.

In the root folder of your project crate a file called now.json and put this content inside.

{
"version": 2,
"routes": [
{
"src": "/.*",
"dest": "api/index"
}
]
}

This is telling vercel that any call to the service should be routed to the api we just created, which is Caravaggio.

If not installed, install now cli

npm i -g now

and then deploy Caravaggio

now

and follow the instructions on screen