Skeleton for the storage bootstrap.
We want to automate this, for example, when deploying in a docker container. A bunch of static files will be loaded into the storage, in order to be served to the clients.main
parent
65d6e5fa05
commit
3280596836
|
@ -25,7 +25,17 @@ start(_Type, StartArgs) ->
|
||||||
end,
|
end,
|
||||||
|
|
||||||
{ok, Port} = application:get_env(port),
|
{ok, Port} = application:get_env(port),
|
||||||
{ok, Bucket} = application:get_env(bucket),
|
|
||||||
|
Bucket = case application:get_env(bucket) of
|
||||||
|
{ok, V} -> V;
|
||||||
|
false -> dudeswave
|
||||||
|
end,
|
||||||
|
|
||||||
|
ok = case storage:create(Bucket) of
|
||||||
|
ok -> bootstrap(Bucket);
|
||||||
|
{error, {already_exists, Bucket, _}} -> ok;
|
||||||
|
_ -> exit(storage_bootstrap_failed)
|
||||||
|
end,
|
||||||
|
|
||||||
Dispatch = cowboy_router:compile([
|
Dispatch = cowboy_router:compile([
|
||||||
{'_', [{"/", dudeswave_handler, #{bucket => Bucket}}]}
|
{'_', [{"/", dudeswave_handler, #{bucket => Bucket}}]}
|
||||||
|
@ -41,4 +51,9 @@ start(_Type, StartArgs) ->
|
||||||
dudeswave_supervisor:start_link(StartArgs).
|
dudeswave_supervisor:start_link(StartArgs).
|
||||||
|
|
||||||
stop(_State) ->
|
stop(_State) ->
|
||||||
cowboy:stop_listener(dudeswave_listener).
|
cowboy:stop_listener(dudeswave_listener).
|
||||||
|
|
||||||
|
%
|
||||||
|
% Bootstrap procedure to be completed
|
||||||
|
%
|
||||||
|
bootstrap(_Bucket) -> ok.
|
||||||
|
|
Loading…
Reference in New Issue