Skip to content

Instantly share code, notes, and snippets.

@mattsandersuk
Last active May 16, 2023 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattsandersuk/9df2cc87ee47f9600f77b6717b618870 to your computer and use it in GitHub Desktop.
Save mattsandersuk/9df2cc87ee47f9600f77b6717b618870 to your computer and use it in GitHub Desktop.
Super Simple, Customisable Deployment Script
DEST='host:path'
COMPILE_COMMAND='yarn production'
deploy.sh
deploy.log
.deployignore
.gitkeep
.gitignore
.git
src
mix-manifest.json
package-lock.json
package.json
deploy.sh
webpack.mix.js
yarn.lock
node_modules
vendor
.DS_Store
#!/bin/bash
# -c
COMPILE=false
# -t
TRANSFER='--dry-run'
# -d
DELETE=''
while getopts 'ctd' FLAG; do
case "${FLAG}" in
c) COMPILE="true" ;;
t) TRANSFER="" ;;
d) DELETE="--delete";;
esac
done
# load config
. $PWD/.deployconfig
# should we COMPILE?
if [ $COMPILE = true ]; then
$COMPILE_COMMAND
fi
# sync it
rsync -av $TRANSFER --exclude-from '.deployignore' ./ $DEST --log-file='deploy.log' $DELETE --no-perms --checksum --prune-empty-dirs | sed '/\/$/d'

Super Simple Deployment Tool

This tool uses rsync to transfer your files to a remote location.

Setup

Create local versions of the following files:

  • deploy.sh
  • .deployignore
  • .deployconfig

e.g.

curl https://gist.githubusercontent.com/mattsandersuk/9df2cc87ee47f9600f77b6717b618870/raw/1afa5d8c4abe48b23ad1d2eb1160b1e05ea0e863/.deployconfig > .deployconfig && curl https://gist.githubusercontent.com/mattsandersuk/9df2cc87ee47f9600f77b6717b618870/raw/1afa5d8c4abe48b23ad1d2eb1160b1e05ea0e863/.deployignore > .deployignore && curl https://gist.githubusercontent.com/mattsandersuk/9df2cc87ee47f9600f77b6717b618870/raw/1afa5d8c4abe48b23ad1d2eb1160b1e05ea0e863/deploy.sh > deploy.sh

Update the config variables inside .deployconfig.

Add any additional files to the .deployignore list that you don't want to transfer.

Run chmod 755 deploy.sh to allow the script to be executable.

Running

  • ./deploy.sh - to perform a dry-run and check what files will be copied
  • ./deploy.sh -t - to transfer the files
  • ./deploy.sh -d - to add the --delete flag, this will remove any files at the destination that don't exist in the local
  • ./deploy.sh -c - to compile assets based on the COMPILE_COMMAND in .deployconfig
  • ./deploy.sh -tdc - to run all 3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment