Initial commit

This commit is contained in:
Annika Backstrom 2018-06-04 00:44:18 +00:00 committed by Annika Backstrom
commit 5d66058f13
4 changed files with 57 additions and 0 deletions

5
Dockerfile Normal file
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
Makefile Normal file
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
README.md Normal file
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
drone-ssh-keys.sh Executable file
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"