Skip to content

Commit

Permalink
docker: Add dev Docker image
Browse files Browse the repository at this point in the history
* Switch to recent rebar3 build for erlang/rebar3#1326
* Add docker-compose.yml
* Update docs
  • Loading branch information
ddeboer committed Sep 21, 2016
1 parent c53773f commit 611b4ac
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 12 deletions.
11 changes: 11 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM alpine:3.4

COPY docker/zotonic.config /etc/zotonic/zotonic.config

RUN apk add --no-cache ca-certificates bash curl make gcc musl-dev g++ bsd-compat-headers git imagemagick inotify-tools wget \
&& apk add --no-cache --repository http://dl-3.alpinelinux.org/alpine/edge/community/ \
erlang erlang-inets erlang-compiler erlang-crypto erlang-mnesia erlang-ssl erlang-stdlib erlang-public-key erlang-tools erlang-dev erlang-asn1 erlang-syntax-tools erlang-eunit erlang-parsetools erlang-snmp erlang-sasl erlang-xmerl erlang-erl-interface

WORKDIR /opt/zotonic

VOLUME /opt/zotonic
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ APP := zotonic
# Erlang Rebar downloading
# see: https://groups.google.com/forum/?fromgroups=#!topic/erlang-programming/U0JJ3SeUv5Y
REBAR := ./rebar3
REBAR_URL := https://s3.amazonaws.com/rebar3/rebar3
REBAR_URL := https://s3-eu-west-1.amazonaws.com/zotonic-rebar/rebar3
REBAR_OPTS ?=
# Default target - update sources and call all compile rules in succession
.PHONY: all
Expand Down
47 changes: 41 additions & 6 deletions doc/developer-guide/docker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,67 @@
Docker
======

We offer two Docker images:
We offer three Docker images:

* `zotonic/zotonic-full`_ contains both Zotonic and PostgreSQL. Use this to get
started quickly.
* `zotonic/zotonic`_ contains only Zotonic. This image is most useful in
production setups or when you’re using Docker Compose with a separate
database container.
* `zotonic/zotonic-dev`_ contains make tools and Erlang. Use this image for
development work on Zotonic itself, where you’ll mount your Zotonic directory
as a volume in the container.

To use any of the images, first `download and install Docker`_.

Start a Zotonic image on your Docker machine::

# use a stable version:
docker run -d -p 8000:8000 zotonic/zotonic-full:0.17.0
$ docker run -d -p 8000:8000 zotonic/zotonic-full:0.17.0

# or a branch:
docker run -d -p 8000:8000 zotonic/zotonic-full:0.x
$ docker run -d -p 8000:8000 zotonic/zotonic-full:0.x

# or run the latest version from master:
docker run -d -p 8000:8000 zotonic/zotonic-full:latest
$ docker run -d -p 8000:8000 zotonic/zotonic-full:latest

Mount a volume that contains your Zotonic sites::

docker run -d -v `pwd`/sites:/opt/zotonic/user/sites zotonic/zotonic-full
$ docker run -d -v `pwd`/sites:/opt/zotonic/user/sites zotonic/zotonic-full

And mount a volume with your custom Zotonic modules::

docker run -d -v `pwd`/sites:/opt/zotonic/user/sites -v `pwd`/modules:/opt/zotonic/user/modules zotonic/zotonic-full
$ docker run -d -v `pwd`/sites:/opt/zotonic/user/sites -v `pwd`/modules:/opt/zotonic/user/modules zotonic/zotonic-full

zotonic-dev
-----------

You run the `zotonic-dev`_ container from your local Zotonic clone::

$ git clone https://github.com/zotonic/zotonic.git

To start the container, use Docker Compose::

$ docker-compose run --service-ports zotonic bash

This opens a shell prompt in the Zotonic container. A PostgreSQL container will
be started automatically as well. In the Zotonic container, you can enter any
command. So, to start Zotonic in debug mode::

$ bin/zotonic debug

The ``-service-ports`` flags exposes Zotonic’s port 8000 as your local port 80,
so you can view the :ref:`Zotonic status page <ref-status-site>` at
``http://localhost``.

You can also run other commands in the container, such as running the tests::

$ bin/zotonic runtests

Any changes you make in the Zotonic source files will be
:ref:`automatically compiled <automatic-recompilation>` in the container.

.. _zotonic/zotonic-full: https://hub.docker.com/r/zotonic/zotonic-full/
.. _zotonic/zotonic: https://hub.docker.com/r/zotonic/zotonic/
.. _zotonic/zotonic-dev: https://hub.docker.com/r/zotonic/zotonic-dev/
.. _download and install Docker: https://www.docker.com/products/docker
9 changes: 5 additions & 4 deletions doc/ref/modules/mod_development.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,12 @@ With this it is possible to see for a request path which dispatch rules are matc
.. image:: /img/development_dispatch_debug.png


.. _automatic-recompilation:

Automatic recompilation
-----------------------

The core Zotonic system starts either ``inotify-tools`` or ``fswatch``, depending on
The core Zotonic system starts either ``inotify-tools`` or ``fswatch``, depending on
which one is available. You have to install one of these to enable auto-compile
and auto-load of changed files.

Expand Down Expand Up @@ -92,7 +93,7 @@ If a changed file is detected then Zotonic will:

* If a beam file changes then the module will be loaded. If the beam file is
a Zotonic module then it will be automatically restarted if either the
function exports or the ``mod_schema`` changed.
function exports or the ``mod_schema`` changed.

* If the .yrl definition of the template parser changes, then the .erl version
of the parser is regenerated. (This will trigger a compile, which triggers a
Expand All @@ -105,7 +106,7 @@ Linux installation
On Linux this feature depends on the `inotifywait` tool, which is part
of the ``inotify-tools`` package. For displaying notifications, it
uses ``notify-send``::

sudo apt-get install inotify-tools libnotify-bin


Expand All @@ -115,7 +116,7 @@ Mac OS X installation
On Mac OS X (version 10.8 and higher), we use the external programs ``fswatch`` and
``terminal-notifier``::

sudo brew install fswatch
sudo brew install fswatch
sudo brew install terminal-notifier


Expand Down
20 changes: 20 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
version: '2'

services:
postgres:
image: postgres:9.5
environment:
POSTGRES_USER: zotonic
volumes:
- ./data:/data
working_dir: /data

zotonic:
image: zotonic/zotonic-dev
privileged: true
links:
- postgres
volumes:
- ./:/opt/zotonic
ports:
- 80:8000
24 changes: 24 additions & 0 deletions docker/docker-entrypoint-dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh


# If the command given is a zotonic command, pass it to zotonic; otherwise exec it directly.
if [ -x "/opt/zotonic/src/scripts/zotonic-$1" ]; then
set -x

HOME=/tmp
ZOTONIC_PIDFILE=/tmp/zotonic.pid
ZOTONIC_CONFIG_DIR=/etc/zotonic

export HOME ZOTONIC_PIDFILE ZOTONIC_CONFIG_DIR

# Create the pid file and enable zotonic to write to it
touch /run/zotonic.pid && chown zotonic /run/zotonic.pid

# Insert password from environment variable into zotonic.config
sed -i -e "s/{password, \"\"}/{password, \"${ZOTONIC_PASSWORD}\"}/" \
/etc/zotonic/zotonic.config

exec /usr/bin/gosu zotonic /opt/zotonic/bin/zotonic "$@"
else
exec "$@"
fi
20 changes: 19 additions & 1 deletion rebar.lock
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{"1.1.0",
[{<<"bcrypt">>,
{git,"https://github.com/smarkets/erlang-bcrypt",
{ref,"a63df34d4957dbb70a703c67c75ed9fee2c78971"}},
Expand Down Expand Up @@ -143,4 +144,21 @@
{<<"z_stdlib">>,
{git,"https://github.com/zotonic/z_stdlib.git",
{ref,"ace6cf5e06b3ba9c3407c1de451953cbb1b48406"}},
0}].
0}]}.
[
{pkg_hash,[
{<<"bert">>, <<"A87D6693515070A9B287C1043CB7E5B2406BE0357685022764BFBD2609703555">>},
{<<"cf">>, <<"69D0B1349FD4D7D4DC55B7F407D29D7A840BF9A1EF5AF529F1EBE0CE153FC2AB">>},
{<<"depcache">>, <<"65ECD265C5150E8F7BB269FA51CF9A2E504AE53D4D1EFB0AF8BB99BF2FC967E1">>},
{<<"edown">>, <<"6803599606B10F8E328D6D60C44CD16244CD2429908894C415FCE4211C3BFEFD">>},
{<<"epgsql">>, <<"DE16186C279FB73217C0666C7A21323D613EDA9395B56E122AA1B262815ADF06">>},
{<<"erlang_localtime">>, <<"497DFD4D13523D3E0EECDCB8D6D59857CF642A17A6BDC6133FF906FDAF2AEF21">>},
{<<"erlware_commons">>, <<"A04433071AD7D112EDEFC75AC77719DD3E6753E697AC09428FC83D7564B80B15">>},
{<<"goldrush">>, <<"2024BA375CEEA47E27EA70E14D2C483B2D8610101B4E852EF7F89163CDB6E649">>},
{<<"gproc">>, <<"2DF2D886F8F8A7B81A4B04AA17972B5965BBC5BF0100EA6D8E8AC6A0E7389AFE">>},
{<<"lager">>, <<"EEF4E18B39E4195D37606D9088EA05BF1B745986CF8EC84F01D332456FE88D17">>},
{<<"meck">>, <<"59CA1CD971372AA223138EFCF9B29475BDE299E1953046A0C727184790AB1520">>},
{<<"poolboy">>, <<"6B46163901CFD0A1B43D692657ED9D7E599853B3B21B95AE5AE0A777CF9B6CA8">>},
{<<"proper">>, <<"5EEF3FA0CAE017ECB4BF6FD6A144349A048E999223A4F1E98CE372FF1772EDD3">>},
{<<"recon">>, <<"281F2CBB439FE3C043773EE6C83172ABD80326DCC6153F6430E4D4E6B14D7E9D">>}]}
].

0 comments on commit 611b4ac

Please sign in to comment.