Tiny PHP Docker images

Docker has been around for a while now and I had my go at a few systems.
With some trial and error I worked up an intermediate knowledge of the inner workings of docker and how it feels to develop with it, from a developer and a devops perspective.

The DevOp in me wants to try out all the new tool, frameworks, scripts to automate as much as possible for my development, however the developer in me is very unhappy having to wait for hundreds of Megabytes (on larger projects it is in the GB range) of images to load and in the worst case I waited an hour for an image build to finish.

Hence I had to do something. I had to find a way to make those images smaller.
On one project we are using eZ Platform, which comes with a docker toolbox.

While developing with it, I don’t notice much, however when I send my project to be built on the CI server, I will always have to pull the base images provided which are quite large:

ezsystems/php 7.0-v1-dev 522.9 MB
ezsystems/php 7.0-v1 451.1 MB

This is a little bit of an overhead, so I searched in my scripts collection and put something together that will build me a stand alone php package, and called it packager which makes use of dockerize.

I can feed packager with a json file which describes which apt packages I want installed, which essential binaries I want and which applications I want to have packaged. Packager then uses an ubuntu:xenial image to execute those instructions, put all the files together and tars it out into the unix pipe.

Contents of package.json

{
"pre-commands": [],
"post-commands": [
"php -r \"copy('https://getcomposer.org/installer', 'composer-setup.php');\"",
"php composer-setup.php --install-dir=/tmp/build/usr/bin/ --filename=composer",
"php -r \"unlink('composer-setup.php');\""
],
"essentials": [
"env",
"bash",
"sh",
"dash"
],
"packages": [
"libcurl3",
"libedit-dev",
"libgd-dev",
"libmemcached-dev",
"libldb-dev",
"libxpm-dev",
"libxslt1-dev",
"libicu-dev",
"php",
"php-curl",
"php-fpm",
"php-gd",
"php-intl",
"php-memcached",
"php-mbstring",
"php-mysql",
"php-mysqlnd",
"php-pear",
"php-xml"
],
"bin": ["php", "php-fpm7.0"]
}
cat php.json \
| docker run \
--rm \
--name pckgr \
-ia stdin \
-a stdout \
-a stderr packager \
> build.tar

Then I define a Dockerfile for my image:

FROM busybox
ADD build.tar /

ENTRYPOINT ["php-fpm7.0", "-F"]

docker build -t local/php .

After I switched the PHP images the eZ application image was now only about 82MB small. The CI Server only needs to build the base image (which takes about 2 – 5 minutes to build) once a week and the application builds have cut down in time by about 6 minutes.
I have tried this with PHP and NGINX but failed to get erlang to run with it. Maybe some systems are not supposed to be run in isolation.
Check out my repository and feel free to contribute.

Advertisements

TwigSfHelper2ExtensionsBundle Release

It has been a while since I published some code online, however lately I had some time to look through my things and see what I can package as a plugin/bundle.

Since I have started development with Symfony2 rather than only Symfony 1.x I ran ahead and created my first bundle; the TwigSfHelper2ExtensionsBundle. Simply said this bundle is just a port of some of the Symfony 1.x text and date helpers into Twig filters.

Twig Filters included

  • distance_of_time_in_words: Displays two dates as “time ago”
  • time_ago_in_words: Same as distance_of_time_in_words but shows the difference of now
  • auto_link_text: Turns all urls and email addresses into clickable links. The +link+ parameter can limit what should be linked. Options are :all (default), :email_addresses, and :urls.
  • excerpt_text: Extracts an excerpt from the +text+ surrounding the +phrase+ with a number of characters on each side determined by +radius+. If the phrase isn’t found, nil is returned. Ex: “hello my world” | excerpt(“my”, 3) => “…lo my wo…”
  • simple_format_text: Returns +text+ transformed into html using very simple formatting rules Surrounds paragraphs with <tt>&lt;p&gt;</tt> tags, and converts line breaks into <tt>&lt;br /&gt;</tt> Two consecutive newlines(<tt>nn</tt>) are considered as a paragraph, one newline (<tt>n</tt>) is considered a linebreak, three or more consecutive newlines are turned into two newlines
  • strip_links_text: Turns all links into words, like “<a href=”something”>else</a>” to “else”.

Installation

Step 1: Add bundle to your deps file
[TwigSfHelper2ExtensionsBundle] 
git=http://github.com/mozzymoz/TwigSfHelper2ExtensionsBundle.git 
target=bundles/JustMozzy/TwigSfHelper2ExtensionsBundle
Step 2 Add bundle to your autoload.php and AppKernel:
'JustMozzy' => __DIR__.'/../vendor/bundles'
new JustMozzy\TwigSfHelper2ExtensionsBundle\TwigSfHelper2ExtensionsBundle(),

 

 

Process Monitor

Just a quick dump of a recommendation I got earlier.

Process Monitor is a very useful tool if you need to see what processes are using which resources on your machine. Here’s a short overview from the website

Overview of Process Monitor Capabilities

Process Monitor includes powerful monitoring and filtering capabilities, including:

  • More data captured for operation input and output parameters
  • Non-destructive filters allow you to set filters without losing data
  • Capture of thread stacks for each operation make it possible in many cases to identify the root cause of an operation
  • Reliable capture of process details, including image path, command line, user and session ID
  • Configurable and moveable columns for any event property
  • Filters can be set for any data field, including fields not configured as columns
  • Advanced logging architecture scales to tens of millions of captured events and gigabytes of log data
  • Process tree tool shows relationship of all processes referenced in a trace
  • Native log format preserves all data for loading in a different Process Monitor instance
  • Process tooltip for easy viewing of process image information
  • Detail tooltip allows convenient access to formatted data that doesn’t fit in the column
  • Cancellable search
  • Boot time logging of all operations

You can find the tool here