duneci-proxy 967 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
#! /bin/bash

set -e
set -u

usage() {
  cat >&2 <<-EOT
	usage: duneci-proxy <network> <name>

	Setup an internal network <network> (if it does not already exist) and a
	proxy running in container <name> using /srv/<name>/squid.conf.

13
	If <name> already exists, it is stopped and recreated (for updates).
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
	EOT

  exit ${1:-0}
}

if [ $# -ne 2 ]; then
  usage
fi

network=${1}
name=${2}
configdir=/srv/${name}
configfile=${configdir}/squid.conf

if [ ! -e ${configfile} ]; then
  echo "E: ${configfile} does not exist" >&2
  exit 1
fi

if [ -z "$(docker network ls -f name=${network})" ]; then
  docker network create --internal --driver=bridge ${network}
fi

# Ignore error on stop, it might not run (yet)
docker stop ${name} || :
docker rm -v ${name} || :

docker create --name ${name} \
  --restart always --read-only --security-opt no-new-privileges \
  -v /srv/${name}:/srv/squid:ro \
  duneci/proxy
docket network connect ${network} ${name}
docker start ${name}