From 908e81f805433b4083a48f7651cc8508aa6bd1e5 Mon Sep 17 00:00:00 2001 From: Mark Stillwell Date: Mon, 3 Nov 2014 10:45:39 +0000 Subject: [PATCH] added init script to dockerfile... --- Dockerfile | 28 ++++++++++++++++++++++++++-- keys/phusion.key => phusion.key | 0 scripts/setkey.sh | 24 ------------------------ 3 files changed, 26 insertions(+), 26 deletions(-) rename keys/phusion.key => phusion.key (100%) delete mode 100755 scripts/setkey.sh diff --git a/Dockerfile b/Dockerfile index cbf9317..d1dcce9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,29 @@ FROM phusion/baseimage:latest MAINTAINER Mark Stillwell -COPY scripts/setkey.sh /etc/my_init.d/05-setkey -RUN chmod 755 /etc/my_init.d/05-setkey +RUN mkdir -p /etc/my_init.d && \ + > /etc/my_init.d/05-setkey echo '#!/bin/bash\n\ +ATTEMPTS=30\n\ +\n\ +mkdir -p /root/.ssh\n\ +chmod 700 /root/.ssh\n\ +\n\ +TMPFILE=$(mktemp)\n\ +while [ ! -f /root/.ssh/authorized_keys ] && [ ${ATTEMPTS} -gt 0 ]; do\n\ + ATTEMPTS=$((${ATTEMPTS}-1))\n\ + curl -s http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key\\\n\ + > ${TMPFILE} 2>/dev/null\n\ + if [ $? -eq 0 ]; then\n\ + cat ${TMPFILE} >> /root/.ssh/authorized_keys\n\ + chmod 0600 /root/.ssh/authorized_keys\n\ + echo "Successfully retrieved public key from instance metadata"\n\ + echo "********************************************************"\n\ + echo "AUTHORIZED KEYS"\n\ + echo "********************************************************"\n\ + cat /root/.ssh/authorized_keys\n\ + echo\n\ + echo "********************************************************"\n\ + fi\n\ +done\n\ +rm -f ${TMPFILE}\n' && \ + chmod 755 /etc/my_init.d/05-setkey diff --git a/keys/phusion.key b/phusion.key similarity index 100% rename from keys/phusion.key rename to phusion.key diff --git a/scripts/setkey.sh b/scripts/setkey.sh deleted file mode 100755 index ea8f6c5..0000000 --- a/scripts/setkey.sh +++ /dev/null @@ -1,24 +0,0 @@ -#!/bin/bash -ATTEMPTS=30 - -mkdir -p /root/.ssh -chmod 700 /root/.ssh - -TMPFILE=$(mktemp) -while [ ! -f /root/.ssh/authorized_keys ] && [ ${ATTEMPTS} -gt 0 ]; do - ATTEMPTS=$((${ATTEMPTS}-1)) - curl -s http://169.254.169.254/latest/meta-data/public-keys/0/openssh-key \ - > ${TMPFILE} 2>/dev/null - if [ $? -eq 0 ]; then - cat ${TMPFILE} >> /root/.ssh/authorized_keys - chmod 0600 /root/.ssh/authorized_keys - echo "Successfully retrieved public key from instance metadata" - echo "********************************************************" - echo "AUTHORIZED KEYS" - echo "********************************************************" - cat /root/.ssh/authorized_keys - echo - echo "********************************************************" - fi -done -rm -f ${TMPFILE}