Skip to content

Commit

Permalink
Added codename configuration, added architecture in .deb file name (#32)
Browse files Browse the repository at this point in the history
* Added codename configuration, system architecture now is chained to .deb file name

* Added details about codename on README

* Fix warning in mixfile for Elixir 1.4, version bumb

* Fix broken mix.lock, fix missing warnings for Elixir 1.4
  • Loading branch information
samuelebistoletti authored and johnhamelink committed Mar 2, 2017
1 parent a872c69 commit dd00130
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 40 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ The `package` function must be set as per the [hex guidelines][2], but with some
def package do
[
+ external_dependencies: [],
+ codename: lsb_release(),
+ license_file: "LICENSE",
files: [ "lib", "mix.exs", "README*", "LICENSE"],
+ config_files: ["/etc/init/api.conf"],
Expand All @@ -73,6 +74,13 @@ def package do
end
```

```
def lsb_release do
{release, _} = System.cmd("lsb_release", ["-c", "-s"])
String.replace(release, "\n", "")
end
```

A list of configuration options you can add to `package/0`:

- `config_file`
Expand All @@ -99,6 +107,23 @@ A list of configuration options you can add to `package/0`:
- If set, requires both `user` and `group` keys to be set.
- This is used when building the archive to set the correct user and group
- Defaults to root for user & group.
- `codename`
- String
- Should contain the distribution codename to be chained to version number.

### Additional details about codename

This configuration can be very useful in case you want to package the same version
of the app for different distribution dinamically, without modifying the version
in Distillery configuration.

A typical use case can be an environment where you have different Docker containers,
with different OS, each container compiles and packages the application in the running OS,
in order to avoid startup problems in production.

With codename, at the end of the process, you obtain a package in the form "myapp-1.2.1~xenial_amd64.deb".
Also the control script in deb file is packaged with the correct version like 1.2.1~xenial.
At this point, it easier to manage the packages loaded in a repository, because they are versioned also by distribution.

## Usage

Expand Down
2 changes: 1 addition & 1 deletion lib/exrm_deb.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ defmodule ExrmDeb do

def start_build(config) do
ExrmDeb.remove_deb_dir
deb_root = initialize_dir
deb_root = initialize_dir()

{:ok, config} = Data.build(deb_root, config)
:ok = Control.build(deb_root, config)
Expand Down
21 changes: 15 additions & 6 deletions lib/exrm_deb/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@ defmodule ExrmDeb.Config do
the data is in the correct format.
"""

defstruct name: nil, version: nil, licenses: nil, maintainers: nil,
external_dependencies: nil, maintainer_scripts: [],
config_files: [], homepage: nil, description: nil,
defstruct name: nil, version: nil, codename: nil, licenses: nil,
maintainers: nil, external_dependencies: nil,
maintainer_scripts: [], config_files: [],
homepage: nil, description: nil,
vendor: nil, arch: nil, distillery: false,
owner: [user: "root", group: "root"]

use Vex.Struct
alias ReleaseManager.Utils.Logger
alias ExrmDeb.Utils
alias Mix.Project
import Logger, only: [debug: 1, error: 1]
import Logger, only: [error: 1]

# This version number format should be able to handle regular version
# numbers as well as alpha/beta versions
Expand All @@ -36,11 +37,11 @@ defmodule ExrmDeb.Config do
base_config =
[
{:name, Atom.to_string(release.name)},
{:version, release.version},
{:description, Project.config[:description]},
{:arch, Utils.Config.detect_arch},
{:distillery, true}
] ++ config_from_package(Project.config[:package])
++ config_version(release.version, Project.config[:package][:codename])

base_config =
base_config
Expand All @@ -57,10 +58,11 @@ defmodule ExrmDeb.Config do
base_config =
[
{:name, Atom.to_string(Project.config[:app])},
{:version, Project.config[:version]},
{:description, Project.config[:description]},
{:arch, ExrmDeb.Utils.Config.detect_arch}
] ++ config_from_package(Project.config[:package])
++ config_version(Project.config[:version],
Project.config[:package][:codename])

base_config =
base_config
Expand All @@ -75,6 +77,13 @@ defmodule ExrmDeb.Config do
end
def build_config(:exrm), do: build_config(:exrm, %{})

defp config_version(version, codename) when codename != nil do
[{:version, version <> "~" <> codename}]
end
defp config_version(version, _) do
[{:version, version}]
end

defp config_from_package(nil) do
"""
Error: You haven't defined any 'package' data in mix.exs.
Expand Down
2 changes: 1 addition & 1 deletion lib/exrm_deb/deb.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule ExrmDeb.Deb do

out = Path.join([
Utils.rel_dest_path,
"#{config.sanitized_name}-#{config.version}.deb"
"#{config.sanitized_name}-#{config.version}_#{config.arch}.deb"
])

File.rm out
Expand Down
2 changes: 1 addition & 1 deletion lib/exrm_deb/utils/compression.ex
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule ExrmDeb.Utils.Compression do
cmd_opts = opts ++ ["-acf", outfile, "."]

{_ignore, 0} = System.cmd(
tar_cmd,
tar_cmd(),
cmd_opts,
cd: dir,
stderr_to_stdout: true,
Expand Down
8 changes: 4 additions & 4 deletions lib/mix/tasks/release.deb.generate_templates.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ defmodule Mix.Tasks.Release.Deb.GenerateTemplates do
alias ReleaseManager.Utils

def run(_args) do
make_dest_dir
copy_templates
make_dest_dir()
copy_templates()
end

def copy_templates(dest \\ destination_dir) do
def copy_templates(dest \\ destination_dir()) do
Logger.info "Copying templates to ./rel/exrm_deb/templates"
{:ok, _} =
[ConfigUtil.root, "templates"]
Expand All @@ -33,7 +33,7 @@ defmodule Mix.Tasks.Release.Deb.GenerateTemplates do
defp make_dest_dir do
Logger.info "Making ./rel/exrm_deb/templates directory"
:ok =
destination_dir
destination_dir()
|> File.mkdir_p
end

Expand Down
4 changes: 2 additions & 2 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ defmodule ExrmDeb.Mixfile do

def project do
[app: :exrm_deb,
version: "0.1.0",
version: "0.1.1",
elixir: "~> 1.3",
description: "Create a deb for your elixir release with ease",
build_embedded: Mix.env == :prod,
Expand All @@ -14,7 +14,7 @@ defmodule ExrmDeb.Mixfile do
"coveralls": :test,
"coveralls.detail": :test,
"coveralls.post": :test],
package: package]
package: package()]
end

def application, do: [applications: apps(Mix.env)]
Expand Down
44 changes: 19 additions & 25 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,32 +1,26 @@
%{"bbmustache": {:hex, :bbmustache, "1.0.4", "7ba94f971c5afd7b6617918a4bb74705e36cab36eb84b19b6a1b7ee06427aa38", [:rebar], []},
"bunt": {:hex, :bunt, "0.1.6", "5d95a6882f73f3b9969fdfd1953798046664e6f77ec4e486e6fafc7caad97c6f", [:mix], []},
"certifi": {:hex, :certifi, "0.4.0", "a7966efb868b179023618d29a407548f70c52466bf1849b9e8ebd0e34b7ea11f", [:rebar3], []},
"cf": {:hex, :cf, "0.2.1", "69d0b1349fd4d7d4dc55b7f407d29d7a840bf9a1ef5af529f1ebe0ce153fc2ab", [:rebar3], []},
"combine": {:hex, :combine, "0.9.2", "cd3c8721f378ebe032487d8a4fa2ced3181a456a3c21b16464da8c46904bb552", [:mix], []},
"distillery": {:hex, :distillery, "1.0.0", "a866a72bf2a3a5f078f5a249017ed951acda88a760d200512f91f585d74db1ec", [:mix], []},
"credo": {:hex, :credo, "0.5.3", "0c405b36e7651245a8ed63c09e2d52c2e2b89b6d02b1570c4d611e0fcbecf4a2", [:mix], [{:bunt, "~> 0.1.6", [hex: :bunt, optional: false]}]},
"dogma": {:hex, :dogma, "0.1.8", "1ee856ed64f3ad635a4b2127beea427ea1b9bc271b8731679a97938e1827730f", [:mix], [{:poison, ">= 1.0.0", [hex: :poison, optional: false]}]},
"earmark": {:hex, :earmark, "1.0.1", "2c2cd903bfdc3de3f189bd9a8d4569a075b88a8981ded9a0d95672f6e2b63141", [:mix], []},
"erlware_commons": {:hex, :erlware_commons, "0.21.0", "a04433071ad7d112edefc75ac77719dd3e6753e697ac09428fc83d7564b80b15", [:rebar3], [{:cf, "0.2.1", [hex: :cf, optional: false]}]},
"ex_doc": {:hex, :ex_doc, "0.14.1", "bfed8d4e93c755e2b150be925ad2cfa6af7c3bfcacc3b609f45f6048c9d623d6", [:mix], [{:earmark, "~> 1.0", [hex: :earmark, optional: false]}]},
"excoveralls": {:hex, :excoveralls, "0.5.1", "5b55d62b384c7edda8b26b52b1a9fc9358fec2e6b157a81071de5cb8a42e4721", [:mix], [{:exjsx, "~> 3.0", [hex: :exjsx, optional: false]}, {:hackney, ">= 0.12.0", [hex: :hackney, optional: false]}]},
"exjsx": {:hex, :exjsx, "3.2.0", "7136cc739ace295fc74c378f33699e5145bead4fdc1b4799822d0287489136fb", [:mix], [{:jsx, "~> 2.6.2", [hex: :jsx, optional: false]}]},
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], []},
"certifi": {:hex, :certifi, "1.0.0", "1c787a85b1855ba354f0b8920392c19aa1d06b0ee1362f9141279620a5be2039", [:rebar3], []},
"cf": {:hex, :cf, "0.2.2", "7f2913fff90abcabd0f489896cfeb0b0674f6c8df6c10b17a83175448029896c", [:rebar3], []},
"combine": {:hex, :combine, "0.9.6", "8d1034a127d4cbf6924c8a5010d3534d958085575fa4d9b878f200d79ac78335", [:mix], []},
"credo": {:hex, :credo, "0.6.1", "a941e2591bd2bd2055dc92b810c174650b40b8290459c89a835af9d59ac4a5f8", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, optional: false]}]},
"distillery": {:hex, :distillery, "1.2.2", "d5a52920cbe2378c8a21dfc83b526b4225944b9dce7bf170fe5f5cddda81ffb3", [:mix], []},
"dogma": {:hex, :dogma, "0.1.14", "561abecb25a2408738e7d2bc34cc565a07e6fadbc4fb91b2cbb35a5a9234cf1c", [:mix], [{:poison, ">= 2.0.0", [hex: :poison, optional: false]}]},
"earmark": {:hex, :earmark, "1.1.1", "433136b7f2e99cde88b745b3a0cfc3fbc81fe58b918a09b40fce7f00db4d8187", [:mix], []},
"erlware_commons": {:hex, :erlware_commons, "0.22.0", "051bed79a34e66678c1cbeebc7b66360c827d081a0c5e2528878011e31ddcdca", [:rebar3], [{:cf, "0.2.2", [hex: :cf, optional: false]}]},
"ex_doc": {:hex, :ex_doc, "0.15.0", "e73333785eef3488cf9144a6e847d3d647e67d02bd6fdac500687854dd5c599f", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, optional: false]}]},
"exrm": {:hex, :exrm, "1.0.8", "5aa8990cdfe300282828b02cefdc339e235f7916388ce99f9a1f926a9271a45d", [:mix], [{:relx, "~> 3.5", [hex: :relx, optional: false]}]},
"faker": {:hex, :faker, "0.6.0", "2d2ff0879d6b10fab5fb47eb2c1149b811e4af780a17022aa249deb3a7156d2b", [:mix], []},
"getopt": {:hex, :getopt, "0.8.2", "b17556db683000ba50370b16c0619df1337e7af7ecbf7d64fbf8d1d6bce3109b", [:rebar], []},
"gettext": {:hex, :gettext, "0.11.0", "80c1dd42d270482418fa158ec5ba073d2980e3718bacad86f3d4ad71d5667679", [:mix], []},
"hackney": {:hex, :hackney, "1.6.1", "ddd22d42db2b50e6a155439c8811b8f6df61a4395de10509714ad2751c6da817", [:rebar3], [{:certifi, "0.4.0", [hex: :certifi, optional: false]}, {:idna, "1.2.0", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.0", [hex: :ssl_verify_fun, optional: false]}]},
"idna": {:hex, :idna, "1.2.0", "ac62ee99da068f43c50dc69acf700e03a62a348360126260e87f2b54eced86b2", [:rebar3], []},
"inch_ex": {:hex, :inch_ex, "0.5.1"},
"jsx": {:hex, :jsx, "2.6.2", "213721e058da0587a4bce3cc8a00ff6684ced229c8f9223245c6ff2c88fbaa5a", [:mix, :rebar], []},
"gettext": {:hex, :gettext, "0.13.1", "5e0daf4e7636d771c4c71ad5f3f53ba09a9ae5c250e1ab9c42ba9edccc476263", [:mix], []},
"hackney": {:hex, :hackney, "1.7.1", "e238c52c5df3c3b16ce613d3a51c7220a784d734879b1e231c9babd433ac1cb4", [:rebar3], [{:certifi, "1.0.0", [hex: :certifi, optional: false]}, {:idna, "4.0.0", [hex: :idna, optional: false]}, {:metrics, "1.0.1", [hex: :metrics, optional: false]}, {:mimerl, "1.0.2", [hex: :mimerl, optional: false]}, {:ssl_verify_fun, "1.1.1", [hex: :ssl_verify_fun, optional: false]}]},
"idna": {:hex, :idna, "4.0.0", "10aaa9f79d0b12cf0def53038547855b91144f1bfcc0ec73494f38bb7b9c4961", [:rebar3], []},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], []},
"mimerl": {:hex, :mimerl, "1.0.2", "993f9b0e084083405ed8252b99460c4f0563e41729ab42d9074fd5e52439be88", [:rebar3], []},
"poison": {:hex, :poison, "2.1.0", "f583218ced822675e484648fa26c933d621373f01c6c76bd00005d7bd4b82e27", [:mix], []},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], []},
"providers": {:hex, :providers, "1.6.0", "db0e2f9043ae60c0155205fcd238d68516331d0e5146155e33d1e79dc452964a", [:rebar3], [{:getopt, "0.8.2", [hex: :getopt, optional: false]}]},
"relx": {:hex, :relx, "3.21.0", "91e1ea9f09b4edfda8461901f4b5c5e0226e43ec161e147eeab29f7761df6eb5", [:rebar3], [{:bbmustache, "1.0.4", [hex: :bbmustache, optional: false]}, {:cf, "0.2.1", [hex: :cf, optional: false]}, {:erlware_commons, "0.21.0", [hex: :erlware_commons, optional: false]}, {:getopt, "0.8.2", [hex: :getopt, optional: false]}, {:providers, "1.6.0", [hex: :providers, optional: false]}]},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.0", "edee20847c42e379bf91261db474ffbe373f8acb56e9079acb6038d4e0bf414f", [:make, :rebar], []},
"ssl_verify_hostname": {:hex, :ssl_verify_hostname, "1.0.5", "2e73e068cd6393526f9fa6d399353d7c9477d6886ba005f323b592d389fb47be", [:make], []},
"swab": {:git, "https://github.com/crownedgrouse/swab.git", "796460142133da5360c64faa3e7fa78f40af09b9", [branch: "master"]},
"timex": {:hex, :timex, "3.0.8", "71d5ebafcdc557c6c866cdc196c5054f587e7cd1118ad8937e2293d51fc85608", [:mix], [{:combine, "~> 0.7", [hex: :combine, optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5", [hex: :tzdata, optional: false]}]},
"tzdata": {:hex, :tzdata, "0.5.9", "575be217b039057a47e133b72838cbe104fb5329b19906ea4e66857001c37edb", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, optional: false]}]},
"relx": {:hex, :relx, "3.22.2", "aee2ef6e9ac6d21d6661133b7a0be6e81424de9cdca0012fc008bc677297c469", [:rebar3], [{:bbmustache, "1.0.4", [hex: :bbmustache, optional: false]}, {:cf, "0.2.2", [hex: :cf, optional: false]}, {:erlware_commons, "0.22.0", [hex: :erlware_commons, optional: false]}, {:getopt, "0.8.2", [hex: :getopt, optional: false]}, {:providers, "1.6.0", [hex: :providers, optional: false]}]},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.1", "28a4d65b7f59893bc2c7de786dec1e1555bd742d336043fe644ae956c3497fbe", [:make, :rebar], []},
"swab": {:git, "https://github.com/crownedgrouse/swab.git", "f1f22531491d3a2fbbfd17b4f34503b395dd6ab4", [branch: "master"]},
"timex": {:hex, :timex, "3.1.13", "48b33162e3ec33e9a08fb5f98e3f3c19c3e328dded3156096c1969b77d33eef0", [:mix], [{:combine, "~> 0.7", [hex: :combine, optional: false]}, {:gettext, "~> 0.10", [hex: :gettext, optional: false]}, {:tzdata, "~> 0.1.8 or ~> 0.5", [hex: :tzdata, optional: false]}]},
"tzdata": {:hex, :tzdata, "0.5.10", "087e8dfe8c0283473115ad8ca6974b898ecb55ca5c725427a142a79593391e90", [:mix], [{:hackney, "~> 1.0", [hex: :hackney, optional: false]}]},
"vex": {:hex, :vex, "0.6.0", "4e79b396b2ec18cd909eed0450b19108d9631842598d46552dc05031100b7a56", [:mix], []}}

0 comments on commit dd00130

Please sign in to comment.