Browse Source

Initial commit

master
4 changed files with 57 additions and 0 deletions
  1. +5
    -0
      Dockerfile
  2. +9
    -0
      Makefile
  3. +25
    -0
      README.md
  4. +18
    -0
      drone-ssh-keys.sh

+ 5
- 0
Dockerfile View File

@@ -0,0 +1,5 @@
FROM alpine:3.7

COPY drone-ssh-keys.sh /usr/bin/drone-ssh-keys

RUN apk add --no-cache openssh-client rsync

+ 9
- 0
Makefile View File

@@ -0,0 +1,9 @@
IMAGE_NAME := images.abackstrom.com/rsync-ssh

image:
docker build -t $(IMAGE_NAME) .

push:
docker push $(IMAGE_NAME)

.PHONY: image push

+ 25
- 0
README.md View File

@@ -0,0 +1,25 @@
# drone-rsync-ssh

A Dockerfile for rsync+ssh deploys using [Drone](https://drone.io/).

* In Drone, add repository secrets for `ssh_private_key` and `ssh_host_key`
* In your `.drone.yml`, run `drone-ssh-keys` to inject SSH secrets into `~/.ssh`

## Sample .drone.yml

Here's a sample `.drone.yml` that injects the SSH keys, rsyncs files to a host,
then triggers a command on the host.

pipeline:
deploy:
image: images.abackstrom.com/rsync-ssh
secrets: [ ssh_private_key, ssh_host_key ]
commands:
- drone-ssh-keys
- rsync -Chrz -e ssh ./public user@host:/var/www/html
- ssh user@host 'sudo systemctl reload nginx'

## Building the image

make image IMAGE_NAME=your_name_here


+ 18
- 0
drone-ssh-keys.sh View File

@@ -0,0 +1,18 @@
#!/bin/sh

if [ -z "$SSH_PRIVATE_KEY" ] ; then
echo "\$SSH_PRIVATE_KEY is not set!" >/dev/stderr
exit 1
fi

if [ -z "$SSH_HOST_KEY" ] ; then
echo "\$SSH_HOST_KEY is not set!" >/dev/stderr
exit 1
fi

mkdir "${HOME}/.ssh"
echo -n "${SSH_PRIVATE_KEY}" > "${HOME}/.ssh/id_rsa"
chmod 700 "${HOME}/.ssh/id_rsa"
echo "${SSH_HOST_KEY}" >> "${HOME}/.ssh/known_hosts"

echo "Created $HOME/.ssh/id_rsa and $HOME/.ssh/known_hosts"

Loading…
Cancel
Save