레이블이 rebar인 게시물을 표시합니다. 모든 게시물 표시
레이블이 rebar인 게시물을 표시합니다. 모든 게시물 표시

2017년 6월 21일 수요일

Erlang - Getting Started using rebar3,cowboy in MacOSX


brew doctor

brew update

brew upgrade

brew install openssl

curl -O https://raw.githubusercontent.com/kerl/kerl/master/kerl && chmod a+x kerl

export KERL_BUILD_BACKEND=git

export OTP_GITHUB_URL="https://github.com/basho/otp"

kerl list releases

kerl update releases

KERL_CONFIGURE_OPTIONS="--disable-hipe --enable-smp-support --enable-threads
                        --enable-kernel-poll --with-ssl=/usr/local/opt/openssl --without-odbc --enable-darwin-64bit" kerl build 19.2 19.2

kerl install 19.2 ~/erlang/19.2

. ~/erlang/19.2/activate

erl -version

wget https://s3.amazonaws.com/rebar3/rebar3 && chmod +x rebar3

./rebar3 local install

rebar3 new release cowboy_hello_world 

cd cowboy_hello_world/

vi rebar.config 

{deps, [
        {cowboy, {git, "https://github.com/ninenines/cowboy", {tag, "2.0.0-pre.1"}}}
]}.

{plugins, [rebar3_run]}.


Add cowboy to the list {application, [{applications, [kernel, stdlib, cowboy]}]}

 vi apps/cowboy_hello_world/src/cowboy_hello_world.app.src 

vi apps/cowboy_hello_world/src/cowboy_hello_world_app.erl 

start(_StartType, _StartArgs) ->
    {ok, Pid} = 'cowboy_hello_world_sup':start_link(),
    Routes = [ {
        '_',
        [
            {"/", cowboy_hello_world_root, []}
        ]
    } ],
    Dispatch = cowboy_router:compile(Routes),

    NumAcceptors = 10,
    TransOpts = [ {ip, {0,0,0,0}}, {port, 2938} ],
    ProtoOpts = [{env, [{dispatch, Dispatch}]}],

    {ok, _} = cowboy:start_http(chicken_poo_poo,
        NumAcceptors, TransOpts, ProtoOpts),

    {ok, Pid}.

vi apps/cowboy_hello_world/src/cowboy_hello_world_root.erl

-module(cowboy_hello_world_root).

-export([init/2]).

init(Req, Opts) ->
    Req2 = cowboy_req:reply(200,
        [{<<"content-type">>, <<"text/plain">>}],
        <<"Hello Erlang!">>,
        Req),
    {ok, Req2, Opts}.

rebar3 run

curl http://localhost:2938




Buy me a coffeeBuy me a coffee

2012년 7월 5일 목요일

using rebar


Richard Jones 님이 정리한, rebar 사용법.
http://www.metabrew.com/article/erlang-rebar-tutorial-generating-releases-upgrades

이건 2010년도에 Belo Horizonte님이 정리한 사용법
http://alancastro.org/2010/05/01/erlang-application-management-with-rebar.html

그런데, outdated된 내용도 있고, 그대로 딱 되지는 않는다.

당장 필요한 것만 정리하면 다음과 같다.

1. rebar를 다운로드 받는다.
https://github.com/basho/rebar

2. 프로젝트 루트 디렉토리를 만든다. 그리고 rebar를 copy한다.
#> mkdir proj_home
#> cd proj_home

3.  proj_home/apps/mysample/src 로 프로젝트를 만든다.
디렉토리 구조는, https://github.com/RJ/erlang_rebar_example_project/tree/v1 이것을 참조하면 된다.

src 폴더에서,
#> rebar create-app appid=mysample
로 소스를 생성한다.

mysample_app.erl 을 mysample.erl로 mv하고, start/0 함수를 추가한다.

다음을 rebar.config에 추가한다.


{sub_dirs, [
            "apps/mysample",
            "rel"
           ]}.


그리고, 추가 소스를 넣고, 동작이 되게 하고, 컴파일한다.
#> ./rebar compile

4. release버젼을 만들어 본다.

#> mkdir rel
#> cd rel
#> ../rebar create-node nodeid=mysample

=> rel.config를 수정한다.
https://github.com/RJ/erlang_rebar_example_project/blob/v1/rel/reltool.config
{lib_dirs, ["../apps"]},

{rel, "dummy", "1",
        [
         kernel,
         stdlib,
         sasl,
         dummy_app
        ]},

이 부분을 수정하면 된다.

#> cd ..
#> ./rebar generate

5. 확인한다.
#> bin/mysample 치면 console,start,stop,attach,ping 등을 해 볼 수 있다.