Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support local and Docker build types #16

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 53 additions & 5 deletions lib/bootleg/tasks/phoenix_digest.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,65 @@ defmodule Bootleg.Tasks.PhoenixDigest do
task :phoenix_digest do
alias Bootleg.UI

build_type = config({:build_type, "remote"})
invoke(:"#{build_type}_phoenix_digest")
UI.info("Phoenix asset digest generated")
end

bash_script = """
[ -f package.json ] && npm install || true
[ -f brunch-config.js ] && [ -d node_modules ] && ./node_modules/brunch/bin/brunch b -p || true
[ -f assets/package.json ] && cd assets && npm install && cd .. || true
[ -f assets/brunch-config.js ] && cd assets && [ -d node_modules ] && ./node_modules/brunch/bin/brunch b -p && cd .. || true
[ -d deps/phoenix ] && mix phx.digest || true
"""

task :local_phoenix_digest do
source_path = config({:ex_path, File.cwd!()})

File.cd!(source_path, fn ->
System.cmd("/bin/bash", ["-c", bash_script],
env: [{"MIX_ENV", mix_env}],
into: IO.stream(:stdio, :line)
)
end)
end

task :docker_phoenix_digest do
mix_env = config({:mix_env, "prod"})
source_path = config({:ex_path, File.cwd!()})
docker_image = config(:docker_build_image)
docker_mount = config({:docker_build_mount, "#{source_path}:/opt/build"})
docker_run_options = config({:docker_build_opts, []})

docker_args =
[
"run",
"-v",
docker_mount,
"--rm",
"-t",
"-e",
"MIX_ENV=#{mix_env}"
] ++ docker_run_options ++ [docker_image]

System.cmd("docker", docker_args ++ ["/bin/bash", "-c", bash_script],
into: IO.stream(:stdio, :line)
)
end

task :remote_phoenix_digest do
mix_env = Keyword.get(config(), :mix_env, "prod")

remote :build do
"[ -f package.json ] && npm install || true"
"[ -f brunch-config.js ] && [ -d node_modules ] && ./node_modules/brunch/bin/brunch b -p || true"
"[ -f assets/package.json ] && cd assets && npm install || true"
"[ -f assets/brunch-config.js ] && cd assets && [ -d node_modules ] && ./node_modules/brunch/bin/brunch b -p || true"
"[ -d deps/phoenix ] && MIX_ENV=#{mix_env} mix phoenix.digest || true"
"[ -f assets/package.json ] && cd assets && npm install && cd .. || true"
"[ -f assets/brunch-config.js ] && cd assets && [ -d node_modules ] && ./node_modules/brunch/bin/brunch b -p && cd .. || true"
"[ -d deps/phoenix ] && MIX_ENV=#{mix_env} mix phx.digest || true"
end
UI.info "Phoenix asset digest generated"
end

after_task :compile, :phoenix_digest
after_task(:compile, :phoenix_digest)
end
end