Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Enable MIX_ENV=prod mix release to be run locally #1386

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ ae_mdw-*.tar
.DS_Store
.elixir_ls/
log/
AEMDW_REVISION
REVISION
VERSION
*~
Expand Down
1 change: 0 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ COPY ./docker/aeternity.yaml /home/aeternity/aeternity.yaml
# Set build git revision
RUN mkdir /home/aeternity/node/ae_mdw
COPY .git .git
RUN BUILD_REV="$(git log -1 --format=%h)" && echo $BUILD_REV > /home/aeternity/node/ae_mdw/AEMDW_REVISION

WORKDIR /home/aeternity/node

Expand Down
4 changes: 3 additions & 1 deletion config/prod.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Config

config :ae_mdw, build_revision: String.trim(File.read!("AEMDW_REVISION"))
# Stat
{revision, 0} = System.cmd("git", ["log", "-1", "--format=%h"])
config :ae_mdw, build_revision: String.trim(revision)

# Logging
config :logger,
Expand Down
61 changes: 60 additions & 1 deletion mix.exs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
defmodule AeMdw.MixProject do
use Mix.Project

@version "1.48.1"

def project() do
[
app: :ae_mdw,
version: "1.48.1",
version: @version,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is automatically handled by release please task on the pipeline.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I switched to @Version because it's now used twice in the file. Will the release please task find and replace multiple instances? Will it replace the new one?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather just leave it for the CI to manage it as it has been doing or it would need to be validated in advance.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will the CI replace both places "1.48.1" will be hard coded if I remove this change to use a module attribute? The two places are here, and on line 123 of this file?

I can hard code 1.48.1 in both places, but it seems like a much worse solution, would quite likely break the CI anyway.

Copy link
Member

@jyeshe jyeshe Aug 24, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tried it before but I think it's unlikely that it replaces in both places. One way to avoid the conflict is to pipe the list and append the releases.

elixir: "~> 1.10",
elixirc_paths: elixirc_paths(Mix.env()),
elixirc_options: [
Expand Down Expand Up @@ -109,6 +111,20 @@ defmodule AeMdw.MixProject do
coveralls: :test,
"test.integration": :test,
"test.iteration": :test
],
releases: [
ae_mdw: fn ->
if is_nil(System.get_env("INCLUDE_LOCAL_NODE")) do
[]
else
[
steps: [&build_node/1, &copy_node/1, :assemble, :tar, &remove_node/1],
overlays: ["node-tmp"],
version: "v" <> @version <> "-" <> to_string(:erlang.system_info(:system_architecture))
]
end

end
]
]
end
Expand Down Expand Up @@ -184,4 +200,47 @@ defmodule AeMdw.MixProject do
]
]
end

defp build_node(release) do
node_path = node_build_root()
IO.inspect(node_path, label: "Building node in directory")
{_, 0} = System.cmd("make", ["prod-package"], cd: node_path)
release
end

defp copy_node(release) do
tar_file = node_tar_file()
File.rm_rf("node-tmp")
File.mkdir_p("node-tmp/local/rel/aeternity/data/mnesia")
IO.inspect(tar_file, label: "Using aeternity release")
:erl_tar.extract(tar_file, [:compressed, {:cwd, "node-tmp/local/rel/aeternity"}])
release
end

defp remove_node(release) do
File.rm_rf("node-tmp")
release
end

defp node_build_root() do
System.get_env("NODE_BUILD_ROOT", "../aeternity/")
end

defp node_tar_file() do
reldir = Path.join(node_build_root(), "_build/prod/rel/aeternity")
files = File.ls!(reldir)
tar_file = latest_tar_file(files, reldir)
Path.join(reldir, tar_file)
end

defp latest_tar_file(files, reldir) do
files
|> Enum.filter(fn file -> String.ends_with?(file, ".tar.gz") end)
|> Enum.filter(fn file -> String.starts_with?(file, "aeternity") end)
|> Enum.map(fn file -> {file, File.lstat!(Path.join(reldir, file))} end)
|> Enum.sort(fn {_, f1}, {_, f2} -> f1.ctime > f2.ctime end)
|> Enum.map(fn {file, _} -> file end)
|> List.first()
end

end
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%{
"ae_plugin": {:git, "https://github.com/aeternity/ae_plugin.git", "f5438d957d871f6a32b10a2be8f6e7c4d3550534", []},
"ae_plugin": {:git, "https://github.com/aeternity/ae_plugin.git", "49c6541dbd6c82f0ce00718c288077823661986f", []},
"benchee": {:hex, :benchee, "1.0.1", "66b211f9bfd84bd97e6d1beaddf8fc2312aaabe192f776e8931cb0c16f53a521", [:mix], [{:deep_merge, "~> 1.0", [hex: :deep_merge, repo: "hexpm", optional: false]}], "hexpm", "3ad58ae787e9c7c94dd7ceda3b587ec2c64604563e049b2a0e8baafae832addb"},
"blankable": {:hex, :blankable, "1.0.0", "89ab564a63c55af117e115144e3b3b57eb53ad43ba0f15553357eb283e0ed425", [:mix], [], "hexpm", "7cf11aac0e44f4eedbee0c15c1d37d94c090cb72a8d9fddf9f7aec30f9278899"},
"bunt": {:hex, :bunt, "0.2.1", "e2d4792f7bc0ced7583ab54922808919518d0e57ee162901a16a1b6664ef3b14", [:mix], [], "hexpm", "a330bfb4245239787b15005e66ae6845c9cd524a288f0d141c148b02603777a5"},
Expand Down