Skip to content

Instantly share code, notes, and snippets.

@motephyr
Last active December 19, 2018 15:06
Show Gist options
  • Save motephyr/a13b5cab05dbf5bfd78c0bfc81a35bf8 to your computer and use it in GitHub Desktop.
Save motephyr/a13b5cab05dbf5bfd78c0bfc81a35bf8 to your computer and use it in GitHub Desktop.
alias Bootleg.{UI, Config}
use Bootleg.DSL
# Configure the following roles to match your environment.
# `build` defines what remote server your distillery release should be built on.
#
# Some available options are:
# - `user`: ssh username to use for SSH authentication to the role's hosts
# - `password`: password to be used for SSH authentication
# - `identity`: local path to an identity file that will be used for SSH authentication instead of a password
# - `workspace`: remote file system path to be used for building and deploying this Elixir project
role :build, "xxx.xxx.xxx.xxx", user: "xxxxxx", workspace: "/tmp/bootleg/build", identity: "~/.ssh/xxx", release_workspace: "/home/xxxxxxxx/app"
role :app, ["xxx.xxx.xxx.xxx"], user: "xxxxxx", workspace: "/home/xxxxxx/app", identity: "~/.ssh/xxx", release_workspace: "/home/xxxxxxx/app"
config :mix_env, "staging"
config :refspec, "develop"
# config :git_mode, :pull
# config :repo_url, "[email protected]:xxxx/xxxxxx.git"
task :remote_build do
build_role = Config.get_role(:build)
invoke(:init)
# invoke(:clean)
invoke(:remote_scm_update)
invoke(:compile)
invoke(:remote_generate_release)
if build_role.options[:release_workspace] do
invoke(:copy_build_release)
else
invoke(:download_release)
end
end
before_task :remote_build do
Task.async(fn ->
UI.info("start compile js")
"mix phx.digest.clean; cd assets; yarn; brunch build --production; cd ..; MIX_ENV=staging mix phx.digest"
|> String.to_charlist
|> :os.cmd
UI.info("finish compile js")
end)
# Task.await(task)
end
task :compile do
build_at= Config.get_role(:build).options[:workspace]
key= Config.get_role(:build).options[:identity]
"scp -i #{key} -r ./config/staging.secret.exs dressertest:#{build_at}/config/staging.secret.exs"
|> String.to_charlist
|> :os.cmd
mix_env = config({:mix_env, "staging"})
source_path = config({:ex_path, ""})
UI.info("Building on remote server with mix env #{mix_env}...")
remote :build, cd: source_path do
"MIX_ENV=#{mix_env} mix local.rebar --force"
"MIX_ENV=#{mix_env} mix local.hex --if-missing --force"
"MIX_ENV=#{mix_env} mix deps.get --only=#{mix_env}"
"MIX_ENV=#{mix_env} mix do clean, compile --force"
end
UI.info("rsync js")
"rsync -av -e 'ssh -i #{key}' ./priv/static/ xxxxxxx:#{build_at}/priv/static/"
|> String.to_charlist
|> :os.cmd
end
task :migrate do
mix_env = config({:mix_env, "staging"})
source_path = config({:ex_path, ""})
remote :build, cd: source_path do
"MIX_ENV=#{mix_env} mix ecto.migrate"
end
:ok
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment