92 lines
2.5 KiB
Bash
Executable file
92 lines
2.5 KiB
Bash
Executable file
#!/bin/bash
|
||
|
||
version=0.20
|
||
program=${0##*/}
|
||
progdir=${0%/*}
|
||
if [ "$progdir" = "$program" ]; then progdir="."; fi
|
||
if [ "$progdir" = "." ]; then progdir="$PWD"; fi
|
||
parent=$(dirname "$progdir")
|
||
if [ "$parent" = "." ]; then parent="$PWD"; fi
|
||
if [[ $(uname) =~ CYGWIN.* ]]; then parent=$(echo "$parent" | sed -e 's/^\/cygdrive\/\(.\)/\1:/'); fi
|
||
|
||
|
||
function usage() {
|
||
cat <<EOF
|
||
NAME
|
||
$program - Build a datatracker docker image
|
||
|
||
SYNOPSIS
|
||
$program [OPTIONS]
|
||
|
||
DESCRIPTION
|
||
This script builds a Ubuntu-based docker image that has been
|
||
set up with the dependencies needed to easily run the IETF
|
||
datatracker in development mode. It uses docker/Dockerfile;
|
||
i.e., the Dockerfile in the same directory as this script.
|
||
|
||
OPTIONS
|
||
EOF
|
||
sed -n -E "s|(^\s+-[A-Za-z])\).*#(.*)|\1 \2|p" "$0"
|
||
cat <<EOF
|
||
|
||
AUTHOR
|
||
Written by:
|
||
Henrik Levkowetz, <henrik@levkowetz.com>
|
||
Lars Eggert, <lars@eggert.org>
|
||
|
||
COPYRIGHT
|
||
Copyright (c) 2016 IETF Trust and the persons identified as authors of
|
||
the code. All rights reserved. Redistribution and use in source and
|
||
binary forms, with or without modification, is permitted pursuant to,
|
||
and subject to the license terms contained in, the Revised BSD
|
||
License set forth in Section 4.c of the IETF Trust’s Legal Provisions
|
||
Relating to IETF Documents(https://trustee.ietf.org/license-info).
|
||
|
||
EOF
|
||
}
|
||
|
||
|
||
function die() {
|
||
echo -e "\n$program: error: $*" >&2
|
||
exit 1
|
||
}
|
||
|
||
|
||
function version() {
|
||
echo -e "$program $version"
|
||
}
|
||
|
||
|
||
trap 'echo "$program($LINENO): Command failed with error code $? ([$$] $0 $*)"; exit 1' ERR
|
||
|
||
# Default values
|
||
IMAGE=ietf/datatracker-environment
|
||
TAG=$(basename "$(svn info "$parent" | grep ^URL | awk '{print $2}') | tr -d '\r')")
|
||
LOCAL=1
|
||
|
||
# Option parsing
|
||
shortopts=hut:V
|
||
args=$(getopt -o$shortopts $*)
|
||
if [ $? != 0 ] ; then die "Terminating..." >&2 ; exit 1 ; fi
|
||
set -- $args
|
||
|
||
while true ; do
|
||
case "$1" in
|
||
-h) usage; exit;; # Show this help, then exit
|
||
-u) LOCAL=0;; # Upload image to repository after build
|
||
-t) TAG=$2; shift;; # Use this docker image tag
|
||
-V) version; exit;; # Show program version, then exit
|
||
--) shift; break;;
|
||
*) die "Internal error, inconsistent option specification: '$1'";;
|
||
esac
|
||
shift
|
||
done
|
||
|
||
# The program itself
|
||
docker rmi -f $IMAGE:trunk 2>/dev/null || true
|
||
docker build --progress plain -t "$IMAGE:$TAG" docker/
|
||
docker tag "$(docker images -q $IMAGE | head -n 1)" $IMAGE:latest
|
||
if [ -z "$LOCAL" ]; then
|
||
docker push $IMAGE:latest
|
||
docker push "$IMAGE:$TAG"
|
||
fi |