Skip to content

Instantly share code, notes, and snippets.

@andreapavoni
Created May 22, 2017 08:53
Show Gist options
  • Save andreapavoni/a858bf576af144274e2aca1eafdf99af to your computer and use it in GitHub Desktop.
Save andreapavoni/a858bf576af144274e2aca1eafdf99af to your computer and use it in GitHub Desktop.
Edeliver configuration to deploy a Phoenix app compiling and digesting assets locally
# MYAPP/.deliver/config
APP="<APP NAME>"
MAIN_HOST="<BUILD & PRODUCTION HOST>"
MAIN_USER="<MAIN USER FOR BUILD AND DEPLOY>"
BUILD_HOST="${MAIN_HOST}"
BUILD_USER="${MAIN_USER}"
BUILD_AT="/tmp/edeliver/${APP}/builds"
PRODUCTION_HOSTS="${MAIN_HOST}" # deploy / production hosts separated by space
PRODUCTION_USER="${MAIN_USER}" # local user at deploy hosts
DELIVER_TO="/home/${MAIN_USER}/apps" # deploy directory on production hosts
AUTO_VERSION=git-branch+git-revision
RELEASE_DIR="${BUILD_AT}/rel/${APP}"
USING_DISTILLERY=true
RELEASE_STORE_PATH="/home/${MAIN_USER}/releases/"
RELEASE_STORE="${BUILD_USER}@${BUILD_HOST}:${RELEASE_STORE_PATH}"
post_git_push() {
status "Hard-Cleaning generated files from last build"
__sync_remote "
[ -f ~/.profile ] && source ~/.profile
set -e
cd $DELIVER_TO
echo \"cleaning files in: $GIT_CLEAN_PATHS\"
git clean -ffdx $GIT_CLEAN_PATHS
"
}
# Compile assets for phoenix app
pre_erlang_clean_compile() {
status "Compiling assets locally:"
# compile assets locally (see .deliver/production_assets.zsh)
eval "$(pwd)/.deliver/production_assets.zsh"
# copy assets to remote host
status "Copy assets to ${BUILD_USER}@${BUILD_HOST}:${BUILD_AT}"
scp -r priv/static ${BUILD_USER}@${BUILD_HOST}:${BUILD_AT}/priv/static
status "Creating releases directory if does not exists"
__sync_remote "
set -e
mkdir -p ${RELEASE_STORE_PATH}
"
}
pre_start_deployed_release() {
symlink_static
symlink_uploads
}
# Symlink static assets from released app dir to the server
symlink_static(){
status "Symlinking static assets path"
__sync_remote "
[ -f ~/.profile ] && source ~/.profile
set -e
ln -sfn $DELIVER_TO/$APP/lib/$APP-$RELEASE$VERSION/priv/static $DELIVER_TO/$APP/static
"
}
# Optional: Symlink server uploads folder to the released app dir
symlink_uploads(){
status "Symlinking uploads path"
__sync_remote "
[ -f ~/.profile ] && source ~/.profile
set -e
[ ! -d $DELIVER_TO/$APP/uploads ] && mkdir -p $DELIVER_TO/$APP/uploads
ln -sfn $DELIVER_TO/$APP/uploads $DELIVER_TO/$APP/lib/$APP-$RELEASE$VERSION/uploads
"
}
# vim: set ft=sh:
# MYAPP/.deliver/production_assets.zsh
# Feel free to change zsh to bash (or whatever your shell is)
# and eventual local commands for asset compiling
#!/usr/bin/env zsh
source ~/.zshrc
nvm &>/dev/null
echo "Run yarn install"
yarn install
echo "Remove old priv/static"
[ -d priv/static ] && rm -rf priv/static
echo "Compile assets"
npm run deploy
echo "Create digest"
MIX_ENV=prod mix phoenix.digest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment