From 5115fbec2b31ca7354f6da880f2588bd1b9b07aa Mon Sep 17 00:00:00 2001 From: Samuel Manzanera Date: Fri, 29 May 2020 17:58:11 +0200 Subject: [PATCH] Update on the release and build: - Create dockerfile for the build - Create scripts to generate the release - Use distillery instead of elixir release for the hot reload support --- .dockerignore | 21 +++++++ .gitignore | 3 +- apps/uniris_core/config/dev.exs | 4 +- apps/uniris_core/mix.exs | 2 +- create_release | 26 ++++++++ docker/build.dockerfile | 29 +++++++++ docker_release | 21 +++++++ mix.exs | 22 ++----- mix.lock | 2 + rel/config.exs | 63 +++++++++++++++++++ rel/plugins/.gitignore | 3 + config/releases.exs => rel/runtime_config.exs | 8 +-- rel/vm.args | 30 +++++++++ 13 files changed, 208 insertions(+), 26 deletions(-) create mode 100644 .dockerignore create mode 100755 create_release create mode 100644 docker/build.dockerfile create mode 100755 docker_release create mode 100644 rel/config.exs create mode 100644 rel/plugins/.gitignore rename config/releases.exs => rel/runtime_config.exs (50%) create mode 100644 rel/vm.args diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..0133f7a6b --- /dev/null +++ b/.dockerignore @@ -0,0 +1,21 @@ +/_build +/cover +/deps +/doc +/.fetch +erl_crash.dump +*.ez +*.beam +/config/*.secret.exs +.elixir_ls +**/doc +. + +/apps/uniris_core/priv/crypto/c_dist +/apps/uniris_core/priv/crypto/storage_nonce +/apps/uniris_core/priv/storage +/apps/uniris_core/priv/last_sync +/apps/uniris_core/priv/p2p/test_seeds + +/create_release.sh +/docker \ No newline at end of file diff --git a/.gitignore b/.gitignore index 26e84bb30..2c74269a8 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,5 @@ erl_crash.dump /apps/uniris_core/priv/crypto/storage_nonce /apps/uniris_core/priv/storage /apps/uniris_core/priv/last_sync -/apps/uniris_core/priv/p2p/test_seeds \ No newline at end of file +/apps/uniris_core/priv/p2p/test_seeds +/rel/artifacts \ No newline at end of file diff --git a/apps/uniris_core/config/dev.exs b/apps/uniris_core/config/dev.exs index 7c8088b2e..005e8c12d 100755 --- a/apps/uniris_core/config/dev.exs +++ b/apps/uniris_core/config/dev.exs @@ -1,9 +1,11 @@ use Mix.Config config :uniris_core, UnirisCore.Crypto, - seed: System.get_env("UNIRIS_CRYPTO_SEED", :crypto.strong_rand_bytes(32)), keystore: UnirisCore.Crypto.SoftwareKeystore +config :uniris_core, UnirisCore.Crypto.SoftwareKeystore, + seed: System.get_env("UNIRIS_CRYPTO_SEED", :crypto.strong_rand_bytes(32)) + config :uniris_core, UnirisCore.BeaconSlotTimer, slot_interval: 58_000 config :uniris_core, UnirisCore.SharedSecrets.NodeRenewal, diff --git a/apps/uniris_core/mix.exs b/apps/uniris_core/mix.exs index fc1d2a244..883f03150 100644 --- a/apps/uniris_core/mix.exs +++ b/apps/uniris_core/mix.exs @@ -4,7 +4,7 @@ defmodule UnirisCore.MixProject do def project do [ app: :uniris_core, - version: "0.1.0", + version: "0.2.0", build_path: "../../_build", config_path: "../../config/config.exs", deps_path: "../../deps", diff --git a/create_release b/create_release new file mode 100755 index 000000000..44317ab03 --- /dev/null +++ b/create_release @@ -0,0 +1,26 @@ +#!/usr/bin/env bash + +mkdir -p rel/artifacts + +# Install updated versions of hex/rebar +mix local.rebar --force +mix local.hex --if-missing --force + +export MIX_ENV=prod + +# Fetch deps and compile +mix deps.get + +# Run an explicit clean to remove any build artifacts from the host +rm -Rf _build/prod + +# Clean the updated files during the dev (last_sync, storage_nonce, file storage) +mix clean_priv_dir + +# Build the release +mix distillery.release + +# Copy tarball to output +cp "_build/prod/rel/uniris_node/releases/$VERSION/uniris_node.tar.gz" rel/artifacts/"uniris_node-$VERSION.tar.gz" + +exit 0 \ No newline at end of file diff --git a/docker/build.dockerfile b/docker/build.dockerfile new file mode 100644 index 000000000..285ca39d9 --- /dev/null +++ b/docker/build.dockerfile @@ -0,0 +1,29 @@ +FROM ubuntu + +ENV VERSION=$version +ENV DEBIAN_FRONTEND=noninteractive +ENV LANG=en_US.UTF-8 + +# Install Erlang,Elixir and build essentials +RUN apt-get update && \ + apt-get install -y wget gnupg2 build-essential -y locales git && \ + locale-gen en_US.UTF-8 && \ + wget https://packages.erlang-solutions.com/erlang-solutions_2.0_all.deb && \ + dpkg -i erlang-solutions_2.0_all.deb && \ + apt-get update && \ + apt-get install -y esl-erlang elixir + +# Install libsodium +RUN wget https://download.libsodium.org/libsodium/releases/LATEST.tar.gz && \ + tar zxvf LATEST.tar.gz && \ + cd libsodium-stable && \ + ./configure && \ + make && make check && \ + make install && \ + ldconfig + +RUN mkdir /opt/build +WORKDIR /opt/build +COPY . . + +CMD ["/bin/bash"] \ No newline at end of file diff --git a/docker_release b/docker_release new file mode 100755 index 000000000..c503188c1 --- /dev/null +++ b/docker_release @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +# Check the arguments +if [[ $# -eq 0 ]] ; then + echo " + Missing version number + + Usage: + + ./docker_release [version_number] + " + exit 1 +fi + +VERSION=$1 + +# Build an image for the release with Elixir/Erlang and Libsodium +docker build -f docker/build.dockerfile -t uniris_release . + +# Run the create_release to generate the release with the given version +docker run -v $(pwd):/opt/build --rm -it --env VERSION=$VERSION uniris_release:latest ./create_release \ No newline at end of file diff --git a/mix.exs b/mix.exs index e30b94e97..33f63059b 100644 --- a/mix.exs +++ b/mix.exs @@ -7,22 +7,7 @@ defmodule Uniris.MixProject do version: "0.1.0", start_permanent: Mix.env() == :prod, deps: deps(), - elixirc_options: [warnings_as_errors: true], - - releases: [ - uniris_node: [ - steps: [ - :assemble, - :tar - ], - include_executables_for: [:unix], - applications: [ - runtime_tools: :permanent, - uniris_core: :permanent, - uniris_web: :temporary - ] - ], - ] + elixirc_options: [warnings_as_errors: true] ] end @@ -33,8 +18,9 @@ defmodule Uniris.MixProject do # Run "mix help deps" for examples and options. defp deps do [ - {:ex_doc, "~> 0.21.2"}, - {:credo, "~> 1.1.0", only: [:dev, :test], runtime: false} + {:ex_doc, "~> 0.21.2", only: :dev}, + {:credo, "~> 1.1.0", only: [:dev, :test], runtime: false}, + {:distillery, "~> 2.0"} ] end end diff --git a/mix.lock b/mix.lock index 5f53e611e..a72506f14 100644 --- a/mix.lock +++ b/mix.lock @@ -2,6 +2,7 @@ "absinthe": {:hex, :absinthe, "1.4.16", "0933e4d9f12652b12115d5709c0293a1bf78a22578032e9ad0dad4efee6b9eb1", [:mix], [{:dataloader, "~> 1.0.0", [hex: :dataloader, repo: "hexpm", optional: true]}, {:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "076b8bd9552f4966ba1242f412f6c439b731169a36a0ddaaffcd3893828f5bf6"}, "absinthe_phoenix": {:hex, :absinthe_phoenix, "1.4.4", "af3b7b44483121f756ea0ec75a536b74f67cdd62ec6a34b9e58df1fb4662389e", [:mix], [{:absinthe, "~> 1.4.0", [hex: :absinthe, repo: "hexpm", optional: false]}, {:absinthe_plug, "~> 1.4.0", [hex: :absinthe_plug, repo: "hexpm", optional: false]}, {:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:phoenix, "~> 1.4", [hex: :phoenix, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.13", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 1.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}], "hexpm", "54118c32ca00257b3cd3e616b3f9cee99e493d2399528334cbb5457e470400d3"}, "absinthe_plug": {:hex, :absinthe_plug, "1.4.7", "939b6b9e1c7abc6b399a5b49faa690a1fbb55b195c670aa35783b14b08ccec7a", [:mix], [{:absinthe, "~> 1.4.11", [hex: :absinthe, repo: "hexpm", optional: false]}, {:plug, "~> 1.3.2 or ~> 1.4", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "c6ecb0e56a963287ac252d0563e5b33b84b300ce8203d3d1410dddb5dc6d08e9"}, + "artificery": {:hex, :artificery, "0.4.3", "0bc4260f988dcb9dda4b23f9fc3c6c8b99a6220a331534fdf5bf2fd0d4333b02", [:mix], [], "hexpm", "12e95333a30e20884e937abdbefa3e7f5e05609c2ba8cf37b33f000b9ffc0504"}, "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"}, "connection": {:hex, :connection, "1.0.4", "a1cae72211f0eef17705aaededacac3eb30e6625b04a6117c1b2db6ace7d5976", [:mix], [], "hexpm", "4a0850c9be22a43af9920a71ab17c051f5f7d45c209e40269a1938832510e4d9"}, "cors_plug": {:hex, :cors_plug, "1.5.2", "72df63c87e4f94112f458ce9d25800900cc88608c1078f0e4faddf20933eda6e", [:mix], [{:plug, "~> 1.3 or ~> 1.4 or ~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "9af027d20dc12dd0c4345a6b87247e0c62965871feea0bfecf9764648b02cc69"}, @@ -10,6 +11,7 @@ "credo": {:hex, :credo, "1.1.5", "caec7a3cadd2e58609d7ee25b3931b129e739e070539ad1a0cd7efeeb47014f4", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "d0bbd3222607ccaaac5c0340f7f525c627ae4d7aee6c8c8c108922620c5b6446"}, "db_connection": {:hex, :db_connection, "2.2.2", "3bbca41b199e1598245b716248964926303b5d4609ff065125ce98bcd368939e", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm", "642af240d8a8affb93b4ba5a6fcd2bbcbdc327e1a524b825d383711536f8070c"}, "decimal": {:hex, :decimal, "1.8.1", "a4ef3f5f3428bdbc0d35374029ffcf4ede8533536fa79896dd450168d9acdf3c", [:mix], [], "hexpm", "3cb154b00225ac687f6cbd4acc4b7960027c757a5152b369923ead9ddbca7aec"}, + "distillery": {:hex, :distillery, "2.1.1", "f9332afc2eec8a1a2b86f22429e068ef35f84a93ea1718265e740d90dd367814", [:mix], [{:artificery, "~> 0.2", [hex: :artificery, repo: "hexpm", optional: false]}], "hexpm", "bbc7008b0161a6f130d8d903b5b3232351fccc9c31a991f8fcbf2a12ace22995"}, "earmark": {:hex, :earmark, "1.4.3", "364ca2e9710f6bff494117dbbd53880d84bebb692dafc3a78eb50aa3183f2bfd", [:mix], [], "hexpm", "8cf8a291ebf1c7b9539e3cddb19e9cef066c2441b1640f13c34c1d3cfc825fec"}, "elixir_make": {:hex, :elixir_make, "0.6.0", "38349f3e29aff4864352084fc736fa7fa0f2995a819a737554f7ebd28b85aaab", [:mix], [], "hexpm", "d522695b93b7f0b4c0fcb2dfe73a6b905b1c301226a5a55cb42e5b14d509e050"}, "ex_doc": {:hex, :ex_doc, "0.21.2", "caca5bc28ed7b3bdc0b662f8afe2bee1eedb5c3cf7b322feeeb7c6ebbde089d6", [:mix], [{:earmark, "~> 1.3.3 or ~> 1.4", [hex: :earmark, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}], "hexpm", "f1155337ae17ff7a1255217b4c1ceefcd1860b7ceb1a1874031e7a861b052e39"}, diff --git a/rel/config.exs b/rel/config.exs new file mode 100644 index 000000000..346b83c75 --- /dev/null +++ b/rel/config.exs @@ -0,0 +1,63 @@ +# Import all plugins from `rel/plugins` +# They can then be used by adding `plugin MyPlugin` to +# either an environment, or release definition, where +# `MyPlugin` is the name of the plugin module. +~w(rel plugins *.exs) +|> Path.join() +|> Path.wildcard() +|> Enum.map(&Code.eval_file(&1)) + +use Distillery.Releases.Config, + # This sets the default release built by `mix distillery.release` + default_release: :default, + # This sets the default environment used by `mix distillery.release` + default_environment: Mix.env() + +# For a full list of config options for both releases +# and environments, visit https://hexdocs.pm/distillery/config/distillery.html + + +# You may define one or more environments in this file, +# an environment's settings will override those of a release +# when building in that environment, this combination of release +# and environment configuration is called a profile + +environment :dev do + # If you are running Phoenix, you should make sure that + # server: true is set and the code reloader is disabled, + # even in dev mode. + # It is recommended that you build with MIX_ENV=prod and pass + # the --env flag to Distillery explicitly if you want to use + # dev mode. + set dev_mode: true + set include_erts: false + set cookie: :"8y|aIx=xQ|1$Ip73CXG>HJz5@kWhR~OyzS?>_en(asysESIrl76Tr0H*RHV@LXK%" +end + +environment :prod do + set include_erts: true + set include_src: false + set cookie: :"c$^t~i5q@BHl>tHN;!*@d_n|!h|6n0~f)6q{Qk1Eg(IUJ$YH_oFUE_RCRGjGI3%G" + set vm_args: "rel/vm.args" + set config_providers: [ + {Distillery.Releases.Config.Providers.Elixir, ["${RELEASE_ROOT_DIR}/etc/runtime_config.exs"]} + ] + set overlays: [ + {:copy, "rel/runtime_config.exs", "etc/runtime_config.exs"} + ] +end + +# You may define one or more releases in this file. +# If you have not set a default release, or selected one +# when running `mix distillery.release`, the first release in the file +# will be used by default + +release :uniris_node do + set version: System.fetch_env!("VERSION") + set applications: [ + :runtime_tools, + uniris_core: :permanent, + uniris_web: :permanent + ] +end + diff --git a/rel/plugins/.gitignore b/rel/plugins/.gitignore new file mode 100644 index 000000000..4fa3b5c29 --- /dev/null +++ b/rel/plugins/.gitignore @@ -0,0 +1,3 @@ +*.* +!*.exs +!.gitignore \ No newline at end of file diff --git a/config/releases.exs b/rel/runtime_config.exs similarity index 50% rename from config/releases.exs rename to rel/runtime_config.exs index ee8ff0042..18e000ab1 100644 --- a/config/releases.exs +++ b/rel/runtime_config.exs @@ -1,15 +1,13 @@ import Config -config :uniris_core, UnirisCore.Crypto, +config :uniris_core, UnirisCore.Crypto.SoftwareKeystore, seed: System.fetch_env!("UNIRIS_CRYPTO_SEED") config :uniris_core, UnirisCore.P2P, - port: System.get_env("UNIRIS_P2P_PORT", "3002") |> String.to_integer() + port: 3002 config :uniris_web, UnirisWeb.Endpoint, https: [ - port: System.get_env("UNIRIS_WEB_PORT", "443") |> String.to_integer(), keyfile: System.fetch_env!("UNIRIS_WEB_SSL_KEY_PATH"), certfile: System.fetch_env!("UNIRIS_WEB_SSL_CERT_PATH") - ], - url: [port: System.get_env("UNIRIS_WEB_PORT", "443") |> String.to_integer()] + ] diff --git a/rel/vm.args b/rel/vm.args new file mode 100644 index 000000000..93f34bb37 --- /dev/null +++ b/rel/vm.args @@ -0,0 +1,30 @@ +## This file provide the arguments provided to the VM at startup +## You can find a full list of flags and their behaviours at +## http://erlang.org/doc/man/erl.html + +## Name of the node +-name <%= release_name %>@127.0.0.1 + +## Cookie for distributed erlang +-setcookie <%= release.profile.cookie %> + +## Heartbeat management; auto-restarts VM if it dies or becomes unresponsive +## (Disabled by default..use with caution!) +##-heart + +## Enable kernel poll and a few async threads +##+K true +##+A 5 +## For OTP21+, the +A flag is not used anymore, +## +SDio replace it to use dirty schedulers +##+SDio 5 + +## Increase number of concurrent ports/sockets +##-env ERL_MAX_PORTS 4096 + +## Tweak GC to run more often +##-env ERL_FULLSWEEP_AFTER 10 + +# Enable SMP automatically based on availability +# On OTP21+, this is not needed anymore. +-smp auto