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
absc 2024-07-23 23:15:36 +02:00
parent 65d6e5fa05
commit 3280596836
1 changed files with 17 additions and 2 deletions

View File

@ -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}}]}
@ -42,3 +52,8 @@ start(_Type, StartArgs) ->
stop(_State) -> stop(_State) ->
cowboy:stop_listener(dudeswave_listener). cowboy:stop_listener(dudeswave_listener).
%
% Bootstrap procedure to be completed
%
bootstrap(_Bucket) -> ok.