mirror of
https://github.com/Burnett01/rsync-deployments.git
synced 2026-09-25 08:45:22 +08:00
Compare commits
32 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c269e19dd0 | |||
| c39ab06b30 | |||
| 9f59b515f6 | |||
| c5464e03ed | |||
| 0010c2adf6 | |||
| c6d9be15a7 | |||
| d75a44a646 | |||
| c47cfee594 | |||
| 7e62b51e32 | |||
| f8c929a1f4 | |||
| 6a989b68a1 | |||
| 6fa9b56771 | |||
| f5c5431bf6 | |||
| 20b1f5b4b8 | |||
| 1bbe8382e5 | |||
| febcb5ac34 | |||
| 682623851b | |||
| 050c29bcea | |||
| 6093fd5ca1 | |||
| 0186c3a6b2 | |||
| 2f8edbc7f1 | |||
| d573c19867 | |||
| 609b9969e2 | |||
| 1e3e469683 | |||
| 6b3db75d87 | |||
| c4c3b6821b | |||
| 2f0d5a19fa | |||
| 5536ad8c42 | |||
| e9dd3cdb51 | |||
| 72f04677de | |||
| 1eb5088cc2 | |||
| 24cfa35ecb |
+3
-23
@@ -1,27 +1,7 @@
|
|||||||
FROM ubuntu:latest
|
FROM drinternet/rsync:1.0.1
|
||||||
|
|
||||||
|
|
||||||
# Update
|
|
||||||
RUN apt-get update
|
|
||||||
|
|
||||||
|
|
||||||
# Install packages
|
|
||||||
RUN apt-get -yq install rsync openssh-client
|
|
||||||
|
|
||||||
|
|
||||||
# Label
|
|
||||||
LABEL "com.github.actions.name"="rsync deployments"
|
|
||||||
LABEL "com.github.actions.description"="For deploying code to a webserver via rsync over ssh"
|
|
||||||
LABEL "com.github.actions.icon"="truck"
|
|
||||||
LABEL "com.github.actions.color"="yellow"
|
|
||||||
|
|
||||||
LABEL "repository"="https://github.com/Burnett01/rsync-deployments"
|
|
||||||
LABEL "homepage"="https://github.com/Burnett01/rsync-deployments"
|
|
||||||
LABEL "maintainer"="Contention <hello@contention.agency> & Burnett01"
|
|
||||||
|
|
||||||
|
|
||||||
# Copy entrypoint
|
# Copy entrypoint
|
||||||
ADD entrypoint.sh /entrypoint.sh
|
COPY entrypoint.sh /entrypoint.sh
|
||||||
RUN chmod +x /entrypoint.sh
|
RUN chmod +x /entrypoint.sh
|
||||||
ENTRYPOINT ["/entrypoint.sh"]
|
|
||||||
|
|
||||||
|
ENTRYPOINT ["/entrypoint.sh"]
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2019 Contention
|
Copyright (c) 2019-2020 Contention
|
||||||
Copyright (c) 2019 Burnett01
|
Copyright (c) 2019-2020 Burnett01
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -3,27 +3,41 @@
|
|||||||
Forked from [Contention/rsync-deployments](https://github.com/Contention/rsync-deployments)
|
Forked from [Contention/rsync-deployments](https://github.com/Contention/rsync-deployments)
|
||||||
|
|
||||||
|
|
||||||
This GitHub Action deploys files in `GITHUB_WORKSPACE` to a folder on a server via rsync over ssh.
|
This GitHub Action deploys files in `GITHUB_WORKSPACE` to a remote folder via rsync over ssh.
|
||||||
|
|
||||||
Use this action in a build/test workflow which leaves deployable code in `GITHUB_WORKSPACE`.
|
Use this action in a CD workflow which leaves deployable code in `GITHUB_WORKSPACE`.
|
||||||
|
|
||||||
# Required SECRETs
|
The underlaying base-image of the docker-image is very small (Alpine (no cache)) which results in fast deployments.
|
||||||
|
|
||||||
This action needs a `DEPLOY_KEY` secret variable. This should be the private key part of a ssh key pair. The public key part should be added to the authorized_keys file on the server that receives the deployment. This should be set in the Github secrets section and then referenced as an `env` variable.
|
---
|
||||||
|
|
||||||
# ARGs
|
## Inputs
|
||||||
|
|
||||||
This action requires 4 args in the `with` block.
|
- `switches`* - The first is for any initial/required rsync flags, eg: `-avzr --delete`
|
||||||
|
|
||||||
1. `swtiches` - The first is for any initial/required rsync flags, eg: `-avzr --delete`
|
- `rsh` - Remote shell commands
|
||||||
|
|
||||||
2. `rsh` - Remote shell commands, eg for using a different SSH port: `"-p ${{ secrets.DEPLOY_PORT }}"`
|
- `path` - The source path. Defaults to GITHUB_WORKSPACE
|
||||||
|
|
||||||
3. `path` - The source path, if none; use `""`
|
- `remote_path`* - The deployment target path
|
||||||
|
|
||||||
4. `upload_path` - The deployment target, and should be in the format: `[USER]@[HOST]:[PATH]`
|
- `remote_host`* - The remote host
|
||||||
|
|
||||||
# Example usage
|
- `remote_port` - The remote port. Defaults to 22
|
||||||
|
|
||||||
|
- `remote_user`* - The remote user
|
||||||
|
|
||||||
|
- `remote_key`* - The remote ssh key
|
||||||
|
|
||||||
|
``* = Required``
|
||||||
|
|
||||||
|
## Required secret
|
||||||
|
|
||||||
|
This action needs a `DEPLOY_KEY` secret variable. This should be the private key part of a ssh key pair. The public key part should be added to the authorized_keys file on the server that receives the deployment. This should be set in the Github secrets section and then referenced as the `remote_key` input.
|
||||||
|
|
||||||
|
## Example usage
|
||||||
|
|
||||||
|
Simple:
|
||||||
|
|
||||||
```
|
```
|
||||||
name: DEPLOY
|
name: DEPLOY
|
||||||
@@ -38,20 +52,103 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v1
|
- uses: actions/checkout@v1
|
||||||
- name: rsync deployments
|
- name: rsync deployments
|
||||||
uses: burnett01/rsync-deployments@1.0
|
uses: burnett01/rsync-deployments@4.0
|
||||||
with:
|
with:
|
||||||
switches: -avzr --delete --exclude="" --include=""
|
switches: -avzr --delete
|
||||||
rsh: "-p ${{ secrets.DEPLOY_PORT }}"
|
|
||||||
path: src/
|
path: src/
|
||||||
upload_path: user@example.com:/var/www/html/
|
remote_path: /var/www/html/
|
||||||
|
remote_host: example.com
|
||||||
env:
|
remote_user: debian
|
||||||
DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }}
|
remote_key: ${{ secrets.DEPLOY_KEY }}
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## Disclaimer
|
Advanced:
|
||||||
|
|
||||||
If you're using GitHub Actions, you probably already know that it's still in limited public beta, and GitHub advise against using Actions in production.
|
```
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
- name: rsync deployments
|
||||||
|
uses: burnett01/rsync-deployments@4.0
|
||||||
|
with:
|
||||||
|
switches: -avzr --delete --exclude="" --include="" --filter=""
|
||||||
|
path: src/
|
||||||
|
remote_path: /var/www/html/
|
||||||
|
remote_host: example.com
|
||||||
|
remote_port: 5555
|
||||||
|
remote_user: debian
|
||||||
|
remote_key: ${{ secrets.DEPLOY_KEY }}
|
||||||
|
```
|
||||||
|
|
||||||
So, check your keys. Check your deployment paths. And use at your own risk.
|
For better security, I suggest you create additional secrets for remote_host, remote_port and remote_user inputs.
|
||||||
|
|
||||||
|
```
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
- name: rsync deployments
|
||||||
|
uses: burnett01/rsync-deployments@4.0
|
||||||
|
with:
|
||||||
|
switches: -avzr --delete
|
||||||
|
path: src/
|
||||||
|
remote_path: /var/www/html/
|
||||||
|
remote_host: ${{ secrets.DEPLOY_HOST }}
|
||||||
|
remote_port: ${{ secrets.DEPLOY_PORT }}
|
||||||
|
remote_user: ${{ secrets.DEPLOY_USER }}
|
||||||
|
remote_key: ${{ secrets.DEPLOY_KEY }}
|
||||||
|
```
|
||||||
|
|
||||||
|
For maximum speed limit the checkout action (``actions/checkout@v1``) to a depth of 2:
|
||||||
|
|
||||||
|
```
|
||||||
|
jobs:
|
||||||
|
deploy:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v1
|
||||||
|
with:
|
||||||
|
fetch-depth: 2
|
||||||
|
- name: rsync deployments
|
||||||
|
uses: burnett01/rsync-deployments@4.0
|
||||||
|
with:
|
||||||
|
switches: -avzr --delete
|
||||||
|
path: src/
|
||||||
|
remote_path: /var/www/html/
|
||||||
|
remote_host: ${{ secrets.DEPLOY_HOST }}
|
||||||
|
remote_port: ${{ secrets.DEPLOY_PORT }}
|
||||||
|
remote_user: ${{ secrets.DEPLOY_USER }}
|
||||||
|
remote_key: ${{ secrets.DEPLOY_KEY }}
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Version 3.0
|
||||||
|
|
||||||
|
Looking for version 3.0?
|
||||||
|
|
||||||
|
Check here: https://github.com/Burnett01/rsync-deployments/tree/3.0
|
||||||
|
|
||||||
|
Version 3.0 uses the ``alpine:latest`` base-image directly.<br>
|
||||||
|
Consider upgrading to 4.0 that uses a docker-image ``drinternet/rsync:1.0.1`` that is<br>
|
||||||
|
based on ``alpine:latest``and heavily optimized for rsync.
|
||||||
|
|
||||||
|
## Version 2.0
|
||||||
|
|
||||||
|
Looking for version 2.0?
|
||||||
|
|
||||||
|
Check here: https://github.com/Burnett01/rsync-deployments/tree/2.0
|
||||||
|
|
||||||
|
Version 2.0 uses a larger base-image (``ubuntu:latest``).<br>
|
||||||
|
Consider upgrading to 3.0 for even faster deployments.
|
||||||
|
|
||||||
|
## Version 1.0 (EOL)
|
||||||
|
|
||||||
|
Looking for version 1.0?
|
||||||
|
|
||||||
|
Check here: https://github.com/Burnett01/rsync-deployments/tree/1.0
|
||||||
|
|
||||||
|
Please note that version 1.0 has reached end of life state.
|
||||||
|
|||||||
+14
-1
@@ -13,9 +13,22 @@ inputs:
|
|||||||
description: 'The local path'
|
description: 'The local path'
|
||||||
required: false
|
required: false
|
||||||
default: ''
|
default: ''
|
||||||
upload_path:
|
remote_path:
|
||||||
description: 'The remote path'
|
description: 'The remote path'
|
||||||
required: true
|
required: true
|
||||||
|
remote_host:
|
||||||
|
description: 'The remote host'
|
||||||
|
required: true
|
||||||
|
remote_port:
|
||||||
|
description: 'The remote port'
|
||||||
|
required: false
|
||||||
|
default: 22
|
||||||
|
remote_user:
|
||||||
|
description: 'The remote user'
|
||||||
|
required: true
|
||||||
|
remote_key:
|
||||||
|
description: 'The remote key'
|
||||||
|
required: true
|
||||||
runs:
|
runs:
|
||||||
using: 'docker'
|
using: 'docker'
|
||||||
image: 'Dockerfile'
|
image: 'Dockerfile'
|
||||||
|
|||||||
+6
-14
@@ -1,17 +1,9 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
|
# Start the SSH agent and load key.
|
||||||
|
source agent-start "$GITHUB_ACTION"
|
||||||
|
echo "$INPUT_REMOTE_KEY" | agent-add
|
||||||
|
|
||||||
|
# Add strict errors and deploy.
|
||||||
set -eu
|
set -eu
|
||||||
|
sh -c "rsync $INPUT_SWITCHES -e 'ssh -o StrictHostKeyChecking=no -p $INPUT_REMOTE_PORT $INPUT_RSH' $GITHUB_WORKSPACE/$INPUT_PATH $INPUT_REMOTE_USER@$INPUT_REMOTE_HOST:$INPUT_REMOTE_PATH"
|
||||||
# Set deploy key
|
|
||||||
SSH_PATH="$HOME/.ssh"
|
|
||||||
# Create .ssh dir if it doesn't exist
|
|
||||||
if [ ! -d "$SSH_PATH" ]; then
|
|
||||||
mkdir "$SSH_PATH"
|
|
||||||
fi
|
|
||||||
# Place deploy_key into .ssh dir
|
|
||||||
echo "$DEPLOY_KEY" > "$SSH_PATH/deploy_key"
|
|
||||||
# Set r+w to user only
|
|
||||||
chmod 600 "$SSH_PATH/deploy_key"
|
|
||||||
|
|
||||||
# Do deployment
|
|
||||||
sh -c "rsync $INPUT_SWITCHES -e 'ssh -i $SSH_PATH/deploy_key -o StrictHostKeyChecking=no $INPUT_RSH' $GITHUB_WORKSPACE/$INPUT_PATH $INPUT_UPLOAD_PATH"
|
|
||||||
|
|||||||
Reference in New Issue
Block a user