Commit 44138ce7 authored by Fabrizio Ruggeri's avatar Fabrizio Ruggeri
Browse files

Continue working on it

NOT working
parent 31c61bbd
coverage
website
\ No newline at end of file
/coverage
/website
/src_OLD
/test_OLD
/dist
module.exports = {
env: {
es6: true,
node: true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:prettier/recommended',
'plugin:jest/recommended',
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 11,
sourceType: 'module',
},
plugins: ['@typescript-eslint'],
rules: {
'@typescript-eslint/explicit-function-return-type': 'off',
},
};
{
"root": true,
"extends": "airbnb-base",
"rules": {
"no-unused-vars": [
"error",
{
"argsIgnorePattern": "^_"
}
],
"no-nested-ternary": 0,
"no-multiple-empty-lines": [
"error",
{
"max": 2,
"maxEOF": 1
}
],
"no-plusplus": [
"error",
{
"allowForLoopAfterthoughts": true
}
]
}
}
......@@ -5,7 +5,6 @@
# Visual Studio Code - https://code.visualstudio.com/
.settings/
.vscode/
tsconfig.json
jsconfig.json
### Node ###
......@@ -114,3 +113,7 @@ ignoreme.*
caravaggio
config/local.*
src/config/local.*
src_OLD/
test_OLD
dist/
*-diff.png
image: node:10
image: node:12
## Quality checkers by Gitlab
......
{
"trailingComma": "es5",
"tabWidth": 2,
"semi": true,
"singleQuote": true
}
# Changelog
## 2.8.0
- Supprot Node.js v12
- Update sharp to version 0.24
- Supprot Node.js v12
- Update sharp to version 0.24
## 2.7.2
- Moved documentation on its own repository
- Moved documentation to new website at [caravaggio.ramielcreations.com](https://caravaggio.ramielcreations.com)
- Moved documentation on its own repository
- Moved documentation to new website at [caravaggio.ramielcreations.com](https://caravaggio.ramielcreations.com)
## 2.7.1
- Move to a custom config module
- This avoids to have external dependencies at runtime. Useful for future usage.
- Remove documentation from the project. Now it has its own project at https://gitlab.com/ramiel/caravaggio-docs
- Move to a custom config module
- This avoids to have external dependencies at runtime. Useful for future usage.
- Remove documentation from the project. Now it has its own project at https://gitlab.com/ramiel/caravaggio-docs
## 2.7.0
- ✨ New `duotone` effect. Shift your images to two color tones
- Pipeline faster and more powerful
- ✨ New `duotone` effect. Shift your images to two color tones
- Pipeline faster and more powerful
## 2.6.0
- ⚖️ Use new licesezero.com prosperity license
- Improvement: use native Map as memory cache
- ⚖️ Use new licesezero.com prosperity license
- Improvement: use native Map as memory cache
## 2.5.2
- Improved documentation
- Improved documentation
## 2.5.1
- Fix documentation for domain whitelist (@tobiah)
- Update readme
- Updated docusaurus
- Fix documentation for domain whitelist (@tobiah)
- Update readme
- Updated docusaurus
## 2.5.0
- Allow rotations of any angle
- Allow rotations of any angle
- Update sharp to version 0.21.1
## 2.4.0
- Add `overlay` option. Now you can add watermarks to your images!
## 2.3.6
- ✨📖 Documentation now has a useful "Try it" on each example!
......@@ -49,7 +55,6 @@
- Caches are faster. Now the policy is to return the cached value before saving if possible
- Fixed a bug which prevent running verbose mode in production
## 2.3.4
- Fix: output cache configuration is correctly read
......@@ -62,7 +67,6 @@
- Dependencies security updates
## 2.2.2
- Various documentation fixes
......@@ -106,11 +110,13 @@
- Removed now example link in documentation until it's clear what to do about it
- Now deploy is easier
- Publish on npm and docker hub automatically!
## 1.3.5
- ✨ Docker is much, much simpler!
- Documentation have now integrated search...thanks [algolia](https://www.algolia.com/)! 🔍
- Errors have link to documentation...so nice! 👩‍⚕️
## 1.3.4
- Wrong values in operation result in 400 response
......@@ -122,6 +128,7 @@
- Documentation update
- Remove console.log from code
- Docker listen to port 8565 by default. For real now.
## 1.3.1
- Cli global program
......@@ -143,6 +150,7 @@
- Send cache headers
- Three stage pipeline
- Add logger
## 1.1.0
- Support new persistors
......@@ -150,10 +158,9 @@
- Error handler
- Domain whitelist
- Docker version (initial)
## 1.0.1
- Basic working service
- Supported operations: rotate, flip, blur
- Supported persistence: file, memory
......@@ -7,7 +7,7 @@ You can find the complete documentation on the [Caravaggio website](https://cara
### About this docker image
This docker image provide a production ready version of Caravaggio.
This docker image provide a production ready version of Caravaggio.
### Start a Caravaggio server instance
......@@ -19,7 +19,7 @@ Starting a Caravaggio instance is simple:
### Configuration
For a full description of all the configuration options refer to the [official documentation](https://caravaggio.ramielcreations.com/docs/configuration.html)
For a full description of all the configuration options refer to the [official documentation](https://caravaggio.ramielcreations.com/docs/configuration.html)
i.e. to change the port and the cache system
`$ docker run -ti --name some-caravaggio -p 3333:3333 -d ramielcreations/caravaggio:tag --port 3333 --cache none`
......
FROM node:10-alpine AS build
FROM node:12-alpine AS build
LABEL maintainer="Fabrizio Ruggeri"
......@@ -21,11 +21,13 @@ WORKDIR /caravaggio
COPY package.json package-lock.json /caravaggio/
RUN npm install --production
RUN npm install
COPY . /caravaggio
RUN pkg -t node10-alpine-x64 .
RUN npm run build
RUN pkg -t node12-alpine-x64 .
RUN ls -l /caravaggio/node_modules/sharp/
......
[![caravaggio logo](https://res.cloudinary.com/ramiel/image/upload/c_scale,r_0,w_100/v1517679412/caravaggio-logo_xdwpin.jpg)](https://res.cloudinary.com/ramiel/image/upload/c_scale,r_0,w_100/v1517679412/caravaggio-logo_xdwpin.jpg)
# Caravaggio
[![caravaggio logo](https://res.cloudinary.com/ramiel/image/upload/c_scale,r_0,w_100/v1517679412/caravaggio-logo_xdwpin.jpg)](https://res.cloudinary.com/ramiel/image/upload/c_scale,r_0,w_100/v1517679412/caravaggio-logo_xdwpin.jpg)
# Caravaggio
[![pipeline status](https://gitlab.com/ramiel/caravaggio/badges/master/pipeline.svg)](https://gitlab.com/ramiel/caravaggio/commits/master)
[![coverage report](https://gitlab.com/ramiel/caravaggio/badges/master/coverage.svg)](https://gitlab.com/ramiel/caravaggio/commits/master)
......@@ -34,7 +34,6 @@ docker run --name caravaggio -p 8565:8565 -dti ramielcreations/caravaggio:latest
Refer to the [page on the docker store](https://store.docker.com/community/images/ramielcreations/caravaggio) for its configuration
### Git
```
......@@ -48,23 +47,22 @@ npm start
The service is avaiable at `http://localhost:8565/`
and can be used sending a set of options and an image:
and can be used sending a set of options and an image:
`http://localhost:8565/rotate_90/https://image.com/pony.jpg`
## Available operations
Please, refer to the [documentation](https://caravaggio.ramielcreations.com) to know what are the available operations.
## Thank you
This project is possible thanks to
This project is possible thanks to
- [sharp](http://sharp.pixelplumbing.com/en/stable/) - A js image processing library
- [micro](https://github.com/zeit/micro) - A fast microservice library
- [micro](https://github.com/zeit/micro) - A fast microservice library
- A lot of other great developers
- The amazing photographers on [pexels.com](https://www.pexels.com/)
# Licensing
This package is free to use for commercial purposes for a trial period under the terms of the [Prosperity Public License](./LICENSE).
......
/* eslint-env jest */
const path = require('path');
const fs = require('fs');
const getImage = (name = 'caravaggio.jpg') => new Promise((resolve, reject) => {
fs.readFile(path.join(__dirname, '..', 'test', 'fixtures', name), (err, data) => {
if (err) return reject(err);
return resolve(data);
});
});
module.exports = jest.fn((/* url */) => getImage()
.then(buffer => ({
buffer: () => buffer,
})));
/* eslint-env jest */
import path from 'path';
import fs from 'fs';
const getImage = (name = 'caravaggio.jpg') =>
new Promise((resolve, reject) => {
fs.readFile(
path.join(__dirname, '..', 'test', 'fixtures', name),
(err, data) => {
if (err) return reject(err);
return resolve(data);
}
);
});
export default jest.fn((/* url */) =>
getImage().then((buffer) => ({
buffer: () => buffer,
})));
#!/usr/bin/env node
const os = require('os');
const yargs = require('yargs');
const merge = require('lodash/merge');
const defaultConfig = require('../src/config');
const caravaggio = require('../index');
['SIGINT', 'SIGTERM'].forEach((signal) => {
process.on(signal, () => process.exit(0));
});
const options = yargs // eslint-disable-line no-unused-expressions
.option('port', {
alias: 'p',
default: 8565,
describe: 'the server will listen to this port',
type: 'number',
})
.option('cache', {
default: 'memory',
describe: 'Set the cache system',
type: 'string',
choices: ['memory', 'file', 'none'],
group: 'cache',
})
.option('cache-filepath', {
describe: '[when --cache=file] The file path for the file cache',
type: 'string',
default: os.tmpdir(),
group: 'cache',
})
.option('cache-limit', {
default: 100,
describe: '[when --cache=memory] The maximum amount of memory to use in MB',
type: 'number',
group: 'cache',
})
.option('inputcache', {
default: 'none',
describe: 'Set the input cache system. This cache save the original images to avoid re-download',
type: 'string',
choices: ['memory', 'file', 'none'],
group: 'input cache',
})
.option('inputcache-filepath', {
describe: '[when --cache=file] The file path for the file cache',
type: 'string',
default: os.tmpdir(),
group: 'input cache',
})
.option('inputcache-limit', {
default: 100,
describe: '[when --cache=memory] The maximum amount of memory to use in MB',
type: 'number',
group: 'input cache',
})
.option('whitelist', {
describe: 'Restrict the images to a list of domains',
type: 'array',
group: 'security',
})
.option('verbose', {
alias: 'v',
describe: 'Increase the verbosity of the application',
type: 'boolean',
// conflicts: 'quiet',
group: 'log',
})
.option('quiet', {
alias: 'q',
describe: 'Do not output anything',
type: 'boolean',
// conflicts: 'verbose',
group: 'log',
})
.option('json', {
describe: 'Output logs in json format.',
type: 'boolean',
default: false,
group: 'log',
})
// .conflicts('verbose', 'quiet')
.options('guess-type-by-extension', {
describe: 'use the file extension to guess the file type instead of reading metadata (when possible)',
type: 'boolean',
default: false,
group: 'image manipulation',
})
.options('progressive', {
describe: 'the output images are progressive by default (when applicable)',
type: 'boolean',
default: true,
group: 'image manipulation',
})
.options('errors', {
describe: 'set the error output format',
type: 'string',
choices: ['plain', 'html', 'json'],
default: 'json',
group: 'misc',
})
.options('compress', {
describe: 'compress the response through gzip/deflate if the browser ask for it',
type: 'boolean',
default: false,
group: 'misc',
})
.argv;
const defaultTransformations = [];
if (options.progressive) {
defaultTransformations.push(['progressive', 'true']);
}
let cacheOptions;
switch (options.cache) {
case 'file':
cacheOptions = {
basePath: options['cache-filepath'],
};
break;
case 'memory':
cacheOptions = {
limit: options['cache-limit'],
};
break;
default:
cacheOptions = {};
break;
}
let inputCacheOptions;
switch (options.inputcache) {
case 'file':
inputCacheOptions = {
basePath: options['inputcache-filepath'],
};
break;
case 'memory':
inputCacheOptions = {
limit: options['inputcache-limit'],
};
break;
default:
inputCacheOptions = {};
break;
}
const cliConfig = {
port: options.port,
caches: {
output: {
type: options.cache,
options: cacheOptions,
},
input: {
type: options.inputcache,
options: inputCacheOptions,
},
},
logger: {
pretty: !options.json,
level: options.verbose
? 'debug'
: options.quiet
? 'silent'
: 'info',
},
whitelist: options.whitelist || false,
guessTypeByExtension: options['guess-type-by-extension'],
defaultTransformations,
errors: options.errors,
compress: options.compress,
};
caravaggio(merge(defaultConfig, cliConfig));
version: 2
dependencies:
- type: js
- type: js
path: website
const micro = require('micro');
const { createLogger } = require('./src/logger');
const app = require('./src');
const caravaggio = (config) => {
const { port } = config;
const logger = createLogger(config);
logger.debug(config, 'configuration:');
const server = micro(app(config));
server.listen(port);
logger.info(`Server started. Listen on port: ${port}.`);
};
module.exports = caravaggio;
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testPathIgnorePatterns: [
'<rootDir>/node_modules/',
'<rootDir>/test_OLD/',
'<rootDir>/src/config/test.ts',
'<rootDir>/dist',
],
coverageReporters: ['text-summary', 'html'],
collectCoverageFrom: ['src/**/*.ts'],
};
This diff is collapsed.
{
"name": "caravaggio",
"version": "2.8.0",
"version": "3.0.0-beta.1",
"description": "A blazing fast image processor service",
"main": "index.js",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"bin": {
"caravaggio": "bin/caravaggio"
"caravaggio": "dist/bin/caravaggio.js"
},
"scripts": {
"start": "NODE_ENV=production bin/caravaggio",
"dev": "NODE_ENV=development micro-dev -p 3001 ./src/dev.js -s",
"now-start": "bin/caravaggio --cache memory --cache-limit 1024 --inputcache memory --inputcache-limit 1024 --errors html --whitelist ramiel.gitlab.io cvg-res.now.sh --verbose",
"start": "NODE_ENV=production node dist/server",
"dev": "NODE_ENV=development tsnd --respawn src/server.ts",
"build": "rimraf dist/ && NODE_ENV=production tsc --build",
"prepublish": "npm run build",
"test": "npm run lint && npm run test-only -- --coverage --colors=false",
"test-only": "NODE_ENV=test jest",
"test-watch": "npm run test-only -- --watch",
"lint": "eslint ."
},
"now": {
"public": true,
"type": "npm"
},
"repository": {
"type": "git",
"url": "git+https://gitlab.com/ramiel/caravaggio.git"
......@@ -37,54 +35,44 @@
},
"homepage": "https://caravaggio.ramielcreations.com",
"dependencies": {
"fs-extra": "7.0.0",
"lodash": "^4.17.11",
"configuring": "^0.3.2",
"express-compression": "^1.0.1",
"fs-extra": "^9.0.0",
"md5": "^2.2.1",
"micro": "^9.3.3",
"micro-redirect": "^1.0.0",
"microrouter": "^3.1.2",
"node-fetch": "^2.1.2",
"pino": "^5.5.0",
"pino-pretty": "^2.2.0",
"sharp": "^0.24.0",
"yargs": "12.0.2"
"micro": "^9.3.4",
"microrouter": "^3.1.3",
"node-fetch": "^2.6.0",
"pino": "^6.2.1",
"pino-pretty": "