├── .gitignore ├── README.md ├── Vagrantfile ├── Vagrantfile.pkg ├── build.sh ├── etc ├── thumbor.conf.custom ├── thumbor.conf.default ├── thumbor.default ├── thumbor.instances ├── thumbor.key ├── thumbor.nginx └── thumbor.port └── install.sh /.gitignore: -------------------------------------------------------------------------------- 1 | .vagrant 2 | *.box 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | vagrant-thumbor-base 2 | =================== 3 | 4 | A Vagrant box based on Ubuntu precise32, running [thumbor](https://github.com/globocom/thumbor) 5 | built from the officially supported aptitude PPA. 6 | 7 | By default the box is configured to run four instances of thumbor, load balanced by nginx and a redis storage backend. 8 | 9 | Configuration 10 | ------------- 11 | The defaults for configuring the service should be fine in general and you can just build, but you 12 | can customise the installation. 13 | 14 | To customise the default configuration the `etc` directory contains: 15 | 16 | * `thumbor.conf.custom` for settings you're most likely to want to modify. 17 | * `thumbor.port` to specify the port that the box will forward the service over (default 8888). 18 | * `thumbor.instances` to specify the number of instances nginx will load balance (default 4). 19 | * `thumbor.key` to specify the security key (up to 16 characters) used for signed URLs (default empty to generate a random key) 20 | 21 | The `etc` directory also contains `thumbor.conf.default` (the other conf settings for thumbor), `thumbor.default` and `thumbor.nginx`. These can be edited but in general should be left alone. 22 | 23 | Build instructions 24 | ------------------ 25 | To generate the .box file: 26 | 27 | ./build.sh 28 | 29 | To install locally: 30 | 31 | vagrant box add vagrant-thumbor-base vagrant-thumbor-base.box 32 | -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | # -*- mode: ruby -*- 2 | # vi: set ft=ruby : 3 | 4 | Vagrant::Config.run do |config| 5 | # Base box to build off, and download URL for when it doesn't exist on the user's system already 6 | config.vm.box = "precise32" 7 | config.vm.box_url = "http://files.vagrantup.com/precise32.box" 8 | 9 | # Boot with a GUI so you can see the screen. (Default is headless) 10 | # config.vm.boot_mode = :gui 11 | 12 | # Assign this VM to a host only network IP, allowing you to access it 13 | # via the IP. 14 | # config.vm.network "33.33.33.10" 15 | 16 | # Forward a port from the guest to the host, which allows for outside 17 | # computers to access the VM, whereas host only networking does not. 18 | config.vm.forward_port 8888, 8888 19 | 20 | # Share an additional folder to the guest VM. The first argument is 21 | # an identifier, the second is the path on the guest to mount the 22 | # folder, and the third is the path on the host to the actual folder. 23 | config.vm.share_folder "host", "/home/vagrant/host", "." 24 | 25 | # Enable provisioning with a shell script. 26 | config.vm.provision :shell, :path => "install.sh" 27 | end 28 | 29 | -------------------------------------------------------------------------------- /Vagrantfile.pkg: -------------------------------------------------------------------------------- 1 | Vagrant::Config.run do |config| 2 | config.vm.forward_port 8888, 8888 3 | end 4 | -------------------------------------------------------------------------------- /build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | BOX_NAME=vagrant-thumbor-base 4 | BOX=${BOX_NAME}.box 5 | 6 | function msg { 7 | echo "Thumbor box created." 8 | 9 | echo "Test with vagrant up then:" 10 | echo "http://localhost:8888/unsafe/300x/https://raw.github.com/globocom/thumbor/blob/master/tests/visual_test/flower.jpg" 11 | echo "Install box locally with:" 12 | echo "vagrant box add $BOX_NAME $BOX" 13 | } 14 | 15 | vagrant up && rm -f $BOX && vagrant package --vagrantfile Vagrantfile.pkg --output $BOX && msg 16 | -------------------------------------------------------------------------------- /etc/thumbor.conf.custom: -------------------------------------------------------------------------------- 1 | 2 | # the domains that can have their images resized 3 | # use an empty list for allow all sources 4 | #ALLOWED_SOURCES = ['mydomain.com'] 5 | 6 | # the max width of the resized image 7 | # use 0 for no max width 8 | # if the original image is larger than MAX_WIDTH x MAX_HEIGHT, 9 | # it is proportionally resized to MAX_WIDTH x MAX_HEIGHT 10 | # MAX_WIDTH = 800 11 | 12 | # the max height of the resized image 13 | # use 0 for no max height 14 | # if the original image is larger than MAX_WIDTH x MAX_HEIGHT, 15 | # it is proportionally resized to MAX_WIDTH x MAX_HEIGHT 16 | # MAX_HEIGHT = 600 17 | 18 | # maximum size of the source image in Kbytes. 19 | # use 0 for no limit. 20 | # this is a very important measure to disencourage very 21 | # large source images. 22 | # THIS ONLY WORKS WITH http_loader. 23 | MAX_SOURCE_SIZE = 0 24 | 25 | # if you enable this, the unencryted URL will be available 26 | # to users. 27 | # SUITABLE FOR A VAGRANT BOX 28 | ALLOW_UNSAFE_URL = True 29 | -------------------------------------------------------------------------------- /etc/thumbor.conf.default: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python 2 | # -*- coding: utf-8 -*- 3 | 4 | # thumbor imaging service 5 | # https://github.com/globocom/thumbor/wiki 6 | 7 | # Licensed under the MIT license: 8 | # http://www.opensource.org/licenses/mit-license 9 | # Copyright (c) 2011 globo.com timehome@corp.globo.com 10 | 11 | # the quality of the generated image 12 | # this option can vary widely between 13 | # imaging engines and works only on jpeg images 14 | QUALITY = 85 15 | 16 | # enable this options to specify client-side cache in seconds 17 | MAX_AGE = 24 * 60 * 60 18 | 19 | # client-side caching time for temporary images (using queued detectors or after detection errors) 20 | MAX_AGE_TEMP_IMAGE = 0 21 | 22 | # the way images are to be loaded 23 | LOADER = 'thumbor.loaders.http_loader' 24 | 25 | # if you set UPLOAD_ENABLED to True, 26 | # a route /upload will be enabled for your thumbor process 27 | # You can then do a put to this URL to store the photo 28 | # using the specified Storage 29 | UPLOAD_ENABLED = False 30 | UPLOAD_PHOTO_STORAGE = 'thumbor.storages.file_storage' 31 | UPLOAD_PUT_ALLOWED = False 32 | UPLOAD_DELETE_ALLOWED = False 33 | 34 | # how to store the loaded images so we don't have to load 35 | # them again with the loader 36 | STORAGE = 'thumbor.storages.redis_storage' 37 | #STORAGE = 'thumbor.storages.no_storage' 38 | #STORAGE = 'thumbor.storages.file_storage' 39 | #STORAGE = 'thumbor.storages.mixed_storage' 40 | 41 | # root path of the file storage 42 | FILE_STORAGE_ROOT_PATH = '/var/lib/thumbor/storage' 43 | 44 | # If you want to cache results, use this options to specify how to cache it 45 | # Set Expiration seconds to ZERO if you want them not to expire. 46 | #RESULT_STORAGE = 'thumbor.result_storages.file_storage' 47 | #RESULT_STORAGE_EXPIRATION_SECONDS = 60 * 60 * 24 # one day 48 | #RESULT_STORAGE_FILE_STORAGE_ROOT_PATH = '/tmp/thumbor/result_storage' 49 | 50 | RESULT_STORAGE_STORES_UNSAFE=False 51 | 52 | # stores the crypto key in each image in the storage 53 | # this is VERY useful to allow changing the security key 54 | STORES_CRYPTO_KEY_FOR_EACH_IMAGE = True 55 | 56 | REDIS_STORAGE_SERVER_HOST = 'localhost' 57 | REDIS_STORAGE_SERVER_PORT = 6379 58 | REDIS_STORAGE_SERVER_DB = 0 59 | REDIS_STORAGE_SERVER_PASSWORD = None 60 | 61 | # imaging engine to use to process images 62 | # OpenCV will still be used for smart detection when PIL is the engine 63 | # but does not support flipping when used as the engine. 64 | #ENGINE = 'thumbor.engines.graphicsmagick' 65 | ENGINE = 'thumbor.engines.pil' 66 | #ENGINE = 'thumbor.engines.opencv' 67 | 68 | # detectors to use to find Focal Points in the image 69 | # more about detectors can be found in thumbor's docs 70 | # at https://github.com/globocom/thumbor/wiki 71 | DETECTORS = [ 72 | 'thumbor.detectors.face_detector', 73 | 'thumbor.detectors.feature_detector', 74 | ] 75 | 76 | # Redis parameters for queued detectors 77 | REDIS_QUEUE_SERVER_HOST = 'localhost' 78 | REDIS_QUEUE_SERVER_PORT = 6379 79 | REDIS_QUEUE_SERVER_DB = 0 80 | REDIS_QUEUE_SERVER_PASSWORD = None 81 | 82 | # if you use face detection this is the file that 83 | # OpenCV will use to find faces. The default should be 84 | # fine, so change this at your own peril. 85 | # if you set a relative path it will be relative to 86 | # the thumbor/detectors/face_detector folder 87 | #FACE_DETECTOR_CASCADE_FILE = 'haarcascade_frontalface_alt.xml' 88 | 89 | # this is the security key used to encrypt/decrypt urls. 90 | # make sure this is unique and not well-known 91 | # This can be any string of up to 16 characters 92 | # Only used if keyfile is not specified in /etc/default/thumbor 93 | #SECURITY_KEY = "MY_SECURE_KEY" 94 | 95 | # Mixed storage classes. Change them to the fullname of the 96 | # storage you desire for each operation. 97 | #MIXED_STORAGE_FILE_STORAGE = 'thumbor.storages.file_storage' 98 | #MIXED_STORAGE_CRYPTO_STORAGE = 'thumbor.storages.no_storage' 99 | #MIXED_STORAGE_DETECTOR_STORAGE = 'thumbor.storages.no_storage' 100 | 101 | FILTERS = [ 102 | 'thumbor.filters.brightness', 103 | 'thumbor.filters.contrast', 104 | 'thumbor.filters.rgb', 105 | 'thumbor.filters.round_corner', 106 | 'thumbor.filters.quality', 107 | 'thumbor.filters.noise', 108 | 'thumbor.filters.watermark', 109 | 'thumbor.filters.equalize', 110 | 'thumbor.filters.fill', 111 | 'thumbor.filters.sharpen', 112 | 'thumbor.filters.strip_icc', 113 | 'thumbor.filters.frame', 114 | 115 | # can only be applied if there are already points for the image being served 116 | # this means that either you are using the local face detector or the image 117 | # has already went through remote detection 118 | # 'thumbor.filters.redeye', 119 | ] 120 | -------------------------------------------------------------------------------- /etc/thumbor.default: -------------------------------------------------------------------------------- 1 | # set this to 0 to disable thumbor, remove or set anything else to enable it 2 | # you can temporarily override this with 3 | # sudo service thumbor start force=1 4 | enabled=1 5 | 6 | # Location of the configuration file 7 | conffile=/etc/thumbor.conf 8 | 9 | # Location of the keyfile which contains the signing secret used in URLs 10 | keyfile=/etc/thumbor.key 11 | 12 | # IP address to bind to. Defaults to all IP addresses 13 | ip=127.0.0.1 14 | 15 | # TCP port to bind to. Defaults to port 8888. 16 | # multiple instances of thumbor can be started by putting several ports coma separeted 17 | # Ex: 18 | # port=8888,8889,8890 19 | # or 20 | # port=8888 #Default 21 | -------------------------------------------------------------------------------- /etc/thumbor.instances: -------------------------------------------------------------------------------- 1 | 4 2 | -------------------------------------------------------------------------------- /etc/thumbor.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/torchbox/vagrant-thumbor-base/42970754306194d0f42d1c0781b63bca67ff9e17/etc/thumbor.key -------------------------------------------------------------------------------- /etc/thumbor.nginx: -------------------------------------------------------------------------------- 1 | upstream thumbor { 2 | SERVER_STUB 3 | } 4 | 5 | server { 6 | listen PORT; 7 | server_name localhost; 8 | merge_slashes off; 9 | 10 | location / { 11 | proxy_pass http://thumbor; 12 | } 13 | 14 | location = /favicon.ico { 15 | return 204; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /etc/thumbor.port: -------------------------------------------------------------------------------- 1 | 8888 2 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -f .thumbor_installed ] 4 | then 5 | exit 6 | fi 7 | 8 | sudo aptitude -yq install curl 9 | curl http://python-distribute.org/distribute_setup.py | sudo python 10 | sudo echo "deb http://ppa.launchpad.net/thumbor/ppa/ubuntu precise main" | sudo tee -a /etc/apt/sources.list > /dev/null 11 | sudo echo "deb-src http://ppa.launchpad.net/thumbor/ppa/ubuntu precise main" | sudo tee -a /etc/apt/sources.list > /dev/null 12 | sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C6C3D73D1225313B 13 | sudo aptitude update -yq 14 | sudo aptitude install -yq thumbor 15 | 16 | sudo aptitude install -yq nginx 17 | sudo update-rc.d nginx enable > /dev/null 18 | sudo aptitude install -yq redis-server 19 | sudo update-rc.d redis-server enable > /dev/null 20 | 21 | THUMBOR_PORT=`cat host/etc/thumbor.port` 22 | THUMBOR_INSTANCES=`cat host/etc/thumbor.instances` 23 | BASE_PORT=9000 24 | PORTS='' 25 | SERVERS='' 26 | for ((i=1 ; i<=$THUMBOR_INSTANCES ; i++)) 27 | do 28 | PORTS="${PORTS}$(($BASE_PORT-1 + $i))," 29 | SERVERS="${SERVERS} server 127.0.0.1:$(($BASE_PORT-1 + $i));\n" 30 | done 31 | sudo cp host/etc/thumbor.nginx /etc/nginx/conf.d/thumbor.conf 32 | sudo perl -pi -e "s/SERVER_STUB/$SERVERS/;s/PORT/$THUMBOR_PORT/" /etc/nginx/conf.d/thumbor.conf 33 | sudo mv /etc/default/thumbor /etc/default/thumbor.orig 34 | sudo cp host/etc/thumbor.default /etc/default/thumbor 35 | echo "port="$PORTS | sudo tee -a /etc/default/thumbor > /dev/null 36 | sudo mv /etc/thumbor.conf /etc/thumbor.conf.orig 37 | sudo cp host/etc/thumbor.conf.default /etc/thumbor.conf 38 | cat host/etc/thumbor.conf.custom | sudo tee -a /etc/thumbor.conf > /dev/null 39 | sudo mv /etc/thumbor.key /etc/thumbor.key.orig 40 | if [ -s host/etc/thumbor.key ] 41 | then 42 | sudo cp host/etc/thumbor.key /etc/thumbor.key 43 | else 44 | < /dev/urandom tr -dc a-z0-9 | head -c16 | sudo tee /etc/thumbor.key > /dev/null 45 | fi 46 | 47 | sudo rm /var/lib/dhcp/* 48 | # Makes the packaged box a bit smaller but takes a while to run: 49 | #dd if=/dev/zero of=/tmp/ZEROS bs=1M ; rm /tmp/ZEROS 50 | 51 | touch .thumbor_installed 52 | --------------------------------------------------------------------------------