Hey Noah,
Since the Ruby runtime runs on the
Flexible Environment, you can use
runtime: custom in app.yaml and supply a Dockerfile (in which the first line will be "
FROM gcr.io/google_appengine/ruby") (see
here a link to the github page of the Ruby runtime Docker image) which will install ImageMagick.
To install ImageMagick in the Dockerfile, you'd probably want to create a script that the Dockerfile runs, which will group together the many commands needed to install the dependencies and build from source. The script would look something like the following:
#!/bin/bash
apt-get -y install \
build-essential \
checkinstall \
libx11-dev \
libxext-dev \
zlib1g-dev \
libpng12-dev \
libjpeg-dev \
libfreetype6-dev \
libxml2-dev
apt-get -y build-dep imagemagick
wget http://www.imagemagick.org/download/ImageMagick.tar.gz
tar -xzvf ImageMagick.tar.gz
cd ImageMagick*
./configure
make
make install
... and the Dockerfile would include lines like:
ADD . /app/
RUN chmod +x /app/install-imagick.sh
RUN /app/install-imagick.sh
This will make ImageMagick available on the VM which runs your Ruby process. You can then call the program from Ruby using any of the various methods by which this can be done (
see here a blog post referencing 5 different ways to run commands from Ruby).
Although you could run ImageMagick to resize images dynamically on each request, this is not the most efficient way to go about it if all you require are thumbnails.
For thumbnails, I would recommend, whenever an image is uploaded, creating a process that will use ImageMagick to create and store a resized version for future use. You can use
Cloud Pub/Sub to create "task queues" in this way. The basic steps would be:
1. Receive the image upload and store the full image in Cloud Storage
2. Push a message to the Pub/Sub topic you created to manage this workflow (give it a name like "thumbnail-creation")
3. Have a pool of instances with ImageMagick installed who will subscribe to this topic
4. When an instance receives a request corresponding to the published message, have it download the image, and then resize and store the image as a thumbnail
I hope this is helpful, let me know if you have any further questions; I'll be happy to assist!
Cheers,
Nick
Cloud Platform Community Support