How to use sync properly with application built using relx release assembler?

1.1k views Asked by At

I would like to use Sync on-the-fly recompiling with Cowboy project assembled using relx (as per Cowboy Getting Started Guide).

The problem is that even if I manage to get Sync starting in my application by mentioning sync in applications list in my_application.app.src file like this:

{application, my_application, [
    {description, "My Cowboy Application"},
    {vsn, "0.1.0"},
    {modules, []},
    {registered, [my_app_sup]},
    {applications, [
        kernel,
        stdlib,
        cowboy,
        sync
    ]},
    {mod, {my_app, []}},
    {env, []}
]}.`

I still can't get it working because of relx assembler does not move my source code to _rel directory (of course, it shouldn't).

Is there any way to tell Sync where my source files are located? Or may be I'm totally wrong and Sync integration with relx must be done in some other way?

2

There are 2 answers

0
nu-ex On BEST ANSWER

My development setup with sync consists of:

  • Installing sync to my exported ERL_LIBS path (i.e. $HOME/lib/erlang)
  • Creating a development relx config and executing it with relx -c relx-dev.config
  • Creating a simple shell script to cd into where the console script lives and execute it
  • Adding a config script to tweak my growl notifications

When developing, I include sync in my development relx.config file. However, once I install sync in a directory and export it to ERL_LIBS, it magically appears when I start the sync app in any of my erlang projects.

Here is an example of my development relx-dev.config file:

{dev_mode, true}.
{lib_dirs, ["/usr/local/erlang"]}.
{output_dir, "_rel-dev"}.
{release,
 {myapp, "0.0.1"},
 [{myapp_core, "0.0.1", '='}, sasl, syntax_tools, compiler, sync]
}.
{extended_start_script, true}.

Once the relx-dev.config script is created, I build the release with this command:

relx -c relx-dev.config

Here is the console script I use to start the console:

#!/usr/bin/sh
_rel-dev/myapp/bin/myapp console

This script will start an erlang shell with a node name, start all of my apps and the the sync application and load a custom sync config file.

Here is an example sync.config file placed in the same directory where you started the shell:

[{sync, [{growl, [errors, warnings]}]}].

The sync README has lots of info about configuring logging behavior for the console and growl. Alternatives to using a .config file include passing options to the erl command and executing sync functions in the shell.

0
Chris On

If I understand your question correctly what you want to do is just run your app via relx and have Scan pick up any changes you made to the source. If so here is what you do.

When you run the relx command add a -d option.

./relx -d true

what this says is relx will symlink all your dependences instead of copying them over. This makes the package process faster as well. From there just run your app in the _rel folder (or where ever you have it output to) and "sync" away.

A couple of notes:

1) If you don't want to symlink ALL the dependences you can use the overrides feature. However I am lazy and do an all or nothing kind of approach :)

2) In your relx.config file make sure you include the "compiler" and syntax_tools as dependencies or scan will crash each time you edit a file :(

Here is a copy of my relx.config if it helps

{paths, ["apps", "deps"]}.
{lib_dirs, ["/usr/local/lib/erlang/lib", "apps", "deps"]}.
{sys_config, "./config/sys.config"}.
{release, {merigo_chat, "1.0.0"}, [
kernel,
stdlib,
syntax_tools,
compiler,
sync,
{mySampleApp, "1.0.0"},

% Debugging applications,  Need to run observer and debugger from within the package
tools,
wx,
observer,
runtime_tools,
webtool,
appmon,
debugger
]}.

% Not you can skip the overrides if you use the -d option in relx
{overrides, [
{mySampleApp, "apps/mySampleApp"},
]}.
{extended_start_script, true}.