A worker model of type docker
can be spawned by a Hatchery Docker Swarm
In this example, we will build a Docker model able to build an AngularJS application with webfonts. To create webfonts, a grunt
task (optionally) requires fontforge
and ttfautohint
.
The following tools must be included in the model:
Node.js
and npm
bower
grunt-cli
gulp-cli
fontforge
ttfautohint
We will use the official nodejs image from Docker. In this image, there is already a user named node. For the example, we will compile ttfautohint
.
To build a Docker model, you need:
Copy this content in a file named Dockerfile
# User official Node.js Docker image
FROM node:6.10.1
#Answer 'yes' to each question
ENV DEBIAN_FRONTEND noninteractive
# Upgrade the debian packages
RUN (apt-get update && apt-get upgrade -y -q && apt-get -y -q autoclean && apt-get -y -q autoremove)
#The official image comes with npm; so we can use it to install some packages
RUN npm install -g grunt-cli gulp-cli bower
# Install fontforge for our specific need
RUN apt-get install -y fontforge
# Install packages and compile ttfautohint (still for our specific need)
RUN apt-get install -y libharfbuzz-dev libfreetype6-dev libqt4-dev\
&& cd /tmp \
&& curl -L http://download.savannah.gnu.org/releases/freetype/ttfautohint-1.6.tar.gz |tar xz\
&& cd ttfautohint-1.6\
&& ./configure\
&& make\
&& make install
# Change user. If you do not specify this command, the user will be root, and in our case,
# Bower will shout as it cannot be launched by root
USER node
# Specify a working directory on which the current user has write access
# Remember, a curl command will be, first, executed to download the worker
WORKDIR /home/node
from you shell, type the following command to build the Docker image:
docker build --no-cache --pull -t registry.my.infra.net/my/beautiful/worker:latest .
If you want to test it, you can launch your Docker in bash mode:
docker run -it registry.my.infra.net/my/beautiful/worker:latest /bin/bash
pwd
fontforge -v
exit
Now push it
docker push registry.my.infra.net/my/beautiful/worker:latest
sh -c
for a Unix environment.curl {{.API}}/download/worker/linux/$(uname -m) -o worker --retry 10 --retry-max-time 120 -C - && chmod +x worker && exec ./worker
to see all the available variables to interpolate for your worker parameters click hereNow you can specify this model in prerequisite on your job. Create a new prerequisite of type “model”, then choose your worker model in list
If you want to specify an image using a private registry or a private image. You need to check the private checkbox and fill credentials in username and password to access to your image. And if your image is not on docker hub but from a private registry you need to fill the registry info (the registry api url, for example for docker hub it’s https://index.docker.io/v1/ but we fill it by default).