Implement releases
This commit is contained in:
parent
7ae60f9270
commit
8a5aa5b5aa
9 changed files with 163 additions and 3 deletions
18
lib/mix/tasks/mebe.build.frontend.ex
Normal file
18
lib/mix/tasks/mebe.build.frontend.ex
Normal file
|
@ -0,0 +1,18 @@
|
|||
defmodule Mix.Tasks.Mebe.Build.Frontend do
|
||||
use MBU.BuildTask, auto_path: false, create_out_path: false
|
||||
import MBU.TaskUtils
|
||||
|
||||
@shortdoc "Build Mebe2 frontend"
|
||||
|
||||
@deps ["mebe.clean"]
|
||||
|
||||
task _ do
|
||||
frontend_path = Path.join([File.cwd!(), "lib", "web", "frontend"])
|
||||
|
||||
[
|
||||
exec(System.find_executable("bsb"), [], name: "ocaml", cd: frontend_path),
|
||||
exec(System.find_executable("node"), ["fuse", "build"], name: "fusebox", cd: frontend_path)
|
||||
]
|
||||
|> listen()
|
||||
end
|
||||
end
|
|
@ -2,6 +2,8 @@ const { FuseBox, QuantumPlugin, SassPlugin, CSSPlugin, CSSResourcePlugin } = req
|
|||
|
||||
const DIST_PATH = '../../../priv/static';
|
||||
|
||||
const BUILD_ONLY = process.argv.length > 2 && process.argv[2] === 'build';
|
||||
|
||||
const IS_PRODUCTION = process.env.NODE_ENV === 'production';
|
||||
|
||||
const fuse = FuseBox.init({
|
||||
|
@ -23,7 +25,7 @@ const fuse = FuseBox.init({
|
|||
]
|
||||
});
|
||||
|
||||
if (!IS_PRODUCTION) {
|
||||
if (!IS_PRODUCTION && !BUILD_ONLY) {
|
||||
fuse.dev({
|
||||
port: 2125,
|
||||
proxy: {
|
||||
|
@ -37,7 +39,7 @@ if (!IS_PRODUCTION) {
|
|||
|
||||
const app = fuse.bundle('app').instructions(`> index.bs.js + style/index.scss`);
|
||||
|
||||
if (!IS_PRODUCTION) {
|
||||
if (!IS_PRODUCTION && !BUILD_ONLY) {
|
||||
app.hmr({ reload: true }).watch();
|
||||
}
|
||||
|
||||
|
|
3
mix.exs
3
mix.exs
|
@ -28,7 +28,8 @@ defmodule Mebe2.MixProject do
|
|||
{:calendar, "~> 0.17.4"},
|
||||
{:ex2ms, "~> 1.5.0"},
|
||||
{:mbu, "~> 3.0.0", runtime: false},
|
||||
{:exsync, "~> 0.2.3", only: :dev}
|
||||
{:exsync, "~> 0.2.3", only: :dev},
|
||||
{:distillery, "~> 2.0"}
|
||||
]
|
||||
end
|
||||
end
|
||||
|
|
2
mix.lock
2
mix.lock
|
@ -1,10 +1,12 @@
|
|||
%{
|
||||
"ace": {:hex, :ace, "0.17.1", "89c6d0940151f194f6572cfeb0e62295d14f344f90f01eeb625dd2b60ab7cd79", [:mix], [{:hpack, "~> 0.2.3", [hex: :hpack_erl, repo: "hexpm", optional: false]}, {:raxx, "~> 0.16.0", [hex: :raxx, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"artificery": {:hex, :artificery, "0.2.6", "f602909757263f7897130cbd006b0e40514a541b148d366ad65b89236b93497a", [:mix], [], "hexpm"},
|
||||
"calendar": {:hex, :calendar, "0.17.4", "22c5e8d98a4db9494396e5727108dffb820ee0d18fed4b0aa8ab76e4f5bc32f1", [:mix], [{:tzdata, "~> 0.5.8 or ~> 0.1.201603", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"certifi": {:hex, :certifi, "2.3.1", "d0f424232390bf47d82da8478022301c561cf6445b5b5fb6a84d49a9e76d2639", [:rebar3], [{:parse_trans, "3.2.0", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"cookie": {:hex, :cookie, "0.1.1", "89438362ee0f0ed400e9f076d617d630f82d682e3fbcf767072a46a6e1ed5781", [:mix], [], "hexpm"},
|
||||
"cowboy": {:hex, :cowboy, "2.4.0", "f1b72fabe9c8a5fc64ac5ac85fb65474d64733d1df52a26fad5d4ba3d9f70a9f", [:rebar3], [{:cowlib, "~> 2.3.0", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "~> 1.5.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"cowlib": {:hex, :cowlib, "2.3.0", "bbd58ef537904e4f7c1dd62e6aa8bc831c8183ce4efa9bd1150164fe15be4caa", [:rebar3], [], "hexpm"},
|
||||
"distillery": {:hex, :distillery, "2.0.11", "9259399cb64c88e2df6bbaef29e09b0a81d16d0155203ebf65c6be7b95f7b744", [:mix], [{:artificery, "~> 0.2", [hex: :artificery, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"earmark": {:hex, :earmark, "1.2.6", "b6da42b3831458d3ecc57314dff3051b080b9b2be88c2e5aa41cd642a5b044ed", [:mix], [], "hexpm"},
|
||||
"eex_html": {:hex, :eex_html, "0.1.1", "df7ad68245068d5fea0dab2a38e5afdc386ec00a5b6445eac6402ed7aa6a2b12", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
|
||||
"ex2ms": {:hex, :ex2ms, "1.5.0", "19e27f9212be9a96093fed8cdfbef0a2b56c21237196d26760f11dfcfae58e97", [:mix], [], "hexpm"},
|
||||
|
|
69
rel/config.exs
Normal file
69
rel/config.exs
Normal file
|
@ -0,0 +1,69 @@
|
|||
# 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 Mix.Releases.Config,
|
||||
# This sets the default release built by `mix release`
|
||||
default_release: :default,
|
||||
# This sets the default environment used by `mix 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: :"k(2`m4yq3i$1?0<[)TwNJEVE/Qy.KA&3rl=2C}g7d0bCVx93s^7r5Y%_.&:m,%JX")
|
||||
end
|
||||
|
||||
environment :prod do
|
||||
plugin(Mebe2.ReleasePlugins.BuildStatics)
|
||||
set(include_erts: true)
|
||||
set(include_src: false)
|
||||
set(cookie: System.get_env("COOKIE") |> String.to_atom())
|
||||
set(vm_args: "rel/vm.args")
|
||||
|
||||
set(
|
||||
config_providers: [
|
||||
{Mix.Releases.Config.Providers.Elixir, ["${RELEASE_ROOT_DIR}/etc/config.exs"]}
|
||||
]
|
||||
)
|
||||
|
||||
set(
|
||||
overlays: [
|
||||
{:copy, "rel/config/config.exs", "etc/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 release`, the first release in the file
|
||||
# will be used by default
|
||||
|
||||
release :mebe_2 do
|
||||
set(version: current_version(:mebe_2))
|
||||
|
||||
set(
|
||||
applications: [
|
||||
:runtime_tools
|
||||
]
|
||||
)
|
||||
end
|
12
rel/config/config.exs
Normal file
12
rel/config/config.exs
Normal file
|
@ -0,0 +1,12 @@
|
|||
use Mix.Config
|
||||
|
||||
# This file is used for configuring the Mebe2 release after release generation time. You can
|
||||
# override settings that were set during release compilation time using this file by copying the
|
||||
# settings over and setting a new value for them.
|
||||
|
||||
# Example:
|
||||
# config :mebe_2,
|
||||
# data_path: "/foo/bar"
|
||||
|
||||
# Note: Some settings can be also configured by using environment variables. The values from env
|
||||
# vars will overwrite the values set here.
|
3
rel/plugins/.gitignore
vendored
Normal file
3
rel/plugins/.gitignore
vendored
Normal file
|
@ -0,0 +1,3 @@
|
|||
*.*
|
||||
!*.exs
|
||||
!.gitignore
|
23
rel/plugins/build_statics.exs
Normal file
23
rel/plugins/build_statics.exs
Normal file
|
@ -0,0 +1,23 @@
|
|||
defmodule Mebe2.ReleasePlugins.BuildStatics do
|
||||
use Mix.Releases.Plugin
|
||||
|
||||
@moduledoc """
|
||||
Distillery plugin for generating static files (i.e. the frontend) before building the release.
|
||||
"""
|
||||
|
||||
def before_assembly(release, _opts) do
|
||||
info("Building static assets for release")
|
||||
|
||||
# Minify assets if generating prod release
|
||||
if Mix.env() == :prod do
|
||||
System.put_env("NODE_ENV", "production")
|
||||
end
|
||||
|
||||
Mix.Task.run("mebe.build.frontend")
|
||||
release
|
||||
end
|
||||
|
||||
def after_assembly(release, _opts), do: release
|
||||
def before_package(release, _opts), do: release
|
||||
def after_package(release, _opts), do: release
|
||||
end
|
30
rel/vm.args
Normal file
30
rel/vm.args
Normal file
|
@ -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 <%= System.get_env("NODENAME") || release_name %>@127.0.0.1
|
||||
|
||||
## Cookie for distributed erlang
|
||||
-setcookie <%= System.get_env("COOKIE") || 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
|
Reference in a new issue