Skip to content

Commit

Permalink
Merge pull request #11 from r3cha/add-ssh-port
Browse files Browse the repository at this point in the history
Ability to specify ssh port
  • Loading branch information
wshihadeh authored Nov 2, 2020
2 parents e02ba2e + c9eb5a2 commit e11d221
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ Arguments to pass to the deployment command either `docker` or `docker-compose

Specify Remote Docker host. The input value must be in the follwing format (user@host)

### `remote_docker_port`

Specify Remote Docker ssh port if its not 22 default ie (2222)

### `ssh_public_key`

Remote Docker SSH public key.
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ inputs:
remote_docker_host:
description: Remote Docker host ie (user@host)
required: true
remote_docker_port:
description: Remote Docker ssh port ie (22)
required: false
default: '22'
ssh_public_key:
description: Remote Docker SSH public key
required: true
Expand Down
10 changes: 8 additions & 2 deletions docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ execute_ssh(){
echo "Execute Over SSH: $@"
ssh -q -t -i "$HOME/.ssh/id_rsa" \
-o UserKnownHostsFile=/dev/null \
-p $INPUT_REMOTE_DOCKER_PORT \
-o StrictHostKeyChecking=no "$INPUT_REMOTE_DOCKER_HOST" "$@"
}

if [ -z "$INPUT_REMOTE_DOCKER_PORT" ]; then
INPUT_REMOTE_DOCKER_PORT=22
fi

if [ -z "$INPUT_REMOTE_DOCKER_HOST" ]; then
echo "Input remote_docker_host is required!"
exit 1
Expand Down Expand Up @@ -49,7 +54,7 @@ DEPLOYMENT_COMMAND_OPTIONS=""
if [ "$INPUT_COPY_STACK_FILE" == "true" ]; then
STACK_FILE="$INPUT_DEPLOY_PATH/$STACK_FILE"
else
DEPLOYMENT_COMMAND_OPTIONS=" --log-level debug --host ssh://$INPUT_REMOTE_DOCKER_HOST"
DEPLOYMENT_COMMAND_OPTIONS=" --log-level debug --host ssh://$INPUT_REMOTE_DOCKER_HOST:$INPUT_REMOTE_DOCKER_PORT"
fi

case $INPUT_DEPLOYMENT_MODE in
Expand Down Expand Up @@ -79,7 +84,7 @@ echo "Add known hosts"
printf '%s %s\n' "$SSH_HOST" "$INPUT_SSH_PUBLIC_KEY" > /etc/ssh/ssh_known_hosts

if ! [ -z "$INPUT_DOCKER_PRUNE" ] && [ $INPUT_DOCKER_PRUNE = 'true' ] ; then
yes | docker --log-level debug --host "ssh://$INPUT_REMOTE_DOCKER_HOST" system prune -a 2>&1
yes | docker --log-level debug --host "ssh://$INPUT_REMOTE_DOCKER_HOST:$INPUT_REMOTE_DOCKER_PORT" system prune -a 2>&1
fi

if ! [ -z "$INPUT_COPY_STACK_FILE" ] && [ $INPUT_COPY_STACK_FILE = 'true' ] ; then
Expand All @@ -89,6 +94,7 @@ if ! [ -z "$INPUT_COPY_STACK_FILE" ] && [ $INPUT_COPY_STACK_FILE = 'true' ] ; th
scp -i "$HOME/.ssh/id_rsa" \
-o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=no \
-P $INPUT_REMOTE_DOCKER_PORT \
$INPUT_STACK_FILE_NAME "$INPUT_REMOTE_DOCKER_HOST:$INPUT_DEPLOY_PATH/stacks/$FILE_NAME"

execute_ssh "ln -nfs $INPUT_DEPLOY_PATH/stacks/$FILE_NAME $INPUT_DEPLOY_PATH/$INPUT_STACK_FILE_NAME"
Expand Down

0 comments on commit e11d221

Please sign in to comment.