Last active
January 7, 2019 06:15
-
-
Save jonlunsford/58fee36a705cf50a5a0342bdf47036c9 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# ./lib/mix/taks/docker.ex | |
defmodule Mix.Tasks.Docker do | |
use Mix.Task | |
@shortdoc "Docker utilities for building releases" | |
def run(["release"]) do | |
# Build a fresh Elixir image, in case Dockerfile has changed | |
docker("build -t elixir-ubuntu:latest .") | |
# Get the current working directory | |
{dir, _resp} = System.cmd("pwd", []) | |
# Mount the working directory at /opt/build within the new elixir image | |
# Pass in the rel/bin/release script that will run distillery | |
docker( | |
"run -v #{String.trim(dir)}:/opt/build --rm -i elixir-ubuntu:latest /opt/build/rel/bin/release" | |
) | |
end | |
def run(["upgrade"]) do | |
# Build a fresh Elixir image, in case Dockerfile has changed | |
docker("build -t elixir-ubuntu:latest .") | |
# Get the current working directory | |
{dir, _resp} = System.cmd("pwd", []) | |
# Mount the working directory at /opt/build within the new elixir image | |
# Pass in the rel/bin/release script that will run distillery with the --upgrade flag | |
docker( | |
"run -v #{String.trim(dir)}:/opt/build --rm -i elixir-ubuntu:latest /opt/build/rel/bin/release --upgrade" | |
) | |
end | |
defp docker(cmd) do | |
System.cmd("docker", String.split(cmd, " "), into: IO.stream(:stdio, :line)) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment