Skip to content

Build docker images for a Mojolicious web server using Openshift's source-to-image

License

Notifications You must be signed in to change notification settings

istreeter/s2i-mojo-container

Repository files navigation

s2i-mojo-container

This is the source for building Docker images to run a Mojolicious web application using Openshift's source-to-image.

This repo is used to build a Docker base image at Docker Hub. Use the base image to build any Mojolicious web application from source using Openshift's source-to-image.

Concepts

Mojolicious is a perl web application framework, designed for simple and complex web applications. Hypnotoad is the UNIX optimized preforking web server that ships with Mojolicious. It is optimized specifically for production environments out of the box.

Source to image (S2I) is a toolkit for building Docker images from source code. S2I makes it easy to build Docker images that take application source code as an input and produce a new image that runs the assembled application as output.

The OpenShift Documentation has lots of information on using S2I.

The source in this repo is based on the SCL/Openshift repo for building perl apps with S2I. That repo uses Apache and mod_perl in the Docker image, whereas this repo uses Hypnotoad without requiring Apache.

Build an application

You will need the S2I standalone script. The S2I build syntax is:

$ s2i build <application-source> <base-image-name> <output-image-name>

Build the test application in this repo:

$ s2i build git://github.com/istreeter/s2i-mojo-container --context-dir=test/test-app istreeter/mojo-701-perl-516 mojo-test-app
$ docker run -p 8080:8080 mojo-test-app

Build the Photobooth Mojolicious lite app from diegok

$ s2i build https://github.com/diegok/PhotoBooth.git istreeter/mojo-701-perl-516 photo-booth
$ docker run -p 8080:8080 photo-booth

Build the fastnotes Mojolicious app from koorchik

$ s2i build git://github.com/koorchik/FastNotes-Proto.git istreeter/mojo-701-perl-516 fastnotes-proto
$ docker run -p 8080:8080 fastnotes-proto

Build the Ado Mojolicious app from kberov

$ s2i build git://github.com/kberov/Ado.git istreeter/mojo-701-perl-516 ado
$ docker run -p 8080:8080 ado

The assemble script

The assemble script makes following things happen when you run "s2i build":

  1. Copies the application git repo to /opt/app-root/
  2. Installs dependencies listed in your cpanfile (if present)
  3. Builds the application from a Build.PL script (if present)

Use the environment variable ENABLE_CPAN_TEST to test dependencies when they are installed. Use the environment variable CPAN_MIRROR to set your preferred mirror. For example:

$ s2i build -e "ENABLE_CPAN_TEST=true" -e "CPAN_MIRROR=http://cpan.cpantesters.org/" <application-source> <base-image-name> <output-image-name>

The base image

  1. Based on centos7
  2. Perl packages installed with yum
  3. openssl installed installed with yum
  4. Mojolicious, NET::SSLeay and IO::Socket::SSL installed from cpan
  5. User is non-root, for compatibility with openshift

The run script

The run script runs hypnotoad on your application.

Use the MOJO_SCRIPT environment variable to tell the image the location of your script in your git repo. Either one of the following options will work:

$ s2i build -e "MOJO_SCRIPT=scripts/my_app.pl" <application-source> <base-image-name> <output-image-name>
$ docker run -p 8080:8080 -e "MOJO_SCRIPT=scripts/my_app.pl" <image-name>

If MOJO_SCRIPT is not set, it will try to locate your application by testing. First, it looks for app.pl, index.pl, script/app.pl, script/index.pl. If it still hasn't found a script, it searches your repo directories bin, script, scripts, and "." for anything that is executable or has suffix ".pl". It tries to find anything that can be executed by hypnotoad

Having found the application, it runs hypnotoad in the foreground

Which version?

Mojolicious developers occasionally make breaking changes so different images are provided to support applications using different versions.

The names of the images are mojo-{Mojolicious version}-perl-{perl version}. For example, the image mojo-701-perl-516 comes with Mojolicious version 7.01 and Perl version 5.16

About

Build docker images for a Mojolicious web server using Openshift's source-to-image

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published