Use tools/docker-ssh in make ssh and in test/runner.sh to connect to container via SSH, fix SSH connection by IP issue on Mac-OS

This commit is contained in:
Matyas Markovics
2019-04-08 09:49:13 +02:00
parent 36bd41108f
commit 89597c5bc5
3 changed files with 10 additions and 8 deletions

View File

@@ -28,14 +28,10 @@ release: test tag_latest
@echo "*** Don't forget to create a tag by creating an official GitHub release."
ssh: SSH_COMMAND?=
ssh: SSH_IDENTITY_FILE?=image/services/sshd/keys/insecure_key
ssh:
chmod 600 ${SSH_IDENTITY_FILE}
ID=$$(docker ps | grep -F "$(NAME):$(VERSION)" | awk '{ print $$1 }') && \
if test "$$ID" = ""; then echo "Container is not running."; exit 1; fi && \
IP=$$(docker inspect --format '{{ .NetworkSettings.IPAddress }}' $$ID) && \
echo "SSHing into $$IP" && \
ssh -v -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ${SSH_IDENTITY_FILE} root@$$IP ${SSH_COMMAND}
tools/docker-ssh $$ID ${SSH_COMMAND}
test_release:
echo test_release

View File

@@ -33,8 +33,6 @@ docker exec $ID sv start /etc/service/sshd
sleep 1
echo " --> Logging into container and running tests"
cp image/services/sshd/keys/insecure_key /tmp/insecure_key
sleep 1 # Give container some more time to start up.
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
NAME=$NAME VERSION=$VERSION SSH_IDENTITY_FILE=/tmp/insecure_key \
SSH_COMMAND="'/bin/bash -s' < $DIR/test.sh" make ssh
tools/docker-ssh $ID < test/test.sh

View File

@@ -58,6 +58,13 @@ fi
KNOWN_HOSTS_FILE=`mktemp /tmp/docker-ssh.XXXXXXXXX`
IP=`docker inspect -f "{{ .NetworkSettings.IPAddress }}" "$CONTAINER_ID"`
PORT=`docker inspect -f '{{(index (index .NetworkSettings.Ports "22/tcp") 0).HostPort}}' "$CONTAINER_ID"`
if test "`uname`" = "Darwin"; then
IP="127.0.0.1"
else
PORT=22
fi
echo "SSHing into $IP:$PORT"
# Prevent SSH from warning about adding a host to the known_hosts file.
ssh-keyscan "$IP" >"$KNOWN_HOSTS_FILE" 2>&1
@@ -68,6 +75,7 @@ if ! ssh -i ~/.baseimage_docker_insecure_key \
-o PasswordAuthentication=no \
-o KbdInteractiveAuthentication=no \
-o ChallengeResponseAuthentication=no \
-p $PORT \
"root@$IP" "$@"
then
STATUS=$?