Skip to content

Commit

Permalink
Ability to generate secret key with "docker run image_name gen_sessio…
Browse files Browse the repository at this point in the history
…n_key"
  • Loading branch information
ruslansavenok committed Oct 8, 2019
1 parent cf713cd commit 9e4e280
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
5 changes: 4 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,7 @@ ENV APP_NAME=lib_ten
ENV APP_VERSION=0.0.1
ENV PORT 80

CMD /app/bin/lib_ten foreground
VOLUME /app/uploads

ENTRYPOINT ["/app/bin/lib_ten"]
CMD ["foreground"]
12 changes: 12 additions & 0 deletions lib/lib_ten/release_tasks.ex
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,18 @@ defmodule LibTen.ReleaseTasks do
stop_services()
end

def gen_random_key(key_length) do
:crypto.strong_rand_bytes(key_length)
|> Base.encode64
|> binary_part(0, key_length)
end

def print_random_key(length) do
{key_length, _} = Integer.parse(length)
gen_random_key(key_length)
|> IO.puts
end

defp start_services do
IO.puts("Loading #{@app}..")
Application.load(@app)
Expand Down
3 changes: 3 additions & 0 deletions rel/commands/gen_session_key.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

release_ctl eval --mfa "LibTen.ReleaseTasks.print_random_key/1" -- "64"
10 changes: 4 additions & 6 deletions rel/config.exs
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@ environment :prod do
end

release :lib_ten do
random_cookie_length = 128
random_cookie =
:crypto.strong_rand_bytes(random_cookie_length)
|> Base.encode64
|> binary_part(0, random_cookie_length)
set commands: [
gen_session_key: "rel/commands/gen_session_key.sh"
]

# NOTE:
# Ideally we don't want to have any cookie here, so one will
Expand All @@ -39,6 +37,6 @@ release :lib_ten do
# https://github.com/bitwalker/distillery/issues/428
#
# 😢
set cookie: random_cookie
set cookie: LibTen.ReleaseTasks.gen_random_key(128)
set version: current_version(:lib_ten)
end

0 comments on commit 9e4e280

Please sign in to comment.