Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ron van der Heijden committed Aug 26, 2020
0 parents commit aeeafcb
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# OS
.DS_Store
Thumbs.db

# IDEs
.buildpath
.project
.settings/
.build/
.idea/
nbproject/
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Changelog

## 0.1.6 (2020/08/26)
* More loggin
* Improved readme

## 0.1.5 (2020/08/26)
* Updated Alpine version

## 0.1.4 (2020/08/26)
* Initial version
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM alpine:3.12.0

LABEL "name"="Hugo rsync deployment"
LABEL "maintainer"="Ron van der Heijden <[email protected]>"
LABEL "version"="0.1.6"

LABEL "com.github.actions.name"="Hugo rsync deployment"
LABEL "com.github.actions.description"="An action that generates and deploys a static website using Hugo and rsync."
LABEL "com.github.actions.icon"="upload-cloud"
LABEL "com.github.actions.color"="blue"

LABEL "repository"="https://github.com/ronvanderheijden/hugo-rsync-deployment"
LABEL "homepage"="https://ronvanderheijden.nl/"

RUN apk add --no-cache --upgrade --no-progress \
hugo \
openssh \
rsync

ADD entrypoint.sh /
RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Ron van der Heijden

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
73 changes: 73 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Hugo rsync deployment
Why would you use a CMS if you have [GitHub Actions](https://github.com/features/actions), [Hugo](https://gohugo.io) and [rsync](https://linux.die.net/man/1/rsync)?

This action checks out your repository, generates a static website using Hugo and deploys the public files using rsync.

## Requirements
Before we can deploy from github, we need to setup some things.
Assuming we want the user to be named `github` and the host `static-website.com`:

1. We need SSH access from GitHub to the webserver and the public key uploaded to `/home/github/.ssh/authorized_keys`.
1. We need a new GitHub repository with the name `static-website.com` (can be private).
1. We need to place the private key in a secret named `VPS_DEPLOY_KEY` (Repository -> Settings -> Secrets).

## Example
The fastest way to start a project, is to simply clone [the boilerplate](https://github.com/ronvanderheijden/hugo-rsync-deployment-boilerplate).

But we can also place our Hugo website in the `src/` directory and create a file in `.github/workflows/deploy.yml` with the content:
```yaml
name: 'Generate and deploy'

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
deploy-website:
runs-on: ubuntu-latest
steps:
- name: Do a git checkout including submodules
uses: actions/checkout@master
with:
submodules: true

- name: Generate and deploy website
uses: ronvanderheijden/hugo-rsync-deployment@master
env:
VPS_DEPLOY_KEY: ${{ secrets.VPS_DEPLOY_KEY }}
VPS_DEPLOY_USER: github
VPS_DEPLOY_HOST: static-website.com
VPS_DEPLOY_DEST: /var/www/static-website.com/
with:
hugo-arguments: '--minify'
rsync-arguments: '--archive --compress --xattrs --delete'
```
## Hugo
Some Hugo commands that can help:
```sh
hugo version # to compare the local version with the action
hugo server -s src # to run the website locally
hugo -s src # to generate the static website
hugo -s src --minify # to minify CSS, JS, JSON, HTML, SVG and XML resources
```

## rsync
Some tips to test rsync:
```sh
--archive, -a # archive mode (recursive, links, permissions, modification times, group, owner, special files)
--compress, -z # compress file data during the transfer
--xattrs, -X # preserve extended attributes
--delete # delete extraneous files from dest dirs
--dry-run # perform a trial run with no changes made
--exclude=PATTERN # exclude files matching PATTERN
--quiet, -q # suppress non-error messages
```

# Support
Found a bug? Got a feature request? [Create an issue](https://github.com/ronvanderheijden/hugo-rsync-deployment/issues).

# License
Hugo rsync deployment is open source and licensed under [the MIT licence](https://github.com/ronvanderheijden/hugo-rsync-deployment/blob/master/LICENSE.txt).
23 changes: 23 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# action.yml
name: 'Hugo rsync deployment'
description: 'An action that generates and deploys a static website using Hugo and rsync.'
branding:
icon: 'upload-cloud'
color: 'blue'

inputs:
hugo-arguments:
description: 'Hugo arguments'
required: false
default: '--minify'
rsync-arguments:
description: 'Rsync arguments'
required: false
default: '--archive --compress --xattrs --delete'

runs:
using: 'docker'
image: 'Dockerfile'
args:
- ${{ inputs.hugo-arguments }}
- ${{ inputs.rsync-arguments }}
27 changes: 27 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/bin/sh -l

set -euo pipefail

if [[ -z "$GITHUB_WORKSPACE" ]]; then
echo "Set the GITHUB_WORKSPACE env variable."
exit 1
fi

cd "${GITHUB_WORKSPACE}/src"

hugo version
hugo $1

mkdir "${HOME}/.ssh"
echo "${VPS_DEPLOY_KEY}" > "${HOME}/.ssh/id_rsa_deploy"
chmod 600 "${HOME}/.ssh/id_rsa_deploy"

rsync --version
sh -c "
rsync $2 \
-e 'ssh -i ${HOME}/.ssh/id_rsa_deploy -o StrictHostKeyChecking=no' \
${GITHUB_WORKSPACE}/src/public \
${VPS_DEPLOY_USER}@${VPS_DEPLOY_HOST}:${VPS_DEPLOY_DEST}
"

exit 0

0 comments on commit aeeafcb

Please sign in to comment.