]> git.apps.os.sepia.ceph.com Git - teuthology.git/commitdiff
docker-compose: Optionally use an existing SSH key
authorZack Cerza <zack@redhat.com>
Thu, 24 Mar 2022 23:10:33 +0000 (17:10 -0600)
committerZack Cerza <zack@redhat.com>
Mon, 28 Mar 2022 21:31:40 +0000 (15:31 -0600)
This will only work with "real" testnodes; with containerized testnodes
there's no reason not to use a generated key.

Signed-off-by: Zack Cerza <zack@redhat.com>
docs/docker-compose/Dockerfile
docs/docker-compose/docker-compose.yml
docs/docker-compose/start.sh
docs/docker-compose/teuthology.sh

index b4f1494b6bcd16b5f700f7a89f8a2370045c5768..5b46ea239a74432724d82e02cf03bc2d31077b37 100644 (file)
@@ -1,9 +1,10 @@
 FROM ubuntu:latest
+ARG SSH_PRIVKEY_FILE=id_ed25519
 ENV DEBIAN_FRONTEND=noninteractive
 RUN \
     mkdir $HOME/.ssh && \
-    touch $HOME/.ssh/id_ed25519 && \
-    chmod 600 $HOME/.ssh/id_ed25519 && \
+    touch $HOME/.ssh/${SSH_PRIVKEY_FILE} && \
+    chmod 600 $HOME/.ssh/${SSH_PRIVKEY_FILE} && \
     echo "StrictHostKeyChecking=no" > $HOME/.ssh/config && \
     echo "UserKnownHostsFile=/dev/null" >> $HOME/.ssh/config
 RUN apt-get update && \
index 70866ecd1b302b3db25d113b3171eeffdae27b65..df8477ac02417e4f85e45a548f87eee50bb36d70 100644 (file)
@@ -59,7 +59,10 @@ services:
         ports:
             - "11300:11300"
   teuthology:
-    build: ./teuthology
+    build:
+      context: ./teuthology
+      args:
+        SSH_PRIVKEY_FILE: $SSH_PRIVKEY_FILE
     depends_on:
         paddles:
             condition: service_healthy
@@ -68,6 +71,7 @@ services:
         - beanstalk
     environment:
       SSH_PRIVKEY:
+      SSH_PRIVKEY_FILE:
       MACHINE_TYPE:
       TESTNODES:
   testnode:
index 22784dd147df3cd5641c1fd0d8fabbf7b77604a9..f1cba1142f97ff1c30fc466e4231a2779a28b120 100755 (executable)
@@ -15,11 +15,17 @@ cp custom_conf.yaml teuthology/
 
 
 
-# Generate an SSH keypair to use
-SSH_PRIVKEY_PATH=$(mktemp -u /tmp/teuthology-ssh-key-XXXXXX)
-ssh-keygen -t ed25519 -N '' -f $SSH_PRIVKEY_PATH
-export SSH_PRIVKEY=$(cat $SSH_PRIVKEY_PATH)
-export SSH_PUBKEY=$(cat $SSH_PRIVKEY_PATH.pub)
+# Generate an SSH keypair to use if necessary
+if [ -z "$SSH_PRIVKEY_PATH" ]; then
+    SSH_PRIVKEY_PATH=$(mktemp -u /tmp/teuthology-ssh-key-XXXXXX)
+    ssh-keygen -t ed25519 -N '' -f $SSH_PRIVKEY_PATH
+    export SSH_PRIVKEY=$(cat $SSH_PRIVKEY_PATH)
+    export SSH_PUBKEY=$(cat $SSH_PRIVKEY_PATH.pub)
+    export SSH_PRIVKEY_FILE=id_ed25519
+else
+    export SSH_PRIVKEY=$(cat $SSH_PRIVKEY_PATH)
+    export SSH_PRIVKEY_FILE=$(basename $SSH_PRIVKEY_PATH | cut -d. -f1)
+fi
 
 trap "docker-compose down" SIGINT
 docker-compose up \
index ff2250ac06c549e8b81ed48a65f45a35964d57df..7fdfd221f47094f7cf2800996de939f46fc1bc1c 100755 (executable)
@@ -1,7 +1,8 @@
 #!/usr/bin/bash
-set -e
 # We don't want -x yet, in case the private key is sensitive
-echo "$SSH_PRIVKEY" > $HOME/.ssh/id_ed25519
+if [ -n "$SSH_PRIVKEY_FILE" ]; then
+    echo "$SSH_PRIVKEY" > $HOME/.ssh/$SSH_PRIVKEY_FILE
+fi
 source /teuthology/virtualenv/bin/activate
 set -x
 if [ -n "$TESTNODES" ]; then