Skip to content

Commit

Permalink
add ssh command
Browse files Browse the repository at this point in the history
  • Loading branch information
maddox committed Oct 22, 2018
1 parent e7388ed commit 0935a53
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 0 deletions.
24 changes: 24 additions & 0 deletions ssh/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
FROM debian:stable-slim

LABEL "maintainer"="maddox <[email protected]>"
LABEL "repository"="https://github.com/maddox/actions"
LABEL "version"="1.0.0"

LABEL "com.github.actions.name"="SSH"
LABEL "com.github.actions.description"="Run command via SSH"
LABEL "com.github.actions.icon"="server"
LABEL "com.github.actions.color"="orange"

RUN apt-get update && apt-get install -y \
openssh-client \
rm -rf /var/lib/apt/lists/*

RUN mkdir /github/home/.ssh
RUN chmod 700 /github/home/.ssh
RUN touch /github/home/.ssh/known_hosts
RUN chmod 600 /github/home/.ssh/known_hosts

ADD entrypoint.sh /entrypoint.sh


ENTRYPOINT ["/entrypoint.sh"]
21 changes: 21 additions & 0 deletions ssh/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2018 GitHub, Inc. and contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
44 changes: 44 additions & 0 deletions ssh/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# SSH for GitHub Actions

Run a thing on your server.

This action will run the provided argument as a command on your $HOST via SSH.

## Usage

To use the action simply add the following lines to your `.github/main.workflow`

```
action "Run command" {
uses = "maddox/actions/ssh@master"
args = "/opt/deploy/run"
secrets = [
"PRIVATE_KEY",
"PUBLIC_KEY",
"HOST",
"USER"
]
}
```

### Required Arguments

The argument you will use is the command that will be ran on your sever via SSH.

#### Examples

* ```args = "/opt/deploy/run"```
* ```args = "touch ~/.reload"```

### Required Secrets

You'll need to provide some secrets to use the action.

* **PRIVATE_KEY**: Your SSH private key.
* **PUBLIC_KEY**: Your SSH public key.
* **HOST**: The host the action will SSH to to run the command. ie, `your.site.com`.
* **USER**: The user the SSH command will auth as with the public key.

## License

The Dockerfile and associated scripts and documentation in this project are released under the [MIT License](LICENSE).
17 changes: 17 additions & 0 deletions ssh/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/sh

set -e

SSH_PATH="/github/home/.ssh"

echo "$PRIVATE_KEY" > "$SSH_PATH/deploy_key"
echo "$PUBLIC_KEY" > "$SSH_PATH/deploy_key.pub"

chmod 600 "$SSH_PATH/*"

eval $(ssh-agent)
ssh-add "$SSH_PATH/deploy_key"

ssh-keyscan -t rsa $HOST >> "$SSH_PATH/known_hosts"

ssh -A -tt $USER@$HOST "$*"

0 comments on commit 0935a53

Please sign in to comment.