Created
September 2, 2015 19:05
-
-
Save thepaul/65ebca6d2a88fffbcdf0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/tools/dockerz/Dockerfile b/tools/dockerz/Dockerfile | |
new file mode 100644 | |
index 0000000..0eafb35 | |
--- /dev/null | |
+++ b/tools/dockerz/Dockerfile | |
@@ -0,0 +1,17 @@ | |
+FROM ubuntu:trusty | |
+MAINTAINER <[email protected]> | |
+ | |
+RUN apt-get -y update \ | |
+ && apt-get install --no-install-recommends -y \ | |
+ openssh-server aptitude software-properties-common git vim emacs24-nox pssh \ | |
+ clusterssh iotop iftop htop sysstat screen tree strace cppcheck \ | |
+ && apt-add-repository "deb http://hatchery.lab.epochlabs.com/el_private_repo binary/" \ | |
+ && aptitude -y update \ | |
+ && aptitude -y -o Aptitude::Cmdline::ignore-trust-violations=true full-upgrade | |
+ | |
+RUN mkdir -vp /root/.ssh && chmod -v 600 /root/.ssh | |
+ | |
+CMD ["/bin/bash", "-ec", \ | |
+ "cat /config/rootuser.pub >> /root/.ssh/authorized_keys; \ | |
+ cp -v /config/ssh_host_rsa_key /etc/ssh; \ | |
+ /etc/init.d/ssh start '-D -e -f /config/sshd_config'"] | |
diff --git a/tools/dockerz/cleanup b/tools/dockerz/cleanup | |
new file mode 100755 | |
index 0000000..59b1418 | |
--- /dev/null | |
+++ b/tools/dockerz/cleanup | |
@@ -0,0 +1,14 @@ | |
+#!/bin/bash | |
+ | |
+configdir=${COFFEE_DOCKERZ_CONFIG:?COFFEE_DOCKERZ_CONFIG must be set.} | |
+ | |
+"$(dirname "$0")"/lscontainers | while read cntnr; do | |
+ echo -n "stopping $cntnr: " | |
+ docker kill "$cntnr" && | |
+ docker rm "$cntnr" > /dev/null && | |
+ rm -rfv "$configdir/containers/$cntnr" | |
+done | |
+ | |
+rm -fv "$configdir"/rootuser{,.pub} "$configdir"/{ssh_config,knownhosts} | |
+rmdir -v "$configdir"/containers | |
+rmdir -v "$configdir" | |
diff --git a/tools/dockerz/connect b/tools/dockerz/connect | |
new file mode 100755 | |
index 0000000..9b757e1 | |
--- /dev/null | |
+++ b/tools/dockerz/connect | |
@@ -0,0 +1,10 @@ | |
+#!/bin/bash | |
+ | |
+configdir=${COFFEE_DOCKERZ_CONFIG:?COFFEE_DOCKERZ_CONFIG must be set.} | |
+ | |
+if [ ! -d "$configdir/containers" ]; then | |
+ echo "Config dir $configdir is not running containers" >&2 | |
+ exit 1 | |
+fi | |
+ | |
+exec ssh -F "$configdir/ssh_config" "$@" | |
diff --git a/tools/dockerz/lscontainers b/tools/dockerz/lscontainers | |
new file mode 100755 | |
index 0000000..9cee454 | |
--- /dev/null | |
+++ b/tools/dockerz/lscontainers | |
@@ -0,0 +1,6 @@ | |
+#!/bin/bash | |
+ | |
+configdir=${COFFEE_DOCKERZ_CONFIG:?COFFEE_DOCKERZ_CONFIG must be set.} | |
+ | |
+find "$configdir/containers" -mindepth 1 -maxdepth 1 \ | |
+ -type d ! -name ".*" ! -name $'*\n*' -printf '%f\n' | |
diff --git a/tools/dockerz/run b/tools/dockerz/run | |
new file mode 100755 | |
index 0000000..99173dd | |
--- /dev/null | |
+++ b/tools/dockerz/run | |
@@ -0,0 +1,39 @@ | |
+#!/bin/bash -e | |
+ | |
+configdir=${COFFEE_DOCKERZ_CONFIG:?COFFEE_DOCKERZ_CONFIG must be set.} | |
+name=${1:?Usage: $0 [containername]} | |
+image=${2:-coffee1} | |
+ | |
+cdir="$configdir/containers/$name" | |
+mkdir -p "$cdir" | |
+ | |
+ssh-keygen -t rsa -f "$cdir"/ssh_host_rsa_key -b 2048 -C "host ssh key for docker $name" -N '' | |
+ | |
+cp "$configdir"/rootuser.pub "$cdir" | |
+ | |
+cat > "$cdir"/sshd_config <<EOF | |
+Protocol 2 | |
+HostKey /etc/ssh/ssh_host_rsa_key | |
+LogLevel VERBOSE | |
+PermitRootLogin without-password | |
+PrintMotd no | |
+PrintLastLog no | |
+AcceptEnv LANG LC_* | |
+UsePAM yes | |
+EOF | |
+ | |
+docker run -d -v "$cdir":/config:ro --name "$name" "$image" | |
+ | |
+ipaddr=$(docker inspect -f '{{.NetworkSettings.IPAddress}}' "$name") | |
+[ -n "$ipaddr" ] | |
+ | |
+echo "$ipaddr,$name $(cat "$cdir"/ssh_host_rsa_key.pub)" >> "$configdir"/knownhosts | |
+ | |
+cat >> "$configdir"/ssh_config <<EOF | |
+ | |
+Host $name | |
+ HostName $ipaddr | |
+ User root | |
+ IdentityFile $configdir/rootuser | |
+ UserKnownHostsFile $configdir/knownhosts | |
+EOF | |
diff --git a/tools/dockerz/setup b/tools/dockerz/setup | |
new file mode 100755 | |
index 0000000..bad68e0 | |
--- /dev/null | |
+++ b/tools/dockerz/setup | |
@@ -0,0 +1,8 @@ | |
+#!/bin/bash -e | |
+ | |
+configdir=$(mktemp -d -t coffeedockerz.XXXXXXXX) | |
+ | |
+ssh-keygen -t rsa -f "$configdir"/rootuser -b 2048 -C "user ssh key for test docker conns" -N '' 1>&2 | |
+touch "$configdir"/knownhosts "$configdir"/ssh_config | |
+ | |
+echo "export COFFEE_DOCKERZ_CONFIG=$configdir" | |
diff --git a/tools/dockerz/stop b/tools/dockerz/stop | |
new file mode 100755 | |
index 0000000..42388ec | |
--- /dev/null | |
+++ b/tools/dockerz/stop | |
@@ -0,0 +1,4 @@ | |
+#!/bin/bash | |
+ | |
+name=$1 | |
+docker kill "$1" | |
diff --git a/tools/dockerz/stop_all b/tools/dockerz/stop_all | |
new file mode 100755 | |
index 0000000..4e613b0 | |
--- /dev/null | |
+++ b/tools/dockerz/stop_all | |
@@ -0,0 +1,5 @@ | |
+#!/bin/bash | |
+ | |
+configdir=${COFFEE_DOCKERZ_CONFIG:?COFFEE_DOCKERZ_CONFIG must be set.} | |
+ | |
+"$(dirname "$0")"/lscontainers | xargs -r docker kill |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment