Packages
exrm
0.19.1
1.0.8
1.0.6
1.0.5
1.0.4
1.0.3
1.0.2
1.0.1
1.0.0
1.0.0-rc8
1.0.0-rc7
1.0.0-rc6
1.0.0-rc5
1.0.0-rc4
1.0.0-rc3
0.19.9
0.19.8
0.19.7
0.19.6
0.19.5
0.19.4
0.19.3
0.19.2
0.19.1
0.19.0
0.18.8
0.18.7
0.18.6
0.18.5
0.18.4
0.18.3
0.18.2
0.18.1
0.18.0
0.17.3
0.17.2
0.17.1
0.17.0
0.16.0
0.15.3
0.15.2
0.15.1
0.15.0
0.14.17
0.14.16
0.14.15
0.14.14
0.14.13
0.14.12
0.14.11
0.14.10
0.14.9
0.14.8
0.14.7
0.14.6
0.14.5
0.14.3
0.14.2
0.14.1
0.14.0
0.12.12
0.12.11
0.12.10
0.12.9
0.12.8
0.12.7
0.12.6
0.12.5
0.12.4
0.11.3
0.11.2
0.11.1
0.11.0
0.10.3
0.10.1
0.10.0
0.9.2
0.9.1
0.8.1
0.8.0
0.7.3
0.7.2
0.7.1
0.7.0
0.6.15
0.6.14
0.6.13
0.6.12
0.6.11
0.6.10
0.6.9
0.6.8
0.6.7
0.6.6
0.6.5
0.6.4
0.6.3
0.6.2
0.6.1
0.6.0
0.5.0
0.4.7
Exrm, or Elixir Release Manager, provides mix tasks for building, upgrading, and controlling release packages for your application.
Current section
Files
Jump to
Current section
Files
lib/exrm/plugins/conform.ex
defmodule ReleaseManager.Plugin.Conform do
@name "conform"
@shortdoc "Generates a .conf for your release"
@moduledoc """
Generates a .conf for your release
This plugin ensures that your application has a .schema.exs
and .conf file for setting up configuration via the `conform`
library. This .conf file then offers a simplified interface
for sysadmins and other deployment staff for easily configuring
your release in production.
"""
use ReleaseManager.Plugin
alias ReleaseManager.Config
alias ReleaseManager.Utils
def before_release(%Config{name: app, version: version}) do
empty_schema = Conform.Schema.empty
relx_conf_path = Utils.rel_file_dest_path("relx.config")
schema_dest = Utils.rel_file_dest_path("#{app}.schema.exs")
conf_src = Path.join([File.cwd!, "config", "#{app}.conf"])
debug "Conform: Loading schema..."
# Get top-level schema...
schema = app |> String.to_atom |> Conform.Schema.read!
# Get schemas from all dependencies
dep_schemas = Conform.Schema.coalesce
# Merge together
merged = Conform.Schema.merge(dep_schemas, schema)
# If the merged schema is non-empty, save the schema to config/{app}.schema.exs
continue? = cond do
merged == empty_schema ->
warn "Conform: No schema found, conform will not be packaged in this release!"
false
true ->
Conform.Schema.write_quoted(merged, schema_dest)
info "Conform: Schema succesfully loaded!"
true
end
if continue? do
# Define overlays for relx.config
overlays = [{:copy, '#{schema_dest}', 'releases/#{version}/#{app}.schema.exs'}]
info "Conform: generating #{app}.schema.ez."
# generate archive
result = Mix.Task.run("conform.archive", ["#{schema_dest}"])
# add archive to the overlays
overlays = case result do
{_, _, []} ->
{:ok, cwd} = File.cwd
arch = "#{cwd}/rel/releases/#{version}/#{app}.schema.ez"
case File.exists?(arch) do
true ->
File.rm(arch)
false ->
:ok
end
overlays
{_, zip_path, _} ->
[{:copy, '#{zip_path}', 'releases/#{version}/#{app}.schema.ez'}|overlays]
end
overlays = case File.exists?(conf_src) do
true ->
[{:copy, '#{conf_src}', 'releases/#{version}/#{app}.conf'}|overlays]
false ->
overlays
end
# Generate escript for release
debug "Conform: Generating escript.."
escript_path = Mix.Task.run("conform.release")
overlays = [{:copy, escript_path |> String.to_char_list, 'releases/#{version}/conform'}|overlays]
# Add .conf, .schema.exs, and escript to relx.config as overlays
debug "Conform: Adding overlays to relx.config..."
relx_config = relx_conf_path |> Utils.read_terms
updated = Utils.merge(relx_config, [overlay: overlays])
# Persist relx.config
Utils.write_terms(relx_conf_path, updated)
info "Conform: Done!"
end
end
def after_release(_), do: nil
def after_package(_), do: nil
def after_cleanup(_), do: nil
end