Skip to content

Instantly share code, notes, and snippets.

@aabs
Created January 8, 2018 00:39
Show Gist options
  • Save aabs/45518ff1c30b51bdf9dca428136e0f56 to your computer and use it in GitHub Desktop.
Save aabs/45518ff1c30b51bdf9dca428136e0f56 to your computer and use it in GitHub Desktop.
Creating an Erlang/OTP System w/ Rebar 3 + Emacs/EDTS

Setting up a new project

Just me keeping track of what I did to get my Erlang CLI dev env working OK

Context

This is built using Windows 10

Required Tooling

  • Windows 10 Fall Creators Edition
  • Linux Subsystem for Windows + Ubuntu Xenial
  • Rebar3
  • Susan Potter's Rebar3 templates
  • Erlang/OTP v20+
  • Emacs 24.5+
  • Erlang Mode
  • EDTS

Steps

  1. Setup initial project structure

    > rebar3.exe new release mysystem
    
    ===> Writing mysystem/apps/mysystem/src/mysystem_app.erl
    ===> Writing mysystem/apps/mysystem/src/mysystem_sup.erl
    ===> Writing mysystem/apps/mysystem/src/mysystem.app.src
    ===> Writing mysystem/rebar.config
    ===> Writing mysystem/config/sys.config
    ===> Writing mysystem/config/vm.args
    ===> Writing mysystem/.gitignore
    ===> Writing mysystem/LICENSE
    ===> Writing mysystem/README.md
    
    > tree
    .
    ├── mysystem
    │   ├── apps
    │   │   └── mysystem
    │   │       └── src
    │   │           ├── mysystem_app.erl
    │   │           ├── mysystem.app.src
    │   │           └── mysystem_sup.erl
    │   ├── config
    │   │   ├── sys.config
    │   │   └── vm.args
    │   ├── LICENSE
    │   ├── README.md
    │   └── rebar.config
    └── README.md
    
    5 directories, 9 files
  2. Compile the app

    > cd mysystem
    > rebar3.exe compile
    ===> Verifying dependencies...
    ===> Compiling mysystem
    
    > tree
    .
    ├── apps
    │   └── mysystem
    │       └── src
    │           ├── mysystem_app.erl
    │           ├── mysystem.app.src
    │           └── mysystem_sup.erl
    ├── _build
    │   └── default
    │       └── lib
    │           └── mysystem
    │               └── ebin
    │                   ├── mysystem.app
    │                   ├── mysystem_app.beam
    │                   └── mysystem_sup.beam
    ├── config
    │   ├── sys.config
    │   └── vm.args
    ├── LICENSE
    ├── README.md
    ├── rebar.config
    └── rebar.lock
  3. Create a release of the app

    > rebar3.exe release
    ===> Verifying dependencies...
    ===> Compiling mysystem
    ===> Starting relx build process ...
    ===> Resolving OTP Applications from directories:
              d:/ . . . /katas/kata1/mysystem/_build/default/lib
              d:/ . . . /katas/kata1/mysystem/apps
              c:/Program Files/erl9.1/lib
    ===> Resolved mysystem-0.1.0
    ===> Dev mode enabled, release will be symlinked
    ===> release successfully created!
    
    > tree
    .
    ├── apps
    │   └── mysystem
    │       └── src
    │           ├── mysystem_app.erl
    │           ├── mysystem.app.src
    │           └── mysystem_sup.erl
    ├── _build
    │   └── default
    │       ├── lib
    │       │   └── mysystem
    │       │       └── ebin
    │       │           ├── mysystem.app
    │       │           ├── mysystem_app.beam
    │       │           └── mysystem_sup.beam
    │       └── rel
    │           └── mysystem
    │               ├── bin
    │               │   ├── install_upgrade.escript
    │               │   ├── mysystem-0.1.0.cmd
    │               │   ├── mysystem.cmd
    │               │   ├── nodetool
    │               │   ├── no_dot_erlang.boot
    │               │   └── start_clean.boot
    │               ├── lib
    │               └── releases
    │                   ├── 0.1.0
    │                   │   ├── mysystem.boot
    │                   │   ├── mysystem.rel
    │                   │   ├── mysystem.script
    │                   │   ├── no_dot_erlang.boot
    │                   │   └── start_clean.boot
    │                   ├── RELEASES
    │                   └── start_erl.data
    ├── config
    │   ├── sys.config
    │   └── vm.args
    ├── LICENSE
    ├── README.md
    ├── rebar.config
    └── rebar.lock
  4. Create a release tarball

    > rebar3.exe as prod tar
    ===> Verifying dependencies...
    ===> Compiling mysystem
    ===> Starting relx build process ...
    ===> Resolving OTP Applications from directories:
              d:/ . . . /katas/kata1/mysystem/_build/prod/lib
              d:/ . . . /katas/kata1/mysystem/apps
              c:/Program Files/erl9.1/lib
    ===> Resolved mysystem-0.1.0
    ===> Including Erts from c:/Program Files/erl9.1
    ===> release successfully created!
    ===> Starting relx build process ...
    ===> Resolving OTP Applications from directories:
              d:/ . . . /katas/kata1/mysystem/_build/prod/lib
              d:/ . . . /katas/kata1/mysystem/apps
              c:/Program Files/erl9.1/lib
              d:/ . . . /katas/kata1/mysystem/_build/prod/rel
    ===> Resolved mysystem-0.1.0
    ===> tarball d:/ . . . /katas/kata1/mysystem/_build/prod/rel/mysystem/mysystem-0.1.0.tar.gz successfully created!
  5. Introduce the Hex package manager

    {plugins, [rebar3_hex]}.
  6. Update to pull down Hex

    > rebar3.exe update
    
    ===> Package <<"rebar3_hex">> not found. Fetching registry updates and trying again...
    ===> Updating package registry...
    ===> Writing registry to c:/Users/aabs/.cache/rebar3/hex/default/registry
    ===> Generating package index...
    ===> Writing index to c:/Users/aabs/.cache/rebar3/hex/default/packages.idx
    ===> Fetching rebar3_hex ({pkg,<<"rebar3_hex">>,<<"4.1.0">>})
    ===> Downloaded package, caching at c:/Users/aabs/.cache/rebar3/hex/default/packages/rebar3_hex-4.1.0.tar
    ===> Compiling rebar3_hex
    ===> Updating package registry...
    ===> Writing registry to c:/Users/aabs/.cache/rebar3/hex/default/registry
    ===> Generating package index...
    ===> Writing index to c:/Users/aabs/.cache/rebar3/hex/default/packages.idx```
    
  7. Create a gen_server for the app

    cd mysystem/apps/mysystem/src
    rebar3.exe new finsrv name="myservice"
  8. Create an eunit test fixture for the server

    rebar3.exe new eunit name="myservice"
  9. Hook up the service to the app's Supervisor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment