-
Notifications
You must be signed in to change notification settings - Fork 7
Templates: Normal
A normal template is for the most part exactly like any other Docker template except it has queryable data and a context that we create for that data before allowing Docker to create it's own context.
Just like any Docker image, you have a Dockerfile
, it can be transformed using variables and other stuff on a per-tag/group basis because we run all your Dockerfile's through ERB before creating your context for Docker.
-
@metadata
: A Metadata class holding all of the opts.yml data. - You have full access to Ruby and it's context from within ERB as well.
Lets build an image that installs prosody
on both Alpine and Ubuntu with each tag respectively having base packages shared across them and one having it's own unique package (bash) because Alpine is an embedded OS driven at simplicity, it has no bash
. This image uses the default base image of envygeeks/ubuntu:latest
which provides runit
in place of other run systems and provides extra stuff, you can read more about this image here: https://github.com/envygeeks/docker/tree/master/repos/ubuntu
opts.yml
-
repos/prosody
opts.yml
Dockerfile
copy/
maintainer: Your Name <[email protected]>
user: random
tags:
ubuntu: ubuntu
alpine: alpine
aliases:
latest: alpine
images:
tag:
ubuntu: "envygeeks/ubuntu:latest"
alpine: "envygeeks/alpine:latest"
packages:
all:
- prosody
group:
alpine:
- bash
package_commands:
group:
ubuntu: "apt-get update && apt-get install --no-install-recommends -y"
alpine: "apk --update add"
MAINTAINER <% @metadata.maintainer %>
FROM <%= @metadata.image %>
RUN <%= @metadata.package_command + " " + @metadata.packages %>
COPY copy /
MAINTAINER Your Name <[email protected]>
FROM envygeeks/alpine:latest
RUN apk --update add prosody bash
COPY copy /
MAINTAINER Your Name <[email protected]>
FROM envygeeks/ubuntu:latest
RUN apt-get update && apt-get install --no-install-recommends -y prosody
COPY copy /
sed -ri "s/__HOSTNAME__/$HOSTNAME/" \
/etc/prosody/prosody.cfg.lua
ssl_lines() {
grep -nE '\s+-{2}\s+enable:ssl$' /etc/prosody/prosody.cfg.lua | awk -F: '{
print $1
}'
}
if [ "$ENABLE_SSL" ]; then
for v in $(ssl_lines); do
sed -ri "${v}s/(\s*)-{2}\s+/\1/" /etc/prosody/prosody.cfg.lua
sed -ri "${v}s/\s+-{2}\s+enable:ssl\$//" \
/etc/prosody/prosody.cfg.lua
done
else
while { l=$(ssl_lines | head -n1); test -n "$l"; } do sed -i "${l}d" /etc/prosody/prosody.cfg.lua; done
for v in $(grep -nE '\s+-{2}\s+disable:ssl$' /etc/prosody/prosody.cfg.lua | awk -F: '{ print $1 }'); do
sed -ri "${v}s/(\s*)-{2}\s+/\1/" /etc/prosody/prosody.cfg.lua
sed -ri "${v}s/\s+-{2}\s+disable:ssl\$//" \
/etc/prosody/prosody.cfg.lua
done
fi
exec chpst -u prosody:prosody \
prosody
Upon building, you will get three images, random/prosody:ubuntu
, random/prosody:latest
, random/prosody:alpine
, and random/prosody:latest
will point to the image id of random/prosody:alpine
.
docker-template build prosody
docker-template build prosody:ubuntu
docker-template build prosody:alpine
docker-template run --rm -it random/prosody:alpine
docker-template run --rm -it random/prosody:ubuntu
docker-template run --rm -it random/prosody:latest
Copyright 2016 Jordon Bedwell - License: CC BY-SA 4.0