mirror of
https://github.com/jhillyerd/inbucket.git
synced 2025-12-17 17:47:03 +00:00
Docker best practices
- Install and remove OS and Go build deps in a single layer - Use COPY instead of ADD - WORKDIR now resolves ENV variables, use one - Use VOLUMES for configuration and datastore - Added launcher script start-inbucket.sh - Made docker-run.sh more powerful
This commit is contained in:
17
Dockerfile
17
Dockerfile
@@ -4,19 +4,22 @@
|
|||||||
FROM golang:1.6-alpine
|
FROM golang:1.6-alpine
|
||||||
MAINTAINER James Hillyerd, @jameshillyerd
|
MAINTAINER James Hillyerd, @jameshillyerd
|
||||||
|
|
||||||
# Dependencies
|
|
||||||
RUN apk update && apk add git
|
|
||||||
|
|
||||||
# Configuration (WORKDIR doesn't support env vars)
|
# Configuration (WORKDIR doesn't support env vars)
|
||||||
ENV INBUCKET_SRC $GOPATH/src/github.com/jhillyerd/inbucket
|
ENV INBUCKET_SRC $GOPATH/src/github.com/jhillyerd/inbucket
|
||||||
ENV INBUCKET_HOME /opt/inbucket
|
ENV INBUCKET_HOME /opt/inbucket
|
||||||
WORKDIR /opt/inbucket
|
WORKDIR $INBUCKET_HOME
|
||||||
ENTRYPOINT ["bin/inbucket"]
|
ENTRYPOINT ["/con/context/start-inbucket.sh"]
|
||||||
CMD ["/etc/opt/inbucket.conf"]
|
CMD ["/con/configuration/inbucket.conf"]
|
||||||
|
|
||||||
# Ports: SMTP, HTTP, POP3
|
# Ports: SMTP, HTTP, POP3
|
||||||
EXPOSE 10025 10080 10110
|
EXPOSE 10025 10080 10110
|
||||||
|
|
||||||
|
# Persistent Volumes, following convention at:
|
||||||
|
# https://github.com/docker/docker/issues/9277
|
||||||
|
# NOTE /con/context is also used, not exposed by default
|
||||||
|
VOLUME /con/configuration
|
||||||
|
VOLUME /con/data
|
||||||
|
|
||||||
# Build Inbucket
|
# Build Inbucket
|
||||||
ADD . $INBUCKET_SRC/
|
COPY . $INBUCKET_SRC/
|
||||||
RUN "$INBUCKET_SRC/etc/docker/install.sh"
|
RUN "$INBUCKET_SRC/etc/docker/install.sh"
|
||||||
|
|||||||
@@ -86,13 +86,13 @@ public.dir=%(install.dir)s/themes/%(theme)s/public
|
|||||||
|
|
||||||
# Path to the greeting HTML displayed on front page, can
|
# Path to the greeting HTML displayed on front page, can
|
||||||
# be moved out of installation dir for customization
|
# be moved out of installation dir for customization
|
||||||
greeting.file=/etc/opt/inbucket-greeting.html
|
greeting.file=/con/configuration/greeting.html
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
[datastore]
|
[datastore]
|
||||||
|
|
||||||
# Path to the datastore, mail will be written into subdirectories
|
# Path to the datastore, mail will be written into subdirectories
|
||||||
path=/var/opt/inbucket
|
path=/con/data
|
||||||
|
|
||||||
# How many minutes after receipt should a message be stored until it's
|
# How many minutes after receipt should a message be stored until it's
|
||||||
# automatically purged. To retain messages until manually deleted, set this
|
# automatically purged. To retain messages until manually deleted, set this
|
||||||
24
etc/docker/defaults/start-inbucket.sh
Executable file
24
etc/docker/defaults/start-inbucket.sh
Executable file
@@ -0,0 +1,24 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
# start-inbucket.sh
|
||||||
|
# description: start inbucket (runs within a docker container)
|
||||||
|
|
||||||
|
CONF_SOURCE="$INBUCKET_HOME/defaults"
|
||||||
|
CONF_TARGET="/con/configuration"
|
||||||
|
|
||||||
|
set -eo pipefail
|
||||||
|
|
||||||
|
install_default_config() {
|
||||||
|
local file="$1"
|
||||||
|
local source="$CONF_SOURCE/$file"
|
||||||
|
local target="$CONF_TARGET/$file"
|
||||||
|
|
||||||
|
if [ ! -e "$target" ]; then
|
||||||
|
echo "Installing default $file to $CONF_TARGET"
|
||||||
|
install "$source" "$target"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
install_default_config "inbucket.conf"
|
||||||
|
install_default_config "greeting.html"
|
||||||
|
|
||||||
|
exec "$INBUCKET_HOME/bin/inbucket" $*
|
||||||
@@ -2,4 +2,61 @@
|
|||||||
# docker-run.sh
|
# docker-run.sh
|
||||||
# description: Launch Inbucket's docker image
|
# description: Launch Inbucket's docker image
|
||||||
|
|
||||||
docker run -p 9000:10080 -p 2500:10025 -p 1100:10110 jhillyerd/inbucket
|
# Docker Image Tag
|
||||||
|
IMAGE="jhillyerd/inbucket"
|
||||||
|
|
||||||
|
# Ports exposed on host:
|
||||||
|
PORT_HTTP=9000
|
||||||
|
PORT_SMTP=2500
|
||||||
|
PORT_POP3=1100
|
||||||
|
|
||||||
|
# Volumes exposed on host:
|
||||||
|
VOL_CONFIG="/tmp/inbucket/config"
|
||||||
|
VOL_DATA="/tmp/inbucket/data"
|
||||||
|
|
||||||
|
set -eo pipefail
|
||||||
|
|
||||||
|
main() {
|
||||||
|
local run_opts=""
|
||||||
|
|
||||||
|
for arg in $*; do
|
||||||
|
case "$arg" in
|
||||||
|
-h)
|
||||||
|
usage
|
||||||
|
exit
|
||||||
|
;;
|
||||||
|
-r)
|
||||||
|
reset
|
||||||
|
;;
|
||||||
|
-d)
|
||||||
|
run_opts="$run_opts -d"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
|
||||||
|
docker run $run_opts \
|
||||||
|
-p $PORT_HTTP:10080 \
|
||||||
|
-p $PORT_SMTP:10025 \
|
||||||
|
-p $PORT_POP3:10110 \
|
||||||
|
-v "$VOL_CONFIG:/con/configuration" \
|
||||||
|
-v "$VOL_DATA:/con/data" \
|
||||||
|
"$IMAGE"
|
||||||
|
}
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
echo "$0 [options]" 2>&1
|
||||||
|
echo " -d detach - detach and print container ID" 2>&1
|
||||||
|
echo " -r reset - purge config and data before startup" 2>&1
|
||||||
|
echo " -h help - print this message" 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
reset() {
|
||||||
|
/bin/rm -rf "$VOL_CONFIG"
|
||||||
|
/bin/rm -rf "$VOL_DATA"
|
||||||
|
}
|
||||||
|
|
||||||
|
main $*
|
||||||
|
|||||||
@@ -4,9 +4,14 @@
|
|||||||
|
|
||||||
set -eo pipefail
|
set -eo pipefail
|
||||||
|
|
||||||
installdir="${INBUCKET_HOME}"
|
installdir="$INBUCKET_HOME"
|
||||||
srcdir="${INBUCKET_SRC}"
|
srcdir="$INBUCKET_SRC"
|
||||||
bindir="$installdir/bin"
|
bindir="$installdir/bin"
|
||||||
|
defaultsdir="$installdir/defaults"
|
||||||
|
contextdir="/con/context"
|
||||||
|
|
||||||
|
echo "### Installing OS Build Dependencies"
|
||||||
|
apk add --no-cache --virtual .build-deps git
|
||||||
|
|
||||||
# Setup
|
# Setup
|
||||||
export GOBIN="$bindir"
|
export GOBIN="$bindir"
|
||||||
@@ -16,7 +21,7 @@ go clean
|
|||||||
|
|
||||||
# Build
|
# Build
|
||||||
echo "### Fetching Dependencies"
|
echo "### Fetching Dependencies"
|
||||||
go get -d -t -v ./...
|
go get -t -v ./...
|
||||||
|
|
||||||
echo "### Testing Inbucket"
|
echo "### Testing Inbucket"
|
||||||
go test ./...
|
go test ./...
|
||||||
@@ -25,9 +30,19 @@ echo "### Building Inbucket"
|
|||||||
go build -o inbucket -ldflags "-X 'main.BUILDDATE=$builddate'" -v .
|
go build -o inbucket -ldflags "-X 'main.BUILDDATE=$builddate'" -v .
|
||||||
|
|
||||||
echo "### Installing Inbucket"
|
echo "### Installing Inbucket"
|
||||||
|
set -x
|
||||||
mkdir -p "$bindir"
|
mkdir -p "$bindir"
|
||||||
mkdir -p "/etc/opt"
|
install inbucket "$bindir"
|
||||||
mv inbucket "$bindir"
|
mkdir -p "$contextdir"
|
||||||
install etc/docker/inbucket.conf /etc/opt/inbucket.conf
|
install etc/docker/defaults/start-inbucket.sh "$contextdir"
|
||||||
install etc/docker/greeting.html /etc/opt/inbucket-greeting.html
|
|
||||||
cp -r themes "$installdir/"
|
cp -r themes "$installdir/"
|
||||||
|
mkdir -p "$defaultsdir"
|
||||||
|
cp etc/docker/defaults/inbucket.conf "$defaultsdir"
|
||||||
|
cp etc/docker/defaults/greeting.html "$defaultsdir"
|
||||||
|
set +x
|
||||||
|
|
||||||
|
echo "### Removing OS Build Dependencies"
|
||||||
|
apk del .build-deps
|
||||||
|
|
||||||
|
echo "### Removing $GOPATH"
|
||||||
|
rm -rf "$GOPATH"
|
||||||
|
|||||||
Reference in New Issue
Block a user