Last active
February 23, 2016 17:34
-
-
Save binarytemple/195153fc2dc4645a770c to your computer and use it in GitHub Desktop.
[elixir] extracting env information from docker-machine via command execution/parsing
This file contains hidden or 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
| ``` | |
| defmodule DockerMachine do | |
| def get_env() do | |
| case System.cmd("docker-machine", ["env","local"]) do | |
| {output,0} -> { | |
| :success, output |> | |
| String.split("\n") |> | |
| Enum.filter(fn x -> x =~ "export DOCKER" end) |> | |
| Enum.map( fn l -> | |
| String.replace(l, ~r/export (.*)/,"\\1") |> | |
| String.replace(~r/\"/,"") |> | |
| String.split("=") |> | |
| List.to_tuple end)|> | |
| Enum.map( | |
| fn | |
| {"DOCKER_TLS_VERIFY", docker_tls_verify} -> {:docker_tls_verify, docker_tls_verify} | |
| {"DOCKER_HOST", docker_host} -> {:docker_host, docker_host} | |
| {"DOCKER_CERT_PATH", docker_cert_path} -> {:docker_cert_path, docker_cert_path} | |
| {"DOCKER_MACHINE_NAME",docker_machine_name} -> {:docker_machine_name,docker_machine_name} | |
| other -> {:error, other} | |
| end | |
| ) | |
| } | |
| {output,number} -> {:error,output,number} | |
| other -> {:error,other} | |
| end | |
| end | |
| end | |
| ``` |
Author
binarytemple
commented
Feb 23, 2016
Author
Hoping to use it in this way ( config/dev.exs )
use Mix.Config
{:success, keylist} = DockerMachine.get_env
m = Map.new(keylist)
config :docker,
base_url: m[:docker_host],
ssl_options: [
{:ca_file, m[:docker_cert_path] <> "/docker.crt"},
{:cert_file, m[:docker_cert_path] <> "/docker.crt"},
{:key_file, m[:docker_cert_path] <> "/ca.crt"},
],
machine_name: m[:docker_machine_name]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment