Current section

Files

Jump to
horizon priv templates bin build_script.sh.eex
Raw

priv/templates/bin/build_script.sh.eex

#!/bin/sh
# File autogenerated by mix horizon.init (source: build_script.sh.eex)
# Version: <%= @version %>
#
# Build script for a project to be run on the target machine.
# This app is located in the build folder for each `bin_path` and release.
#
# Exit immediately if a command exits with a non-zero status
set -eu
# Set ELIXIR_ERL_OPTIONS to force UTF-8 encoding
export ELIXIR_ERL_OPTIONS="+fnu +pc unicode"
export ERL_AFLAGS="+fnu"
# Navigate to the project directory
BUILD_PATH=<%= @build_path %>
cd $BUILD_PATH
. ./<%= @bin_path %>/horizon_helpers.sh
printf "${GREEN}=== Starting Build Process ===${RESET}\n"
puts "info" "Setting up assets"
puts "info" "Install local.hex"
if [ -f <%= @env_path %> ]; then
. <%= @env_path %>
fi
MIX_ENV=prod mix deps.clean <%= @app %> --build
MIX_ENV=prod mix local.hex --force
MIX_ENV=prod mix deps.get --only prod
# Will need to manually check if tailwind for freebsd is installed as currently the --if-missing flag is not supported when passing in an argument
## install tailwind if it is not installed
create_app_dir() {
doas mkdir -p <%= @app_path %>/releases
doas chown -R $(whoami) <%= @app_path %>
}
mix_assets_setup_freebsd() {
puts "info" "Checking for tailwind-$(get_arch)"
if [ ! -f "<%= @build_path %>/_build/tailwind-$(get_arch)" ]; then
puts "info" "Installing Tailwind <%= @build_path %>/_build/tailwind-$(get_arch)"
MIX_ENV=prod mix assets.setup.freebsd
else
puts "info" "Tailwind installed <%= @build_path %>/_build/tailwind-$(get_arch)"
fi
echo ""
}
mix_phx_digest_clean() {
puts "info" "Cleaning existing digests"
MIX_ENV=prod mix phx.digest.clean --all
echo ""
}
mix_assets_deploy() {
puts "info" "Running: mix assets.deploy.freebsd"
MIX_ENV=prod mix assets.deploy.freebsd
echo ""
}
mix_release() {
target="<%= if not @is_default?, do: @app %>"
puts "info" "Running: mix release $target"
sh -c "MIX_ENV=prod mix release <%= if not @is_default?, do: @app %> --overwrite"
}
puts "info" "Creating/Updating the release"
create_app_dir
mix_assets_setup_freebsd
mix_phx_digest_clean
mix_assets_deploy
mix_release
# move this to deploy/release
# sysrc <%= @app %>_enable="YES"
# add_user <%= @app %>
version="$(cut -d' ' -f2 "<%= @app_path %>/releases/start_erl.data")"
# App is in folder <%= @app_path %> <%= @app %>-$version.tar.gz
# App is ready for deployment to another host or started on the build host.