├── Dockerfile ├── LICENSE ├── README.md ├── action.yml └── entrypoint.sh /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM drinternet/rsync:v1.4.3 2 | 3 | 4 | # Label 5 | LABEL "com.github.actions.name"="rsync deployments" 6 | LABEL "com.github.actions.description"="Quick and simple method of deploying code to a webserver via rsync over ssh" 7 | LABEL "com.github.actions.icon"="truck" 8 | LABEL "com.github.actions.color"="yellow" 9 | 10 | LABEL "repository"="http://github.com/contention/rsync-deployments" 11 | LABEL "homepage"="https://github.com/contention/rsync-deployments" 12 | LABEL "maintainer"="Contention " 13 | 14 | 15 | # Copy entrypoint 16 | ADD entrypoint.sh /entrypoint.sh 17 | RUN chmod +x /entrypoint.sh 18 | ENTRYPOINT ["/entrypoint.sh"] 19 | 20 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Contention 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rsync deployments 2 | 3 | This GitHub Action deploys files in `GITHUB_WORKSPACE` to a folder on a server via rsync over ssh. 4 | 5 | This action would usually follow a build/test action which leaves deployable code in `GITHUB_WORKSPACE`. 6 | 7 | # Required secrets 8 | 9 | This action needs a `DEPLOY_KEY` secret variable. This should be the private key part of an ssh key pair. The public key part should be added to the authorized_keys file on the server that receives the deployment. 10 | 11 | # Required inputs 12 | 13 | This action requires six inputs: 14 | 15 | 1. `FLAGS` for any initial/required rsync flags, eg: `-avzr --delete` 16 | 17 | 2. `EXCLUDES` for any `--exclude` flags and directory pairs, eg: `--exclude .htaccess --exclude /uploads/`. Use `""` if none required. 18 | 19 | 3. `USER` for the server user, eg: `deploybot` 20 | 21 | 4. `HOST` for the deployment target, eg: `myserver.com` 22 | 23 | 5. `LOCALPATH` for the local path to sync, eg: `/dist/` 24 | 25 | 5. `REMOTEPATH` for the remote path to sync, eg: `/srv/myapp/public/htdocs/` 26 | 27 | # Example usage 28 | 29 | ``` 30 | name: Deploy to production 31 | 32 | on: 33 | push: 34 | branches: 35 | - master 36 | 37 | jobs: 38 | deploy: 39 | runs-on: ubuntu-latest 40 | steps: 41 | - uses: actions/checkout@v2 42 | - uses: contention/rsync-deployments@v2.0.0 43 | with: 44 | FLAGS: -avzr --delete 45 | EXCLUDES: --exclude .htaccess --exclude /uploads/ 46 | USER deploybot 47 | HOST: myserver.com 48 | LOCALPATH: /dist/ 49 | REMOTEPATH: /srv/myapp/public/htdocs/ 50 | DEPLOY_KEY: ${{ secrets.DEPLOY_KEY }} 51 | 52 | ``` 53 | 54 | ## REMINDER! 55 | 56 | Check your keys. Check your deployment paths. Check your flags. And use at your own risk. 57 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'rsync deployments' 2 | description: 'Quick and simple method of deploying code to a webserver via rsync over ssh' 3 | author: 'Contention' 4 | inputs: 5 | flags: 6 | description: 'Initial/required rsync flags' 7 | required: true 8 | excludes: 9 | description: 'Exclude flags and directory pairs' 10 | required: true 11 | user: 12 | description: 'The server user' 13 | required: true 14 | host: 15 | description: 'The deployment target' 16 | required: true 17 | localpath: 18 | description: 'The local path to sync' 19 | required: true 20 | remotepath: 21 | description: 'The remote path to sync' 22 | required: true 23 | deploy_key: 24 | description: 'The private key' 25 | required: true 26 | runs: 27 | using: 'docker' 28 | image: 'Dockerfile' 29 | branding: 30 | icon: 'truck' 31 | color: 'yellow' 32 | -------------------------------------------------------------------------------- /entrypoint.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | set -eu 4 | 5 | # Set deploy key 6 | SSH_PATH="$HOME/.ssh" 7 | mkdir "$SSH_PATH" 8 | echo "$INPUT_DEPLOY_KEY" > "$SSH_PATH/deploy_key" 9 | chmod 600 "$SSH_PATH/deploy_key" 10 | 11 | 12 | # Do deployment 13 | sh -c "rsync $INPUT_FLAGS -e 'ssh -i $SSH_PATH/deploy_key -o StrictHostKeyChecking=no' $INPUT_EXCLUDES $GITHUB_WORKSPACE/$INPUT_LOCALPATH $INPUT_USER@$INPUT_HOST:$INPUT_REMOTEPATH" 14 | --------------------------------------------------------------------------------