From a0db030880d93bcdaf43f6459fa5950b49133c62 Mon Sep 17 00:00:00 2001
From: Muhammad Rafif Elfazri <rafif.elfazri@gmail.com>
Date: Sat, 20 Feb 2021 09:28:21 +0700
Subject: [PATCH 1/3] Add GUARDIAN_SECRET_KEY_BASE variables for production

---
 config/docker.env   |  1 +
 config/releases.exs | 12 ++++++++++++
 2 files changed, 13 insertions(+)

diff --git a/config/docker.env b/config/docker.env
index 7bc4769..86d0150 100644
--- a/config/docker.env
+++ b/config/docker.env
@@ -1,4 +1,5 @@
 SECRET_KEY_BASE=REALLY_LONG_SECRET
+GUARDIAN_SECRET_KEY_BASE=REALLY_LONG_SECRET
 DATABASE_HOST=db
 DATABASE_URL=ecto://postgres:postgres@db/postgres
 PORT=4000
diff --git a/config/releases.exs b/config/releases.exs
index 7716ea2..9b865a8 100644
--- a/config/releases.exs
+++ b/config/releases.exs
@@ -23,6 +23,13 @@ secret_key_base =
     You can generate one by calling: mix phx.gen.secret
     """
 
+guardian_secret_key_base =
+System.get_env("GUARDIAN_SECRET_KEY_BASE") ||
+  raise """
+  environment variable GUARDIAN_SECRET_KEY_BASE is missing.
+  You can generate one by calling: mix guardian.gen.secret
+  """
+
 config :diskuy, DiskuyWeb.Endpoint,
   http: [
     port: String.to_integer(System.get_env("PORT") || "4000"),
@@ -30,6 +37,11 @@ config :diskuy, DiskuyWeb.Endpoint,
   ],
   secret_key_base: secret_key_base
 
+
+config :diskuy, DiskuyWeb.Auth.Guardian,
+  issuer: "diskuy",
+  secret_key: guardian_secret_key_base
+
 # ## Using releases (Elixir v1.9+)
 #
 # If you are doing OTP releases, you need to instruct Phoenix
-- 
GitLab


From 657471d7e090ce8210e32db849dbb421a80195aa Mon Sep 17 00:00:00 2001
From: Muhammad Rafif Elfazri <rafif.elfazri@gmail.com>
Date: Sat, 20 Feb 2021 09:31:18 +0700
Subject: [PATCH 2/3] Add alphabetical ordering for topics API

---
 lib/diskuy/forum.ex | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/lib/diskuy/forum.ex b/lib/diskuy/forum.ex
index 8fe2bd2..5944ca7 100644
--- a/lib/diskuy/forum.ex
+++ b/lib/diskuy/forum.ex
@@ -18,7 +18,8 @@ defmodule Diskuy.Forum do
 
   """
   def list_topics do
-    Repo.all(Topic)
+    query = from t in Topic, order_by: t.name
+    Repo.all(query)
   end
 
   @doc """
-- 
GitLab


From 10c6f336457d31e4163f72ed208fb26d18057356 Mon Sep 17 00:00:00 2001
From: Muhammad Rafif Elfazri <rafif.elfazri@gmail.com>
Date: Sat, 20 Feb 2021 09:46:29 +0700
Subject: [PATCH 3/3] Update deploy script with waiting for database server to
 start

---
 entrypoint.sh | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/entrypoint.sh b/entrypoint.sh
index b796fa0..71d524f 100644
--- a/entrypoint.sh
+++ b/entrypoint.sh
@@ -3,14 +3,14 @@
 # docker entrypoint script.
 
 # assign a default for the database_user
-# DB_USER=${DATABASE_USER:-postgres}
+DB_USER=${DATABASE_USER:-postgres}
 
-# # wait until Postgres is ready
-# while ! pg_isready -q -h $DATABASE_HOST -p 5432 -U $DB_USER
-# do
-#   echo "$(date) - waiting for database to start"
-#   sleep 2
-# done
+# wait until Postgres is ready
+while ! pg_isready -q -h $DATABASE_HOST -p 5432 -U $DB_USER
+do
+  echo "$(date) - waiting for database to start"
+  sleep 2
+done
 
 bin="/app/bin/diskuy"
 eval "$bin eval \"Diskuy.Release.migrate\""
-- 
GitLab