forked from sirthias/scala-ssh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests being run against dockerized sshd
That enables running SshClientSpec on CI and also make it easier to run this test locally as it does not require any local setup any more. Solves sirthias#42, at least on code side, @sirthias would need to enable travis on project settings to make it effective Related to sirthias#38 - while this PR does not fix exactly this issue it may enable what was the motivation behind sirthias#38
- Loading branch information
Showing
8 changed files
with
132 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
#!/bin/bash | ||
|
||
source scripts/common/common.sh | ||
|
||
# Check is source worked | ||
echo "Common definitions loaded: $PUBLIC_KEY_FILENAME" | ||
|
||
ssh-keygen -t ed25519 -f "$PRIVATE_KEY_FILENAME" -N "" -q | ||
|
||
docker pull "$DOCKER_IMAGE_NAME" | ||
docker run -d -P --name test_sshd "$DOCKER_IMAGE_NAME" | ||
|
||
# Ensure that sshd started | ||
RETRIES_LEFT=15 | ||
COMMAND_STATUS=1 | ||
until { [ $COMMAND_STATUS -eq 0 ] || [ $RETRIES_LEFT -eq 0 ]; }; do | ||
echo "checking if sshd is up: $RETRIES_LEFT" | ||
docker ps -a | grep test_sshd | ||
COMMAND_STATUS=$? | ||
sleep 2 | ||
let RETRIES_LEFT=RETRIES_LEFT-1 | ||
done | ||
|
||
docker cp "$PUBLIC_KEY_FILENAME" test_sshd:/root/.ssh/authorized_keys | ||
docker exec test_sshd chown root:root /root/.ssh/authorized_keys | ||
|
||
# returns e.g. 0.0.0.0:32875 | ||
SSHD_HOST_PORT=`docker port test_sshd 22` | ||
|
||
# returns e.g. 32875, uses https://stackoverflow.com/a/3162500/429311 | ||
SSHD_PORT=${SSHD_HOST_PORT##*:} | ||
echo "sshd ephemeral port detected: $SSHD_PORT" | ||
write_scala_ssh_config "localhost" "$SSHD_PORT" | ||
|
||
ssh-keyscan -t ed25519 -p "$SSHD_PORT" localhost >>~/.ssh/known_hosts | ||
|
||
sbt test |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#!/bin/bash | ||
|
||
# enable job control | ||
set -m | ||
|
||
PRIVATE_KEY_FILENAME="id_ed25519" | ||
PUBLIC_KEY_FILENAME="id_ed25519.pub" | ||
DOCKER_IMAGE_NAME="rastasheep/ubuntu-sshd:16.04" | ||
|
||
function write_scala_ssh_config() { | ||
local SSHD_HOST="$1" | ||
local SSHD_PORT="$2" | ||
|
||
mkdir -p ~/.scala-ssh | ||
echo $SSHD_HOST > ~/.scala-ssh/.testhost | ||
FULLPATH=`realpath $PRIVATE_KEY_FILENAME` | ||
|
||
cat <<EOF > ~/.scala-ssh/$SSHD_HOST | ||
login-type = keyfile | ||
username = root | ||
keyfile = $FULLPATH | ||
port = $SSHD_PORT | ||
EOF | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
version: '2.4' | ||
|
||
services: | ||
sbt: | ||
image: hseeberger/scala-sbt:8u222_1.3.3_2.12.10 | ||
command: bash -c "/root/workdir/scripts/local/sbt-shell.sh" | ||
ports: | ||
- "5005:5005" | ||
volumes: | ||
- $HOME/.ivy2:/root/.ivy2:cached | ||
- $HOME/.sbt:/root/.sbt:cached | ||
- $HOME/.coursier:/root/.coursier:cached | ||
- ../..:/root/workdir | ||
working_dir: /root/workdir | ||
links: | ||
- sshd | ||
|
||
sshd: | ||
container_name: test_sshd | ||
image: rastasheep/ubuntu-sshd:16.04 | ||
ports: | ||
- 22 |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/bin/bash | ||
|
||
source scripts/common/common.sh | ||
|
||
# Check is source worked | ||
echo "Common definitions loaded: $PUBLIC_KEY_FILENAME" | ||
|
||
# there may exist files from previous run - remove them | ||
rm -f id_ed25519 id_ed25519.pub | ||
|
||
ssh-keygen -t ed25519 -f "$PRIVATE_KEY_FILENAME" -N "" -q | ||
# docker-compose -f scripts/local/docker-compose.yml pull --include-deps sbt | ||
docker-compose -f scripts/local/docker-compose.yml up -d sshd | ||
|
||
docker cp "$PUBLIC_KEY_FILENAME" test_sshd:/root/.ssh/authorized_keys | ||
docker exec test_sshd chown root:root /root/.ssh/authorized_keys | ||
|
||
docker-compose -f scripts/local/docker-compose.yml run --service-ports sbt |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash | ||
|
||
source scripts/common/common.sh | ||
|
||
# Check is source worked | ||
echo "Common definitions loaded: $PUBLIC_KEY_FILENAME" | ||
|
||
# hostname "sshd" as in docker-compose | ||
write_scala_ssh_config sshd 22 | ||
|
||
mkdir ~/.ssh | ||
ssh-keyscan -t ed25519 -p 22 sshd >>~/.ssh/known_hosts | ||
|
||
sbt shell |