From 5d66058f138ccb22398803e861f00426cc0f9b8e Mon Sep 17 00:00:00 2001 From: annika Date: Mon, 4 Jun 2018 00:44:18 +0000 Subject: [PATCH] Initial commit --- Dockerfile | 5 +++++ Makefile | 9 +++++++++ README.md | 25 +++++++++++++++++++++++++ drone-ssh-keys.sh | 18 ++++++++++++++++++ 4 files changed, 57 insertions(+) create mode 100644 Dockerfile create mode 100644 Makefile create mode 100644 README.md create mode 100755 drone-ssh-keys.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..60cff4d --- /dev/null +++ b/Dockerfile @@ -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 diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..dc552d6 --- /dev/null +++ b/Makefile @@ -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 diff --git a/README.md b/README.md new file mode 100644 index 0000000..e859b11 --- /dev/null +++ b/README.md @@ -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 + diff --git a/drone-ssh-keys.sh b/drone-ssh-keys.sh new file mode 100755 index 0000000..5efae08 --- /dev/null +++ b/drone-ssh-keys.sh @@ -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"