Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
Based on 1and1internet/ubuntu but with less custom
  • Loading branch information
VibroAxe committed Dec 6, 2018
0 parents commit 4ef50d6
Show file tree
Hide file tree
Showing 16 changed files with 238 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM ubuntu:bionic
MAINTAINER SteamCache.Net Team <[email protected]>
ARG DEBIAN_FRONTEND=noninteractive
RUN \
apt-get -y update && apt-get -y upgrade && \
apt-get -y install supervisor curl wget bzip2 locales && \
locale-gen en_GB.utf8 && \
update-locale LANG=en_GB.utf8 && \
mkdir --mode 777 -p /var/log/supervisor && \
apt-get -y clean && \
rm -rf /var/lib/apt/lists/*
ENV \
SUPERVISORD_EXIT_ON_FATAL=1 \
LC_ALL=en_GB.UTF-8 \
LANG=en_GB.UTF-8 \
LANGUAGE=en_GB.UTF-8
COPY overlay/ /
RUN chmod -R 755 /init /hooks
ENTRYPOINT ["/bin/bash", "-e", "/init/entrypoint"]
CMD ["/init/supervisord"]
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Ubuntu Docker Image

This image provides a standard ubuntu docker base image for other docker images to build on top of.

It is currently based on 18.04 LTS (Bionic Beaver)

## Extending this image

You can easily extend the behavour of this image in the following ways

* `/hooks/entrypoint-pre.d/`
Executables placed in this directory are executed very early on, before anything else is done.

* `/hooks/entrypoint-run`
If it exists, this is executed if the default command is not overridden. After it's execution completes the default command is executed.

* `/hooks/entrypoint-exec`
If it exists, this is executed if default command is overridden. After it's execution completes the default command is executed.

* `/hooks/supervisord-pre.d/`
Executables placed in this directory are executed just before supervisord is executed.

* `/hooks/supervisord-ready`
If it exists, this is executed once supervisord is read. This is triggered from supervisord itself, when it fires the SUPERVISOR_STATE_CHANGE_RUNNING event.

## Usage

This docker image is not designed for use by anyone outside of the steamcache organisation, you're welcome to try, but support will be limited: HERE BE DRAGONS

1. Make a Dockerfile and specify `steamcache/ubuntu` on the `FROM` line.
2. Anything you want run in the container should be started by supervisord.
3. Use a directory called overlay if you need to copy files in to your new image (see Dockerfile for this image as an example).

## Building and testing

To build just run `docker build --tag steamcache/ubuntu:testing .`.
To test you can run `./run_tests.sh`

13 changes: 13 additions & 0 deletions overlay/etc/apt/apt.conf.d/docker-autoremove-suggests
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Since Docker users are looking for the smallest possible final images, the
# following emerges as a very common pattern:
# RUN apt-get update \
# && apt-get install -y <packages> \
# && <do some compilation work> \
# && apt-get purge -y --auto-remove <packages>
# By default, APT will actually _keep_ packages installed via Recommends or
# Depends if another package Suggests them, even and including if the package
# that originally caused them to be installed is removed. Setting this to
# "false" ensures that APT is appropriately aggressive about removing the
# packages it added.
# https://aptitude.alioth.debian.org/doc/en/ch02s05s05.html#configApt-AutoRemove-SuggestsImportant
Apt::AutoRemove::SuggestsImportant "false";
16 changes: 16 additions & 0 deletions overlay/etc/apt/apt.conf.d/docker-clean
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Since for most Docker users, package installs happen in "docker build" steps,
# they essentially become individual layers due to the way Docker handles
# layering, especially using CoW filesystems. What this means for us is that
# the caches that APT keeps end up just wasting space in those layers, making
# our layers unnecessarily large (especially since we'll normally never use
# these caches again and will instead just "docker build" again and make a brand
# new image).
# Ideally, these would just be invoking "apt-get clean", but in our testing,
# that ended up being cyclic and we got stuck on APT's lock, so we get this fun
# creation that's essentially just "apt-get clean".
DPkg::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };
APT::Update::Post-Invoke { "rm -f /var/cache/apt/archives/*.deb /var/cache/apt/archives/partial/*.deb /var/cache/apt/*.bin || true"; };
Dir::Cache::pkgcache "";
Dir::Cache::srcpkgcache "";
# Note that we do realize this isn't the ideal way to do this, and are always
# open to better suggestions (https://github.com/docker/docker/issues).
9 changes: 9 additions & 0 deletions overlay/etc/apt/apt.conf.d/docker-gzip-indexes
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Since Docker users using "RUN apt-get update && apt-get install -y ..." in
# their Dockerfiles don't go delete the lists files afterwards, we want them to
# be as small as possible on-disk, so we explicitly request "gz" versions and
# tell Apt to keep them gzipped on-disk.
# For comparison, an "apt-get update" layer without this on a pristine
# "debian:wheezy" base image was "29.88 MB", where with this it was only
# "8.273 MB".
Acquire::GzipIndexes "true";
Acquire::CompressionTypes::Order:: "gz";
4 changes: 4 additions & 0 deletions overlay/etc/apt/apt.conf.d/docker-no-languages
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# In Docker, we don't often need the "Translations" files, so we're just wasting
# time and space by downloading them, and this inhibits that. For users that do
# need them, it's a simple matter to delete this file and "apt-get update". :)
Acquire::Languages "none";
4 changes: 4 additions & 0 deletions overlay/etc/apt/apt.conf.d/dpkg-options
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Dpkg::Options {
"--force-confdef";
"--force-confold";
}
14 changes: 14 additions & 0 deletions overlay/etc/apt/sources.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
deb http://mirrorservice.org/sites/archive.ubuntu.com/ubuntu/ bionic main restricted
deb-src http://mirrorservice.org/sites/archive.ubuntu.com/ubuntu/ bionic main restricted
deb http://mirrorservice.org/sites/archive.ubuntu.com/ubuntu/ bionic-updates main restricted
deb-src http://mirrorservice.org/sites/archive.ubuntu.com/ubuntu/ bionic-updates main restricted
deb http://mirrorservice.org/sites/archive.ubuntu.com/ubuntu/ bionic universe
deb-src http://mirrorservice.org/sites/archive.ubuntu.com/ubuntu/ bionic universe
deb http://mirrorservice.org/sites/archive.ubuntu.com/ubuntu/ bionic-updates universe
deb-src http://mirrorservice.org/sites/archive.ubuntu.com/ubuntu/ bionic-updates universe
deb http://mirrorservice.org/sites/archive.ubuntu.com/ubuntu/ bionic-security main restricted
deb-src http://mirrorservice.org/sites/archive.ubuntu.com/ubuntu/ bionic-security main restricted
deb http://mirrorservice.org/sites/archive.ubuntu.com/ubuntu/ bionic-security universe
deb-src http://mirrorservice.org/sites/archive.ubuntu.com/ubuntu/ bionic-security universe
deb http://mirrorservice.org/sites/archive.ubuntu.com/ubuntu/ bionic-security multiverse
deb-src http://mirrorservice.org/sites/archive.ubuntu.com/ubuntu/ bionic-security multiverse
Empty file.
18 changes: 18 additions & 0 deletions overlay/etc/supervisor/supervisord.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[supervisord]
nodaemon=true
logfile=/var/log/supervisor/supervisord.log
pidfile=/var/run/supervisord.pid
user = root

[eventlistener:fatal_check]
command=/etc/supervisor/exit_on_fatal.py
events=PROCESS_STATE_FATAL
autostart=true
autorestart=false
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

[include]
files = /etc/supervisor/conf.d/*.conf
Empty file added overlay/hooks/.gitkeep
Empty file.
Empty file.
Empty file.
5 changes: 5 additions & 0 deletions overlay/hooks/supervisord-ready
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/bin/bash

# Default empty script - supervisord fails if this doesn't exist. Override it in child images if required

exit 0
68 changes: 68 additions & 0 deletions overlay/init/entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
#!/usr/bin/env bash

die () {
echo "ERROR: ${1}"
exit 1
}

check_depending_env () {
if [ -n "${DEPENDING_ENVIRONMENT_VARS}" ]; then
MISSING_ENVIRONMENT_VARS=()
echo -n "* Checking depending environment variables "
for e in ${DEPENDING_ENVIRONMENT_VARS}; do
if [ ! -v "${e}" ]; then
MISSING_ENVIRONMENT_VARS+=("${e}")
fi
done
if [ ${#MISSING_ENVIRONMENT_VARS[@]} -gt 0 ]; then
echo "[missing variables]"
for missing in "${MISSING_ENVIRONMENT_VARS[@]}"; do
echo " * ${missing}"
done
echo
die "Missing environment variables"
fi
echo -n "[done]"
echo
fi
}

[[ ${DOCKER_DEBUG} ]] && set -x

# Set exec-bit automatic. When adding hooks in a Dockerfile, we shoulnt also haveto think about setting +x
# in the Dockerfile for the same file. If you want to disable a hook, rename it.
chmod +x /init/setup /hooks/{entrypoint-pre.d/*,entrypoint-run,entrypoint-exec,supervisord-pre.d/*,supervisord-ready} 2> /dev/null || true

entrypoint_pre=$(ls /hooks/entrypoint-pre.d/* 2>/dev/null | sort -n )
if [ "$entrypoint_pre" != "" ]; then
for hook in $entrypoint_pre; do
echo "Executing hook ${hook}"
/bin/bash -c "${hook}"
if [ "$?" != "0" ]; then
die "hook ${hook}} returned a non-zero exit status '$?'"
fi
done
fi

[[ -f "/hooks/entrypoint-pre" ]] && echo "The /hooks/entrypoint-pre hook has been replaced with /hooks/entrypoint-pre.d/*" && exit 1

[[ -f "/init/setup" ]] && /init/setup

eval ${SETUP:-}

case ${1} in
run)
check_depending_env
[[ -f "/hooks/entrypoint-run" ]] && /hooks/entrypoint-run
if [[ -e /init/supervisord && -d /etc/supervisor ]]; then
# Use exec so we replace our current process so signals can get through
exec /bin/bash /init/supervisord
else
exec /bin/bash
fi
;;
*)
[[ -f "/hooks/entrypoint-exec" ]] && /hooks/entrypoint-exec
exec $*
;;
esac
29 changes: 29 additions & 0 deletions overlay/init/supervisord
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/bash

[ ${DOCKER_DEBUG} ] && set -x

die () {
echo "ERROR: ${1}"
exit 1
}

# PID, trap, wait; all belongs to 'docker stop' signal handeling.
# This is the same logic as the parent docker container, but rather this,
# than creating a one-time process in supervisord to handle this logic.
PID=; trap '[[ ${PID} ]] && kill ${PID}; exit 0' SIGTERM

supervisord_pre=$(ls /hooks/supervisord-pre.d/* 2>/dev/null | sort -n )
if [ "$supervisord_pre" != "" ]; then
for hook in $supervisord_pre; do
echo "Executing hook ${hook}"
/bin/bash -c "${hook}"
if [ "$?" != "0" ]; then
die "hook ${hook}} returned a non-zero exit status '$?'"
fi
done
fi

[[ -f "/hooks/supervisord-pre" ]] && echo "The /hooks/supervisord-pre hook has been replaced with /hooks/supervisord-pre.d/*" && exit 1
#[ -f "/hooks/supervisord-pre" ] && /hooks/supervisord-pre

exec /usr/bin/supervisord -n -c /etc/supervisor/supervisord.conf -e ${SUPERVISORD_LOGLEVEL:-error}

0 comments on commit 4ef50d6

Please sign in to comment.