From 6928817ed8f0f80b3ee1c5941d33880b6f548df9 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Thu, 23 Nov 2023 16:52:13 +0800 Subject: [PATCH 01/16] refactor(filter): improve order in filter pack --- lib/groupher_server/cms/constant.ex | 6 +- .../cms/delegates/Seeds/posts.ex | 2 +- .../cms/delegates/community_crud.ex | 1 + .../schema/Helper/fields.ex | 3 + .../schema/cms/cms_metrics.ex | 4 +- lib/helper/query_builder.ex | 51 ++++++++++- priv/mock/post_seeds.exs | 17 +--- .../cms/paged_articles/paged_posts_test.exs | 91 ++++++++++++++++++- 8 files changed, 150 insertions(+), 25 deletions(-) diff --git a/lib/groupher_server/cms/constant.ex b/lib/groupher_server/cms/constant.ex index 01563fe..5fb4f82 100644 --- a/lib/groupher_server/cms/constant.ex +++ b/lib/groupher_server/cms/constant.ex @@ -30,9 +30,9 @@ defmodule GroupherServer.CMS.Constant do done: 4, # for question cat resolved: 5, - reject_dup: 6, - reject_no_plan: 7, - reject_no_fix: 8, + reject: 6, + reject_dup: 7, + reject_no_plan: 8, reject_repro: 9, reject_stale: 10 } diff --git a/lib/groupher_server/cms/delegates/Seeds/posts.ex b/lib/groupher_server/cms/delegates/Seeds/posts.ex index 51470ad..206ba4e 100644 --- a/lib/groupher_server/cms/delegates/Seeds/posts.ex +++ b/lib/groupher_server/cms/delegates/Seeds/posts.ex @@ -22,7 +22,7 @@ defmodule GroupherServer.CMS.Delegate.Seeds.Articles do def seed_articles(community_slug, thread) do with {:ok, community} <- ORM.find_by(Community, slug: community_slug), {:ok, user} <- ORM.find(User, 1) do - attrs = mock_attrs(thread, %{community_id: community.id}) + attrs = mock_attrs(thread, %{community_id: community.id, original_community: community}) CMS.create_article(community, thread, attrs, user) end end diff --git a/lib/groupher_server/cms/delegates/community_crud.ex b/lib/groupher_server/cms/delegates/community_crud.ex index 2061006..dfc6f4a 100644 --- a/lib/groupher_server/cms/delegates/community_crud.ex +++ b/lib/groupher_server/cms/delegates/community_crud.ex @@ -286,6 +286,7 @@ defmodule GroupherServer.CMS.Delegate.CommunityCRUD do thread, %{inner_id: inner_id} ) do + IO.inspect(inner_id, label: "## inner_id") thread_inner_id_key = :"#{plural(thread)}_inner_id_index" meta = community_meta |> Map.put(thread_inner_id_key, inner_id) |> strip_struct diff --git a/lib/groupher_server_web/schema/Helper/fields.ex b/lib/groupher_server_web/schema/Helper/fields.ex index 8991f85..d01d461 100644 --- a/lib/groupher_server_web/schema/Helper/fields.ex +++ b/lib/groupher_server_web/schema/Helper/fields.ex @@ -205,6 +205,9 @@ defmodule GroupherServerWeb.Schema.Helper.Fields do quote do field(:when, :when_enum) field(:article_tag, :string) + field(:cat, :string) + field(:state, :string) + field(:order, :string) field(:article_tags, list_of(:string)) field(:community, :string) end diff --git a/lib/groupher_server_web/schema/cms/cms_metrics.ex b/lib/groupher_server_web/schema/cms/cms_metrics.ex index 75eeff1..4617a5c 100644 --- a/lib/groupher_server_web/schema/cms/cms_metrics.ex +++ b/lib/groupher_server_web/schema/cms/cms_metrics.ex @@ -124,10 +124,10 @@ defmodule GroupherServerWeb.Schema.CMS.Metrics do value(:todo) value(:wip) value(:done) - value(:resolve) + value(:resolved) + value(:reject) value(:reject_dup) value(:reject_no_plan) - value(:reject_no_fix) value(:reject_repro) value(:reject_stale) end diff --git a/lib/helper/query_builder.ex b/lib/helper/query_builder.ex index e067c4d..e93c467 100644 --- a/lib/helper/query_builder.ex +++ b/lib/helper/query_builder.ex @@ -8,6 +8,9 @@ defmodule Helper.QueryBuilder do alias CMS.Constant + @article_cat Constant.article_cat() + @article_state Constant.article_state() + @audit_illegal Constant.pending(:illegal) @audit_failed Constant.pending(:audit_failed) @@ -59,8 +62,52 @@ defmodule Helper.QueryBuilder do |> order_by([_, s], {^direction, fragment("count(?)", s.id)}) end + defp trans_article_cat(queryable, cat) when is_binary(cat) do + cat_key = cat |> String.downcase() |> String.to_atom() + cat_value = @article_cat |> Map.get(cat_key) + + case cat_value do + ## -1 means not exist + nil -> queryable |> where([p], p.cat == -1) + _ -> queryable |> where([p], p.cat == ^cat_value) + end + end + + defp trans_article_state(queryable, state) when is_binary(state) do + state_key = state |> String.downcase() |> String.to_atom() + state_value = @article_state |> Map.get(state_key) + + case state_value do + ## -1 means not exist + nil -> queryable |> where([p], p.state == -1) + _ -> queryable |> where([p], p.state == ^state_value) + end + end + + defp trans_articles_order(queryable, "upvotes") do + queryable |> order_by(desc: :upvotes_count) + end + + defp trans_articles_order(queryable, "comments") do + queryable |> order_by(desc: :comments_count) + end + + defp trans_articles_order(queryable, "views") do + queryable |> order_by(desc: :views, desc: :inserted_at) + end + + defp trans_articles_order(queryable, "publish") do + queryable |> order_by(desc: :inserted_at) + end + + defp trans_articles_order(queryable, _), do: queryable + def filter_pack(queryable, filter) when is_map(filter) do Enum.reduce(filter, queryable, fn + {:order, key}, queryable -> + queryable |> trans_articles_order(key) + + # old {:sort, :desc_active}, queryable -> queryable |> order_by(desc: :active_at) @@ -174,10 +221,10 @@ defmodule Helper.QueryBuilder do queryable {:cat, cat}, queryable -> - queryable |> where([p], p.cat == ^cat) + queryable |> trans_article_cat(cat) {:state, state}, queryable -> - queryable |> where([p], p.state == ^state) + queryable |> trans_article_state(state) {:community_slug, community_slug}, queryable -> from( diff --git a/priv/mock/post_seeds.exs b/priv/mock/post_seeds.exs index 6f891d2..f9d274f 100644 --- a/priv/mock/post_seeds.exs +++ b/priv/mock/post_seeds.exs @@ -5,22 +5,7 @@ alias CMS.Model.{Post, ArticleTag} alias CMS.Constant alias Helper.ORM -# Enum.reduce(1..10, [], fn _, _ -> - # {:ok, post} = Seeds.Articles.seed_articles("home", :post) - - # {:ok, _} = CMS.set_post_cat(post, Constant.article_cat().feature) - # {:ok, _} = CMS.set_post_state(post, Constant.article_state().todo) - - # {:ok, doc} = Seeds.Articles.seed_articles("home", :doc) -# end) - -{:ok, post} = ORM.find(Post, 8) -{:ok, tag} = ORM.find(ArticleTag, 4) -{:ok, tag2} = ORM.find(ArticleTag, 5) - -IO.inspect post, label: "find post" -IO.inspect tag, label: "find tag" -IO.inspect tag2, label: "find tag2" +{:ok, post} = Seeds.Articles.seed_articles("home", :post) # {:ok, post} = CMS.set_article_tag(:post, post.id, tag.id) # {:ok, post} = CMS.set_article_tag(:post, post.id, tag2.id) diff --git a/test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs b/test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs index e8340dd..6ded210 100644 --- a/test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs +++ b/test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs @@ -32,6 +32,10 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedPosts do setup do {:ok, user} = db_insert(:user) + {:ok, user2} = db_insert(:user) + {:ok, user3} = db_insert(:user) + + {:ok, community} = db_insert(:community) {:ok, post_last_month} = db_insert(:post, %{title: "last month", inserted_at: @last_month}) @@ -45,7 +49,8 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedPosts do guest_conn = simu_conn(:guest) - {:ok, ~m(guest_conn user post_last_week post_last_month post_last_year)a} + {:ok, + ~m(guest_conn user user2 user3 post_last_week post_last_month post_last_year community)a} end describe "[query paged_posts filter pagination]" do @@ -56,6 +61,9 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedPosts do id cat state + views + upvotesCount + commentsCount document { bodyHtml } @@ -84,6 +92,61 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedPosts do assert results["entries"] |> List.first() |> Map.get("articleTags") |> is_list end + @tag :wip + test "publish order should work", ~m(guest_conn community user)a do + variables = %{filter: %{page: 1, size: 20, order: "publish"}} + + post_attrs = mock_attrs(:post, %{community_id: community.id}) + {:ok, post} = CMS.create_article(community, :post, post_attrs, user) + + results = guest_conn |> query_result(@query, variables, "pagedPosts") + first_post = results["entries"] |> List.first() + assert first_post["id"] > post.id + end + + @tag :wip + test "upvotes_count order should work", ~m(guest_conn post_last_week user user2 user3)a do + variables = %{filter: %{page: 1, size: 20, order: "upvotes"}} + + {:ok, _} = CMS.upvote_article(:post, post_last_week.id, user) + {:ok, _} = CMS.upvote_article(:post, post_last_week.id, user2) + {:ok, _} = CMS.upvote_article(:post, post_last_week.id, user3) + + results = guest_conn |> query_result(@query, variables, "pagedPosts") + first_post = results["entries"] |> List.first() + assert first_post["upvotesCount"] === 3 + end + + @tag :wip + test "comments_count order should work", ~m(guest_conn post_last_week user user2 user3)a do + variables = %{filter: %{page: 1, size: 20, order: "comments"}} + + {:ok, _comment} = CMS.create_comment(:post, post_last_week.id, mock_comment(), user) + {:ok, _comment} = CMS.create_comment(:post, post_last_week.id, mock_comment(), user2) + {:ok, _comment} = CMS.create_comment(:post, post_last_week.id, mock_comment(), user3) + + results = guest_conn |> query_result(@query, variables, "pagedPosts") + first_post = results["entries"] |> List.first() + assert first_post["commentsCount"] === 3 + end + + @tag :wip + test "views order should work", ~m(guest_conn community user user2 user3)a do + variables = %{filter: %{page: 1, size: 20, order: "views"}} + + post_attrs = mock_attrs(:post, %{community_id: community.id}) + {:ok, post} = CMS.create_article(community, :post, post_attrs, user) + + {:ok, _} = CMS.read_article(post.original_community_slug, :post, post.inner_id, user) + {:ok, _} = CMS.read_article(post.original_community_slug, :post, post.inner_id, user2) + {:ok, post} = CMS.read_article(post.original_community_slug, :post, post.inner_id, user3) + + results = guest_conn |> query_result(@query, variables, "pagedPosts") + first_post = results["entries"] |> List.first() + last_post = results["entries"] |> List.last() + assert first_post["views"] > last_post["views"] + end + test "should get valid cat & state", ~m(guest_conn post_last_week)a do variables = %{filter: %{page: 1, size: 20}} @@ -96,6 +159,32 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedPosts do assert results["entries"] |> Enum.any?(&(&1["state"] == "WIP")) end + @tag :wip + test "should get valid cat & state by filter", ~m(guest_conn post_last_week)a do + {:ok, _post} = CMS.set_post_cat(post_last_week, @article_cat.feature) + {:ok, _post} = CMS.set_post_state(post_last_week, @article_state.wip) + + variables = %{filter: %{page: 1, size: 20, cat: "feature"}} + results = guest_conn |> query_result(@query, variables, "pagedPosts") + assert results["totalCount"] == 1 + + variables = %{filter: %{page: 1, size: 20, cat: "not exist"}} + results = guest_conn |> query_result(@query, variables, "pagedPosts") + assert results["totalCount"] == 0 + + variables = %{filter: %{page: 1, size: 20, state: "wip"}} + results = guest_conn |> query_result(@query, variables, "pagedPosts") + assert results["totalCount"] == 1 + + variables = %{filter: %{page: 1, size: 20, state: "not exist"}} + results = guest_conn |> query_result(@query, variables, "pagedPosts") + assert results["totalCount"] == 0 + + variables = %{filter: %{page: 1, size: 20, cat: "feature", state: "wip"}} + results = guest_conn |> query_result(@query, variables, "pagedPosts") + assert results["totalCount"] == 1 + end + test "should get valid thread document", ~m(guest_conn)a do {:ok, user} = db_insert(:user) {:ok, community} = db_insert(:community) From df0bbb594970263960e8b3cab09e94b9f9be39a4 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Thu, 23 Nov 2023 16:53:03 +0800 Subject: [PATCH 02/16] chore: fmt --- lib/helper/query_builder.ex | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/helper/query_builder.ex b/lib/helper/query_builder.ex index e93c467..e9fec01 100644 --- a/lib/helper/query_builder.ex +++ b/lib/helper/query_builder.ex @@ -84,19 +84,19 @@ defmodule Helper.QueryBuilder do end end - defp trans_articles_order(queryable, "upvotes") do + defp trans_articles_order(queryable, "upvotes") do queryable |> order_by(desc: :upvotes_count) end - defp trans_articles_order(queryable, "comments") do + defp trans_articles_order(queryable, "comments") do queryable |> order_by(desc: :comments_count) end - defp trans_articles_order(queryable, "views") do - queryable |> order_by(desc: :views, desc: :inserted_at) + defp trans_articles_order(queryable, "views") do + queryable |> order_by(desc: :views, desc: :inserted_at) end - defp trans_articles_order(queryable, "publish") do + defp trans_articles_order(queryable, "publish") do queryable |> order_by(desc: :inserted_at) end From cd0c50151ad8897956a7c54abdf3925c2445a801 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Tue, 2 Jan 2024 16:41:38 +0800 Subject: [PATCH 03/16] chore: wip --- .../cms/delegates/community_crud.ex | 1 - .../cms/delegates/community_operation.ex | 9 +++++ .../cms/models/metrics/dashboard.ex | 6 +++- lib/helper/certification.ex | 10 +++--- lib/helper/converter/chinese_convention.ex | 4 +-- lib/helper/query_builder.ex | 13 ++++++- mix.exs | 3 -- test/groupher_server/cms/cms_test.exs | 34 +++++++++++++++++++ .../mutation/cms/crud_test.exs | 2 +- .../mutation/cms/dashboard_test.exs | 16 ++++++--- .../paged_kanban_posts_test.exs | 3 +- .../cms/paged_articles/paged_posts_test.exs | 5 --- 12 files changed, 82 insertions(+), 24 deletions(-) diff --git a/lib/groupher_server/cms/delegates/community_crud.ex b/lib/groupher_server/cms/delegates/community_crud.ex index dfc6f4a..2061006 100644 --- a/lib/groupher_server/cms/delegates/community_crud.ex +++ b/lib/groupher_server/cms/delegates/community_crud.ex @@ -286,7 +286,6 @@ defmodule GroupherServer.CMS.Delegate.CommunityCRUD do thread, %{inner_id: inner_id} ) do - IO.inspect(inner_id, label: "## inner_id") thread_inner_id_key = :"#{plural(thread)}_inner_id_index" meta = community_meta |> Map.put(thread_inner_id_key, inner_id) |> strip_struct diff --git a/lib/groupher_server/cms/delegates/community_operation.ex b/lib/groupher_server/cms/delegates/community_operation.ex index 511363e..b631017 100644 --- a/lib/groupher_server/cms/delegates/community_operation.ex +++ b/lib/groupher_server/cms/delegates/community_operation.ex @@ -71,6 +71,15 @@ defmodule GroupherServer.CMS.Delegate.CommunityOperation do end end + defp update_passport_item_count( + %CommunityModerator{role: "root"} = moderator, + _community_slug, + _user_id, + _rules + ) do + moderator |> ORM.update(%{passport_item_count: Certification.root_passport_item_count()}) + end + defp update_passport_item_count( %CommunityModerator{} = moderator, community_slug, diff --git a/lib/groupher_server/cms/models/metrics/dashboard.ex b/lib/groupher_server/cms/models/metrics/dashboard.ex index fbdd002..589c7d1 100644 --- a/lib/groupher_server/cms/models/metrics/dashboard.ex +++ b/lib/groupher_server/cms/models/metrics/dashboard.ex @@ -49,6 +49,7 @@ defmodule GroupherServer.CMS.Model.Metrics.Dashboard do [:primary_color, :string, ""], [:post_layout, :string, ""], [:kanban_layout, :string, ""], + [:kanban_card_layout, :string, ""], [:doc_layout, :string, ""], [:doc_faq_layout, :string, ""], [:tag_layout, :string, ""], @@ -69,7 +70,10 @@ defmodule GroupherServer.CMS.Model.Metrics.Dashboard do ## glow [:glow_type, :string, ""], [:glow_fixed, :boolean, false], - [:glow_opacity, :string, ""] + [:glow_opacity, :string, ""], + + ## blur + [:goss_blur, :integer, 100] ] end diff --git a/lib/helper/certification.ex b/lib/helper/certification.ex index 40cb290..407ebc7 100644 --- a/lib/helper/certification.ex +++ b/lib/helper/certification.ex @@ -26,16 +26,14 @@ defmodule Helper.Certification do "article_tag.unset" ] - def moderator_titles(:cms) do - ["root", "moderator"] - end + def root_passport_item_count(), do: 10000 def passport_rules(cms: "root") do %{ + "root.spec" => true, "post.article_tag.create" => true, "post.article_tag.edit" => true, "post.mark_delete" => true, - "root.spec" => true, "community.add_moderator" => true # todo ... } @@ -50,6 +48,10 @@ defmodule Helper.Certification do } end + def moderator_titles(:cms) do + ["root", "moderator"] + end + # a |> Enum.map(fn(x) -> {x, false} end) |> Map.new # %{ # cms: %{ diff --git a/lib/helper/converter/chinese_convention.ex b/lib/helper/converter/chinese_convention.ex index f7fb12f..b1bc3da 100644 --- a/lib/helper/converter/chinese_convention.ex +++ b/lib/helper/converter/chinese_convention.ex @@ -10,7 +10,7 @@ defmodule Helper.Converter.ChineseConvention do https://cn.wordpress.org/plugins/corner-bracket-lover/ """ - require Pangu + # require Pangu @doc """ format chinese stirng follows github: sparanoid/chinese-copywriting-guidelines. @@ -21,7 +21,7 @@ defmodule Helper.Converter.ChineseConvention do @spec format(binary) :: binary def format(text) do text - |> Pangu.spacing() + # |> Pangu.spacing() |> cover_brackets end diff --git a/lib/helper/query_builder.ex b/lib/helper/query_builder.ex index e9fec01..4d9e864 100644 --- a/lib/helper/query_builder.ex +++ b/lib/helper/query_builder.ex @@ -62,6 +62,10 @@ defmodule Helper.QueryBuilder do |> order_by([_, s], {^direction, fragment("count(?)", s.id)}) end + defp trans_article_cat(queryable, cat) when is_integer(cat) do + queryable |> where([p], p.cat == ^cat) + end + defp trans_article_cat(queryable, cat) when is_binary(cat) do cat_key = cat |> String.downcase() |> String.to_atom() cat_value = @article_cat |> Map.get(cat_key) @@ -73,6 +77,10 @@ defmodule Helper.QueryBuilder do end end + defp trans_article_state(queryable, state) when is_integer(state) do + queryable |> where([p], p.state == ^state) + end + defp trans_article_state(queryable, state) when is_binary(state) do state_key = state |> String.downcase() |> String.to_atom() state_value = @article_state |> Map.get(state_key) @@ -104,8 +112,11 @@ defmodule Helper.QueryBuilder do def filter_pack(queryable, filter) when is_map(filter) do Enum.reduce(filter, queryable, fn + {:order, nil}, queryable -> + queryable + {:order, key}, queryable -> - queryable |> trans_articles_order(key) + queryable |> trans_articles_order(String.downcase(key)) # old {:sort, :desc_active}, queryable -> diff --git a/mix.exs b/mix.exs index 5f9097a..43ebb4d 100644 --- a/mix.exs +++ b/mix.exs @@ -109,9 +109,6 @@ defmodule GroupherServer.Mixfile do {:html_sanitize_ex, "~> 1.3"}, {:open_graph, "~> 0.0.3"}, {:earmark, "~> 1.4.13"}, - # 遵循中文排版指南 - # https://github.com/cataska/pangu.ex - {:pangu, "~> 0.1.0"}, {:accessible, "~> 0.3.0"}, {:floki, "~> 0.30.1"}, {:httpoison, "~> 1.8"}, diff --git a/test/groupher_server/cms/cms_test.exs b/test/groupher_server/cms/cms_test.exs index 7d8f47e..baf5446 100644 --- a/test/groupher_server/cms/cms_test.exs +++ b/test/groupher_server/cms/cms_test.exs @@ -116,6 +116,40 @@ defmodule GroupherServer.Test.CMS do end describe "[cms community moderators]" do + test "should have infinite passport count of root", ~m(user user2 community)a do + role = "root" + cur_user = user + {:ok, _} = CMS.add_moderator(community.slug, role, user2, cur_user) + + {:ok, moderator} = + CommunityModerator |> ORM.find_by(%{community_id: community.id, user_id: user2.id}) + + assert moderator.passport_item_count == Certification.root_passport_item_count() + + default_passport_item_count = + Certification.passport_rules(cms: "moderator") |> Map.keys() |> length + + new_community_rules = + Certification.passport_rules(cms: "moderator") + |> Map.merge(%{ + "post.tag.edit2" => true, + "post.tag.edit3" => true, + "post.tag.edit4" => true + }) + + new_passport_rules = %{ + "#{community.slug}" => new_community_rules + } + + {:ok, _} = + CMS.update_moderator_passport(community.slug, new_passport_rules, user2, cur_user) + + {:ok, moderator} = + CommunityModerator |> ORM.find_by(%{community_id: community.id, user_id: user2.id}) + + assert moderator.passport_item_count == Certification.root_passport_item_count() + end + test "should have passport count of community after add moderator", ~m(user user2 community)a do role = "moderator" diff --git a/test/groupher_server_web/mutation/cms/crud_test.exs b/test/groupher_server_web/mutation/cms/crud_test.exs index fc35415..ca87454 100644 --- a/test/groupher_server_web/mutation/cms/crud_test.exs +++ b/test/groupher_server_web/mutation/cms/crud_test.exs @@ -540,7 +540,7 @@ defmodule GroupherServer.Test.Mutation.CMS.CRUD do } } """ - @tag :wip + test "auth user can update moderator to community", ~m(user user2 community)a do role = "moderator" cur_user = user diff --git a/test/groupher_server_web/mutation/cms/dashboard_test.exs b/test/groupher_server_web/mutation/cms/dashboard_test.exs index 110ab90..8c240e5 100644 --- a/test/groupher_server_web/mutation/cms/dashboard_test.exs +++ b/test/groupher_server_web/mutation/cms/dashboard_test.exs @@ -188,8 +188,8 @@ defmodule GroupherServer.Test.Mutation.CMS.Dashboard do end @update_layout_query """ - mutation($community: String!, $primaryColor: String $postLayout: String, $kanbanLayout: String, $footerLayout: String, $broadcastEnable: Boolean, $kanbanBgColors: [String], $glowType: String, $glowFixed: Boolean, $glowOpacity: String, $tagLayout: String) { - updateDashboardLayout(community: $community, primaryColor: $primaryColor, postLayout: $postLayout, kanbanLayout: $kanbanLayout, footerLayout: $footerLayout, broadcastEnable: $broadcastEnable, kanbanBgColors: $kanbanBgColors, glowType: $glowType, glowFixed: $glowFixed, glowOpacity: $glowOpacity, tagLayout: $tagLayout) { + mutation($community: String!, $primaryColor: String $postLayout: String, $kanbanLayout: String, $kanbanCardLayout: String, $footerLayout: String, $broadcastEnable: Boolean, $kanbanBgColors: [String], $glowType: String, $glowFixed: Boolean, $glowOpacity: String, $tagLayout: String, $gossBlur: Int) { + updateDashboardLayout(community: $community, primaryColor: $primaryColor, postLayout: $postLayout, kanbanLayout: $kanbanLayout, kanbanCardLayout: $kanbanCardLayout, footerLayout: $footerLayout, broadcastEnable: $broadcastEnable, kanbanBgColors: $kanbanBgColors, glowType: $glowType, glowFixed: $glowFixed, glowOpacity: $glowOpacity, tagLayout: $tagLayout, gossBlur: $gossBlur) { id title dashboard { @@ -199,11 +199,13 @@ defmodule GroupherServer.Test.Mutation.CMS.Dashboard do glowType glowFixed glowOpacity + gossBlur } } } } """ + @tag :wip test "update community dashboard layout info", ~m(community)a do rule_conn = simu_conn(:user, cms: %{"community.update" => true}) @@ -212,13 +214,15 @@ defmodule GroupherServer.Test.Mutation.CMS.Dashboard do primaryColor: "PURPLE", postLayout: "new layout", broadcastEnable: true, - kanbanLayout: "full", + kanbanLayout: "waterfall", + kanbanCardLayout: "full", footerLayout: "simple", kanbanBgColors: ["#111", "#222"], glowType: "PINK", glowFixed: true, glowOpacity: "30", - tagLayout: "dot" + tagLayout: "dot", + gossBlur: 80 } updated = @@ -229,7 +233,8 @@ defmodule GroupherServer.Test.Mutation.CMS.Dashboard do assert found.dashboard.layout.primary_color == "PURPLE" assert found.dashboard.layout.post_layout == "new layout" - assert found.dashboard.layout.kanban_layout == "full" + assert found.dashboard.layout.kanban_layout == "waterfall" + assert found.dashboard.layout.kanban_card_layout == "full" assert found.dashboard.layout.broadcast_enable == true assert found.dashboard.layout.kanban_bg_colors == ["#111", "#222"] assert found.dashboard.layout.footer_layout == "simple" @@ -238,6 +243,7 @@ defmodule GroupherServer.Test.Mutation.CMS.Dashboard do assert found.dashboard.layout.glow_fixed == true assert found.dashboard.layout.glow_opacity == "30" assert found.dashboard.layout.tag_layout == "dot" + assert found.dashboard.layout.goss_blur == 80 end test "update community dashboard layout should not overwrite existing settings", diff --git a/test/groupher_server_web/query/cms/paged_articles/paged_kanban_posts_test.exs b/test/groupher_server_web/query/cms/paged_articles/paged_kanban_posts_test.exs index fde97c4..b4f3a88 100644 --- a/test/groupher_server_web/query/cms/paged_articles/paged_kanban_posts_test.exs +++ b/test/groupher_server_web/query/cms/paged_articles/paged_kanban_posts_test.exs @@ -70,9 +70,10 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedKanbanPosts do } } """ - + @tag :wip test "should get grouped paged posts", ~m(guest_conn user community post_attrs)a do {:ok, post} = CMS.create_article(community, :post, post_attrs, user) + {:ok, _post} = CMS.set_post_cat(post, @article_cat.feature) {:ok, _post} = CMS.set_post_state(post, @article_state.todo) diff --git a/test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs b/test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs index 6ded210..0292288 100644 --- a/test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs +++ b/test/groupher_server_web/query/cms/paged_articles/paged_posts_test.exs @@ -92,7 +92,6 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedPosts do assert results["entries"] |> List.first() |> Map.get("articleTags") |> is_list end - @tag :wip test "publish order should work", ~m(guest_conn community user)a do variables = %{filter: %{page: 1, size: 20, order: "publish"}} @@ -104,7 +103,6 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedPosts do assert first_post["id"] > post.id end - @tag :wip test "upvotes_count order should work", ~m(guest_conn post_last_week user user2 user3)a do variables = %{filter: %{page: 1, size: 20, order: "upvotes"}} @@ -117,7 +115,6 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedPosts do assert first_post["upvotesCount"] === 3 end - @tag :wip test "comments_count order should work", ~m(guest_conn post_last_week user user2 user3)a do variables = %{filter: %{page: 1, size: 20, order: "comments"}} @@ -130,7 +127,6 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedPosts do assert first_post["commentsCount"] === 3 end - @tag :wip test "views order should work", ~m(guest_conn community user user2 user3)a do variables = %{filter: %{page: 1, size: 20, order: "views"}} @@ -159,7 +155,6 @@ defmodule GroupherServer.Test.Query.PagedArticles.PagedPosts do assert results["entries"] |> Enum.any?(&(&1["state"] == "WIP")) end - @tag :wip test "should get valid cat & state by filter", ~m(guest_conn post_last_week)a do {:ok, _post} = CMS.set_post_cat(post_last_week, @article_cat.feature) {:ok, _post} = CMS.set_post_state(post_last_week, @article_state.wip) From 02087747924214eae2c3d6551600a65124609fe7 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Fri, 1 Mar 2024 19:34:07 +0800 Subject: [PATCH 04/16] chore: wip --- lib/groupher_server/cms/models/metrics/dashboard.ex | 3 ++- .../mutation/cms/dashboard_test.exs | 12 +++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/groupher_server/cms/models/metrics/dashboard.ex b/lib/groupher_server/cms/models/metrics/dashboard.ex index 589c7d1..ef37d51 100644 --- a/lib/groupher_server/cms/models/metrics/dashboard.ex +++ b/lib/groupher_server/cms/models/metrics/dashboard.ex @@ -73,7 +73,8 @@ defmodule GroupherServer.CMS.Model.Metrics.Dashboard do [:glow_opacity, :string, ""], ## blur - [:goss_blur, :integer, 100] + [:goss_blur, :integer, 100], + [:goss_blur_dark, :integer, 100] ] end diff --git a/test/groupher_server_web/mutation/cms/dashboard_test.exs b/test/groupher_server_web/mutation/cms/dashboard_test.exs index 8c240e5..2113611 100644 --- a/test/groupher_server_web/mutation/cms/dashboard_test.exs +++ b/test/groupher_server_web/mutation/cms/dashboard_test.exs @@ -188,8 +188,8 @@ defmodule GroupherServer.Test.Mutation.CMS.Dashboard do end @update_layout_query """ - mutation($community: String!, $primaryColor: String $postLayout: String, $kanbanLayout: String, $kanbanCardLayout: String, $footerLayout: String, $broadcastEnable: Boolean, $kanbanBgColors: [String], $glowType: String, $glowFixed: Boolean, $glowOpacity: String, $tagLayout: String, $gossBlur: Int) { - updateDashboardLayout(community: $community, primaryColor: $primaryColor, postLayout: $postLayout, kanbanLayout: $kanbanLayout, kanbanCardLayout: $kanbanCardLayout, footerLayout: $footerLayout, broadcastEnable: $broadcastEnable, kanbanBgColors: $kanbanBgColors, glowType: $glowType, glowFixed: $glowFixed, glowOpacity: $glowOpacity, tagLayout: $tagLayout, gossBlur: $gossBlur) { + mutation($community: String!, $primaryColor: String $postLayout: String, $kanbanLayout: String, $kanbanCardLayout: String, $footerLayout: String, $broadcastEnable: Boolean, $kanbanBgColors: [String], $glowType: String, $glowFixed: Boolean, $glowOpacity: String, $tagLayout: String, $gossBlur: Int, $gossBlurDark: Int, $brandLayout: String) { + updateDashboardLayout(community: $community, primaryColor: $primaryColor, postLayout: $postLayout, kanbanLayout: $kanbanLayout, kanbanCardLayout: $kanbanCardLayout, footerLayout: $footerLayout, broadcastEnable: $broadcastEnable, kanbanBgColors: $kanbanBgColors, glowType: $glowType, glowFixed: $glowFixed, glowOpacity: $glowOpacity, tagLayout: $tagLayout, gossBlur: $gossBlur, gossBlurDark: $gossBlurDark, brandLayout: $brandLayout) { id title dashboard { @@ -200,6 +200,8 @@ defmodule GroupherServer.Test.Mutation.CMS.Dashboard do glowFixed glowOpacity gossBlur + gossBlurDark + brandLayout } } } @@ -222,7 +224,9 @@ defmodule GroupherServer.Test.Mutation.CMS.Dashboard do glowFixed: true, glowOpacity: "30", tagLayout: "dot", - gossBlur: 80 + gossBlur: 80, + gossBlurDark: 60, + brandLayout: "LOGO" } updated = @@ -244,6 +248,8 @@ defmodule GroupherServer.Test.Mutation.CMS.Dashboard do assert found.dashboard.layout.glow_opacity == "30" assert found.dashboard.layout.tag_layout == "dot" assert found.dashboard.layout.goss_blur == 80 + assert found.dashboard.layout.goss_blur_dark == 60 + assert found.dashboard.layout.brand_layout == "LOGO" end test "update community dashboard layout should not overwrite existing settings", From 4ef8bd2fb6f5712c0ab37284f9cbcb9ed63d532c Mon Sep 17 00:00:00 2001 From: mydearxym Date: Sun, 3 Mar 2024 12:41:27 +0800 Subject: [PATCH 05/16] chore(fly): debug --- .dockerignore | 45 ++++++++ Dockerfile | 87 +++++++++++++++ config/runtime.exs | 198 +++++++++++++++++++++++++++++++++ fly.toml | 35 ++++++ lib/groupher_server/release.ex | 28 +++++ rel/env.sh.eex | 8 ++ rel/overlays/bin/migrate | 3 + rel/overlays/bin/migrate.bat | 1 + rel/overlays/bin/server | 3 + rel/overlays/bin/server.bat | 2 + 10 files changed, 410 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 config/runtime.exs create mode 100644 fly.toml create mode 100644 lib/groupher_server/release.ex create mode 100644 rel/env.sh.eex create mode 100644 rel/overlays/bin/migrate create mode 100644 rel/overlays/bin/migrate.bat create mode 100644 rel/overlays/bin/server create mode 100644 rel/overlays/bin/server.bat diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..61a7393 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,45 @@ +# This file excludes paths from the Docker build context. +# +# By default, Docker's build context includes all files (and folders) in the +# current directory. Even if a file isn't copied into the container it is still sent to +# the Docker daemon. +# +# There are multiple reasons to exclude files from the build context: +# +# 1. Prevent nested folders from being copied into the container (ex: exclude +# /assets/node_modules when copying /assets) +# 2. Reduce the size of the build context and improve build time (ex. /build, /deps, /doc) +# 3. Avoid sending files containing sensitive information +# +# More information on using .dockerignore is available here: +# https://docs.docker.com/engine/reference/builder/#dockerignore-file + +.dockerignore + +# Ignore git, but keep git HEAD and refs to access current commit hash if needed: +# +# $ cat .git/HEAD | awk '{print ".git/"$2}' | xargs cat +# d0b8727759e1e0e7aa3d41707d12376e373d5ecc +.git +!.git/HEAD +!.git/refs + +# Common development/test artifacts +/cover/ +/doc/ +/test/ +/tmp/ +.elixir_ls + +# Mix artifacts +/_build/ +/deps/ +*.ez + +# Generated on crash by the VM +erl_crash.dump + +# Static artifacts - These should be fetched and built inside the Docker image +/assets/node_modules/ +/priv/static/assets/ +/priv/static/cache_manifest.json diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..05e8b9b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,87 @@ +# Find eligible builder and runner images on Docker Hub. We use Ubuntu/Debian instead of +# Alpine to avoid DNS resolution issues in production. +# +# https://hub.docker.com/r/hexpm/elixir/tags?page=1&name=ubuntu +# https://hub.docker.com/_/ubuntu?tab=tags +# +# +# This file is based on these images: +# +# - https://hub.docker.com/r/hexpm/elixir/tags - for the build image +# - https://hub.docker.com/_/debian?tab=tags&page=1&name=bullseye-20240130-slim - for the release image +# - https://pkgs.org/ - resource for finding needed packages +# - Ex: hexpm/elixir:1.15.7-erlang-26.0.2-debian-bullseye-20240130-slim +# +ARG ELIXIR_VERSION=1.15.7 +ARG OTP_VERSION=26.0.2 +ARG DEBIAN_VERSION=bullseye-20240130-slim + +ARG BUILDER_IMAGE="hexpm/elixir:${ELIXIR_VERSION}-erlang-${OTP_VERSION}-debian-${DEBIAN_VERSION}" +ARG RUNNER_IMAGE="debian:${DEBIAN_VERSION}" + +FROM ${BUILDER_IMAGE} as builder + +# install build dependencies +RUN apt-get update -y && apt-get install -y build-essential git \ + && apt-get clean && rm -f /var/lib/apt/lists/*_* + +# prepare build dir +WORKDIR /app + +# install hex + rebar +RUN mix local.hex --force && \ + mix local.rebar --force + +# set build ENV +ENV MIX_ENV="prod" + +# install mix dependencies +COPY mix.exs mix.lock ./ +RUN mix deps.get --only $MIX_ENV +RUN mkdir config + +# copy compile-time config files before we compile dependencies +# to ensure any relevant config change will trigger the dependencies +# to be re-compiled. +COPY config/config.exs config/${MIX_ENV}.exs config/ +RUN mix deps.compile + +COPY priv priv + +COPY lib lib + +# Compile the release +RUN mix compile + +# Changes to config/runtime.exs don't require recompiling the code +COPY config/runtime.exs config/ + +COPY rel rel +RUN mix release + +# start a new build stage so that the final image will only contain +# the compiled release and other runtime necessities +FROM ${RUNNER_IMAGE} + +RUN apt-get update -y && apt-get install -y libstdc++6 openssl libncurses5 locales \ + && apt-get clean && rm -f /var/lib/apt/lists/*_* + +# Set the locale +RUN sed -i '/en_US.UTF-8/s/^# //g' /etc/locale.gen && locale-gen + +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US:en +ENV LC_ALL en_US.UTF-8 + +WORKDIR "/app" +RUN chown nobody /app + +# set runner ENV +ENV MIX_ENV="prod" + +# Only copy the final release from the build stage +COPY --from=builder --chown=nobody:root /app/_build/${MIX_ENV}/rel/groupher_server ./ + +USER nobody + +CMD ["/app/bin/server"] \ No newline at end of file diff --git a/config/runtime.exs b/config/runtime.exs new file mode 100644 index 0000000..a7eda15 --- /dev/null +++ b/config/runtime.exs @@ -0,0 +1,198 @@ +import Config + +if config_env() == :mock do + config :groupher_server, GroupherServerWeb.Endpoint, + http: [port: 4001], + debug_errors: true, + code_reloader: true, + check_origin: false, + watchers: [] + + config :groupher_server, Helper.Guardian, + issuer: "groupher_server", + secret_key: "hello" + + config :logger, :console, format: "[$level] $message\n" + + config :phoenix, :stacktrace_depth, 20 + + # Configure your database + config :groupher_server, GroupherServer.Repo, + adapter: Ecto.Adapters.Postgres, + username: "postgres", + password: "postgres", + database: "groupher_server_mock", + hostname: "localhost", + pool_size: 50, + queue_target: 5000 + + # config email services + config :groupher_server, GroupherServer.Mailer, adapter: Bamboo.LocalAdapter + + config :ex_aliyun_openapi, :sts, + access_key_id: System.get_env("ALI_OSS_STS_AK"), + access_key_secret: System.get_env("_ALIOSS_STS_AS") + + config :groupher_server, Helper.OSS, + endpoint: "oss-cn-shanghai.aliyuncs.com", + access_key_id: System.get_env("ALI_OSS_STS_AK"), + access_key_secret: System.get_env("_ALIOSS_STS_AS") +end + +if config_env() == :test do + # We don't run a server during test. If one is required, + # you can enable the server option below. + config :groupher_server, GroupherServerWeb.Endpoint, + http: [port: 4001], + server: false + + # Print only warnings and errors during test + config :logger, level: :warn + + config :groupher_server, Helper.Guardian, + issuer: "groupher_server", + secret_key: "kSTPDbCUSRhiEmv86eYMUplL7xI5fDa/+6MWKzK2VYGxjwL0XGHHVJiSPNPe9hJe" + + config :groupher_server, :test, + # 成都电信 ip, for test use + remote_ip: "171.223.96.88" + + # Configure your database + config :groupher_server, GroupherServer.Repo, + adapter: Ecto.Adapters.Postgres, + username: "postgres", + password: "postgres", + database: "groupher_server_test", + hostname: "localhost", + pool_size: 50, + pool: Ecto.Adapters.SQL.Sandbox + + config :groupher_server, :github_oauth, + client_id: "3b4281c5e54ffd801f85", + client_secret: "51f04dd8239b27f00a39a647ef3704de4c5ddc26" + + # config email services + config :groupher_server, GroupherServer.Mailer, adapter: Bamboo.TestAdapter + + config :groupher_server, :audit, + token: "24.aa6fb4e4018c371e9ed228db5bea3ec0.2592000.1641816180.282335-25148796" + + config :groupher_server, :plausible, + token: "tDsEjaIBqmfVpkKByebYgrCs1Kl1V3N3prFACyFJq33eeEumg8hAFgm-3ZQamwAq" + + config :ex_aliyun_openapi, :sts, + access_key_id: "LTAI5tBVR8DcAWAjLmqBE1M3", + access_key_secret: "ND45kwF8bswHzvgJ7chvOtVsqneuh2" +end + +if config_env() == :prod do + # For production, we often load configuration from external + # sources, such as your system environment. For this reason, + # you won't find the :http configuration below, but set inside + # GroupherServerWeb.Endpoint.init/2 when load_from_system_env is + # true. Any dynamic configuration should be done there. + # + # Don't forget to configure the url host to something meaningful, + # Phoenix uses this information when generating URLs. + # + # Finally, we also include the path to a cache manifest + # containing the digested version of static files. This + # manifest is generated by the mix phx.digest task + # which you typically run after static files are built. + config :groupher_server, GroupherServerWeb.Endpoint, + load_from_system_env: true, + url: [host: "groupher.com", port: 80] + + # cache_static_manifest: "priv/static/cache_manifest.json" + + # Do not print debug messages in production + # config :logger, level: :info + config :logger, :console, format: "[$level] $message\n" + + # ## SSL Support + # + # To get SSL working, you will need to add the `https` key + # to the previous section and set your `:url` port to 443: + # + # config :groupher_server, GroupherServerWeb.Endpoint, + # ... + # url: [host: "example.com", port: 443], + # https: [:inet6, + # port: 443, + # keyfile: System.get_env("SOME_APP_SSL_KEY_PATH"), + # certfile: System.get_env("SOME_APP_SSL_CERT_PATH")] + # + # Where those two env variables return an absolute path to + # the key and cert in disk or a relative path inside priv, + # for example "priv/ssl/server.key". + # + # We also recommend setting `force_ssl`, ensuring no data is + # ever sent via http, always redirecting to https: + # + # config :groupher_server, GroupherServerWeb.Endpoint, + # force_ssl: [hsts: true] + # + # Check `Plug.SSL` for all available options in `force_ssl`. + + # ## Using releases + # + # If you are doing OTP releases, you need to instruct Phoenix + # to start the server for all endpoints: + # + # config :phoenix, :serve_endpoints, true + # + # Alternatively, you can configure exactly which server to + # start per endpoint: + # + # config :groupher_server, GroupherServerWeb.Endpoint, server: true + # + + # Finally import the config/prod.secret.exs + # which should be versioned separately. + # import_config "prod.secret.exs" + + config :groupher_server, GroupherServerWeb.Endpoint, + secret_key_base: System.get_env("SECRET_KEY_BASE") + + config :groupher_server, Helper.Guardian, + issuer: "groupher_server", + secret_key: System.get_env("GUARDIAN_KEY") + + # You can generate a new secret by running: + # mix phx.gen.secret + # should use RDS 内网地址 + config :groupher_server, GroupherServer.Repo, + adapter: Ecto.Adapters.Postgres, + username: System.get_env("DB_USERNAME"), + password: System.get_env("DB_PASSWORD"), + database: System.get_env("DB_NAME" || "cps_server_prod"), + hostname: System.get_env("DB_HOST"), + port: String.to_integer(System.get_env("DB_PORT") || "3433"), + pool_size: String.to_integer(System.get_env("DB_POOL_SIZE") || "20") + + config :groupher_server, :github_oauth, + client_id: System.get_env("OAUTH_GITHUB_CLIENT_ID"), + client_secret: System.get_env("OAUTH_GITHUB_CLIENT_SECRET"), + redirect_uri: System.get_env("OAUTH_GITHUB_REDIRECT_URI") + + config :groupher_server, :ip_locate, ip_service: System.get_env("IP_LOCATE_KEY") + config :groupher_server, :plausible, token: System.get_env("PLAUSIBLE_TOKEN") + config :groupher_server, :audit, token: System.get_env("AUDIT_TOKEN") + + # config :sentry, + # dsn: System.get_env("SENTRY_DSN"), + # environment_name: :prod, + # enable_source_code_context: true, + # root_source_code_path: File.cwd!(), + # tags: %{ + # env: "production" + # }, + # included_environments: [:prod] + + # config email services + config :groupher_server, GroupherServer.Mailer, api_key: System.get_env("MAILER_API_KEY") + + config :ex_aliyun_openapi, :sts, + access_key_id: System.get_env("ALI_OSS_STS_AK"), + access_key_secret: System.get_env("_ALIOSS_STS_AS") +end diff --git a/fly.toml b/fly.toml new file mode 100644 index 0000000..f56ddbe --- /dev/null +++ b/fly.toml @@ -0,0 +1,35 @@ +# fly.toml app configuration file generated for groupher-server-withered-violet-5488 on 2024-03-03T12:33:37+08:00 +# +# See https://fly.io/docs/reference/configuration/ for information about how to use this file. +# + +app = 'groupher-server-withered-violet-5488' +primary_region = 'sin' +kill_signal = 'SIGTERM' + +[build] + +[deploy] + release_command = '/app/bin/migrate' + +[env] + PHX_HOST = 'groupher-server-withered-violet-5488.fly.dev' + PORT = '8080' + +[http_service] + internal_port = 8080 + force_https = true + auto_stop_machines = true + auto_start_machines = true + min_machines_running = 0 + processes = ['app'] + + [http_service.concurrency] + type = 'connections' + hard_limit = 1000 + soft_limit = 1000 + +[[vm]] + memory = '1gb' + cpu_kind = 'shared' + cpus = 1 diff --git a/lib/groupher_server/release.ex b/lib/groupher_server/release.ex new file mode 100644 index 0000000..60c2cfe --- /dev/null +++ b/lib/groupher_server/release.ex @@ -0,0 +1,28 @@ +defmodule GroupherServer.Release do + @moduledoc """ + Used for executing DB release tasks when run in production without Mix + installed. + """ + @app :groupher_server + + def migrate do + load_app() + + for repo <- repos() do + {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :up, all: true)) + end + end + + def rollback(repo, version) do + load_app() + {:ok, _, _} = Ecto.Migrator.with_repo(repo, &Ecto.Migrator.run(&1, :down, to: version)) + end + + defp repos do + Application.fetch_env!(@app, :ecto_repos) + end + + defp load_app do + Application.load(@app) + end +end diff --git a/rel/env.sh.eex b/rel/env.sh.eex new file mode 100644 index 0000000..2bdface --- /dev/null +++ b/rel/env.sh.eex @@ -0,0 +1,8 @@ +#!/bin/sh + +# configure node for distributed erlang with IPV6 support +export ERL_AFLAGS="-proto_dist inet6_tcp" +export ECTO_IPV6="true" +export DNS_CLUSTER_QUERY="${FLY_APP_NAME}.internal" +export RELEASE_DISTRIBUTION="name" +export RELEASE_NODE="${FLY_APP_NAME}-${FLY_IMAGE_REF##*-}@${FLY_PRIVATE_IP}" diff --git a/rel/overlays/bin/migrate b/rel/overlays/bin/migrate new file mode 100644 index 0000000..92c0190 --- /dev/null +++ b/rel/overlays/bin/migrate @@ -0,0 +1,3 @@ +#!/bin/sh +cd -P -- "$(dirname -- "$0")" +exec ./groupher_server eval GroupherServer.Release.migrate diff --git a/rel/overlays/bin/migrate.bat b/rel/overlays/bin/migrate.bat new file mode 100644 index 0000000..052c69a --- /dev/null +++ b/rel/overlays/bin/migrate.bat @@ -0,0 +1 @@ +call "%~dp0\groupher_server" eval GroupherServer.Release.migrate diff --git a/rel/overlays/bin/server b/rel/overlays/bin/server new file mode 100644 index 0000000..beb2e03 --- /dev/null +++ b/rel/overlays/bin/server @@ -0,0 +1,3 @@ +#!/bin/sh +cd -P -- "$(dirname -- "$0")" +PHX_SERVER=true exec ./groupher_server start diff --git a/rel/overlays/bin/server.bat b/rel/overlays/bin/server.bat new file mode 100644 index 0000000..af63857 --- /dev/null +++ b/rel/overlays/bin/server.bat @@ -0,0 +1,2 @@ +set PHX_SERVER=true +call "%~dp0\groupher_server" start From efaf3bcc0471be16e81af216445a656ced1a3c0f Mon Sep 17 00:00:00 2001 From: mydearxym Date: Mon, 4 Mar 2024 10:52:38 +0800 Subject: [PATCH 06/16] chore(fly): migrateion done --- config/prod.exs | 12 ------------ config/runtime.exs | 11 +++++++++-- fly.toml | 8 ++++---- .../mailer/templates/mention_author.ex | 2 +- {test => lib}/support/assert_helper.ex | 0 {test => lib}/support/channel_case.ex | 0 {test => lib}/support/conn_case.ex | 0 {test => lib}/support/conn_simulator.ex | 0 {test => lib}/support/data_case.ex | 0 {test => lib}/support/factory.ex | 0 {test => lib}/support/geo_data.ex | 0 {test => lib}/support/test_tools.ex | 0 mix.exs | 2 -- 13 files changed, 14 insertions(+), 21 deletions(-) rename {test => lib}/support/assert_helper.ex (100%) rename {test => lib}/support/channel_case.ex (100%) rename {test => lib}/support/conn_case.ex (100%) rename {test => lib}/support/conn_simulator.ex (100%) rename {test => lib}/support/data_case.ex (100%) rename {test => lib}/support/factory.ex (100%) rename {test => lib}/support/geo_data.ex (100%) rename {test => lib}/support/test_tools.ex (100%) diff --git a/config/prod.exs b/config/prod.exs index cdb9afb..73f9f1d 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -72,18 +72,6 @@ config :groupher_server, Helper.Guardian, issuer: "groupher_server", secret_key: System.get_env("GUARDIAN_KEY") -# You can generate a new secret by running: -# mix phx.gen.secret -# should use RDS 内网地址 -config :groupher_server, GroupherServer.Repo, - adapter: Ecto.Adapters.Postgres, - username: System.get_env("DB_USERNAME"), - password: System.get_env("DB_PASSWORD"), - database: System.get_env("DB_NAME" || "cps_server_prod"), - hostname: System.get_env("DB_HOST"), - port: String.to_integer(System.get_env("DB_PORT") || "3433"), - pool_size: String.to_integer(System.get_env("DB_POOL_SIZE") || "20") - config :groupher_server, :github_oauth, client_id: System.get_env("OAUTH_GITHUB_CLIENT_ID"), client_secret: System.get_env("OAUTH_GITHUB_CLIENT_SECRET"), diff --git a/config/runtime.exs b/config/runtime.exs index a7eda15..f0cf663 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -161,14 +161,21 @@ if config_env() == :prod do # You can generate a new secret by running: # mix phx.gen.secret # should use RDS 内网地址 + # see https://neon.tech/docs/guides/elixir-ecto for Neon DB on vercel config :groupher_server, GroupherServer.Repo, adapter: Ecto.Adapters.Postgres, username: System.get_env("DB_USERNAME"), password: System.get_env("DB_PASSWORD"), database: System.get_env("DB_NAME" || "cps_server_prod"), hostname: System.get_env("DB_HOST"), - port: String.to_integer(System.get_env("DB_PORT") || "3433"), - pool_size: String.to_integer(System.get_env("DB_POOL_SIZE") || "20") + port: String.to_integer(System.get_env("DB_PORT") || "5432"), + pool_size: String.to_integer(System.get_env("DB_POOL_SIZE") || "20"), + ssl: true, + ssl_opts: [ + # server_name_indication: String.to_charlist("debug here if need"), + server_name_indication: System.get_env("DB_HOST") |> String.to_charlist(), + verify: :verify_none + ] config :groupher_server, :github_oauth, client_id: System.get_env("OAUTH_GITHUB_CLIENT_ID"), diff --git a/fly.toml b/fly.toml index f56ddbe..543bf00 100644 --- a/fly.toml +++ b/fly.toml @@ -1,10 +1,10 @@ -# fly.toml app configuration file generated for groupher-server-withered-violet-5488 on 2024-03-03T12:33:37+08:00 +# fly.toml app configuration file generated for groupher-server-withered-violet-5488-quiet-fog-9123 on 2024-03-03T20:11:00+08:00 # # See https://fly.io/docs/reference/configuration/ for information about how to use this file. # -app = 'groupher-server-withered-violet-5488' -primary_region = 'sin' +app = 'groupher-server-withered-violet-5488-quiet-fog-9123' +primary_region = 'hkg' kill_signal = 'SIGTERM' [build] @@ -13,7 +13,7 @@ kill_signal = 'SIGTERM' release_command = '/app/bin/migrate' [env] - PHX_HOST = 'groupher-server-withered-violet-5488.fly.dev' + PHX_HOST = 'groupher-server-withered-violet-5488-quiet-fog-9123.fly.dev' PORT = '8080' [http_service] diff --git a/lib/groupher_server/mailer/templates/mention_author.ex b/lib/groupher_server/mailer/templates/mention_author.ex index b5a73a0..17cdb9f 100644 --- a/lib/groupher_server/mailer/templates/mention_author.ex +++ b/lib/groupher_server/mailer/templates/mention_author.ex @@ -9,7 +9,7 @@ defmodule GroupherServer.Email.Templates.MentionAuthor do just copy and paste raw string to: https://mjml.io/try-it-live """ - def html(record) do + def html(_record) do """ TODO """ diff --git a/test/support/assert_helper.ex b/lib/support/assert_helper.ex similarity index 100% rename from test/support/assert_helper.ex rename to lib/support/assert_helper.ex diff --git a/test/support/channel_case.ex b/lib/support/channel_case.ex similarity index 100% rename from test/support/channel_case.ex rename to lib/support/channel_case.ex diff --git a/test/support/conn_case.ex b/lib/support/conn_case.ex similarity index 100% rename from test/support/conn_case.ex rename to lib/support/conn_case.ex diff --git a/test/support/conn_simulator.ex b/lib/support/conn_simulator.ex similarity index 100% rename from test/support/conn_simulator.ex rename to lib/support/conn_simulator.ex diff --git a/test/support/data_case.ex b/lib/support/data_case.ex similarity index 100% rename from test/support/data_case.ex rename to lib/support/data_case.ex diff --git a/test/support/factory.ex b/lib/support/factory.ex similarity index 100% rename from test/support/factory.ex rename to lib/support/factory.ex diff --git a/test/support/geo_data.ex b/lib/support/geo_data.ex similarity index 100% rename from test/support/geo_data.ex rename to lib/support/geo_data.ex diff --git a/test/support/test_tools.ex b/lib/support/test_tools.ex similarity index 100% rename from test/support/test_tools.ex rename to lib/support/test_tools.ex diff --git a/mix.exs b/mix.exs index 43ebb4d..eb8de0d 100644 --- a/mix.exs +++ b/mix.exs @@ -32,7 +32,6 @@ defmodule GroupherServer.Mixfile do [ mod: {GroupherServer.Application, []}, extra_applications: [ - :open_graph, :corsica, :ex_unit, :logger, @@ -107,7 +106,6 @@ defmodule GroupherServer.Mixfile do # cron-like scheduler job {:quantum, "~> 2.3"}, {:html_sanitize_ex, "~> 1.3"}, - {:open_graph, "~> 0.0.3"}, {:earmark, "~> 1.4.13"}, {:accessible, "~> 0.3.0"}, {:floki, "~> 0.30.1"}, From 52bea74ae4e11c31d9d361b9ccb4b2416992ae2b Mon Sep 17 00:00:00 2001 From: mydearxym Date: Sat, 9 Mar 2024 17:20:28 +0800 Subject: [PATCH 07/16] chore: fix graphiql route --- lib/groupher_server_web/router.ex | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/groupher_server_web/router.ex b/lib/groupher_server_web/router.ex index 4e575ce..fede436 100644 --- a/lib/groupher_server_web/router.ex +++ b/lib/groupher_server_web/router.ex @@ -24,10 +24,10 @@ defmodule GroupherServerWeb.Router do forward( "/", Absinthe.Plug.GraphiQL, - schema: GroupherServerWeb.Schema, - json_codec: Jason, - interface: :playground, - context: %{pubsub: GroupherServerWeb.Endpoint} + schema: GroupherServerWeb.Schema + # json_codec: Jason, + # interface: :playground, + # context: %{pubsub: GroupherServerWeb.Endpoint} ) end end From cc0b64d0e6062c164f96ec663e814676b572ce3d Mon Sep 17 00:00:00 2001 From: mydearxym Date: Sat, 9 Mar 2024 17:55:20 +0800 Subject: [PATCH 08/16] chore: set PORT --- config/dev.exs | 2 +- lib/groupher_server_web/endpoint.ex | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/dev.exs b/config/dev.exs index 0fd109c..ad4a843 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -7,7 +7,7 @@ import Config # watchers to your application. For example, we use it # with brunch.io to recompile .js and .css sources. config :groupher_server, GroupherServerWeb.Endpoint, - http: [port: String.to_integer(System.get_env("SERVE_PORT") || "7001")], + http: [port: String.to_integer(System.get_env("PORT") || "7001")], debug_errors: true, code_reloader: true, check_origin: false, diff --git a/lib/groupher_server_web/endpoint.ex b/lib/groupher_server_web/endpoint.ex index 644b6b0..ad499e7 100644 --- a/lib/groupher_server_web/endpoint.ex +++ b/lib/groupher_server_web/endpoint.ex @@ -53,7 +53,7 @@ defmodule GroupherServerWeb.Endpoint do def init(_key, config) do if config[:load_from_system_env] do port = - System.get_env("SERVE_PORT") || raise "expected the PORT environment variable to be set" + System.get_env("PORT") || raise "expected the PORT environment variable to be set" {:ok, Keyword.put(config, :http, [:inet6, port: port])} else From 1a06b40e338cbcd19979d64a565ae7d09af0496b Mon Sep 17 00:00:00 2001 From: mydearxym Date: Sat, 9 Mar 2024 21:03:35 +0800 Subject: [PATCH 09/16] chore: config endpoint --- config/prod.exs | 5 ++--- lib/groupher_server_web/endpoint.ex | 6 ++---- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/config/prod.exs b/config/prod.exs index 73f9f1d..b7e99c0 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -13,9 +13,8 @@ import Config # containing the digested version of static files. This # manifest is generated by the mix phx.digest task # which you typically run after static files are built. -config :groupher_server, GroupherServerWeb.Endpoint, - load_from_system_env: true, - url: [host: "groupher.com", port: 80] +config :groupher_server, GroupherServerWeb.Endpoint, load_from_system_env: true +# url: [host: "groupher.com", port: 80] # cache_static_manifest: "priv/static/cache_manifest.json" diff --git a/lib/groupher_server_web/endpoint.ex b/lib/groupher_server_web/endpoint.ex index ad499e7..7f5c45f 100644 --- a/lib/groupher_server_web/endpoint.ex +++ b/lib/groupher_server_web/endpoint.ex @@ -52,10 +52,8 @@ defmodule GroupherServerWeb.Endpoint do """ def init(_key, config) do if config[:load_from_system_env] do - port = - System.get_env("PORT") || raise "expected the PORT environment variable to be set" - - {:ok, Keyword.put(config, :http, [:inet6, port: port])} + {:ok, + Keyword.put(config, :http, [:inet6, ip: {0, 0, 0, 0}, port: System.get_env("PORT") || 8080])} else {:ok, config} end From abae7cd632a4d0d71bf6e46297d2b8cf263eae55 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Sat, 9 Mar 2024 21:17:24 +0800 Subject: [PATCH 10/16] chore: config endpoint --- config/runtime.exs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/config/runtime.exs b/config/runtime.exs index f0cf663..79a9c49 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -99,9 +99,8 @@ if config_env() == :prod do # containing the digested version of static files. This # manifest is generated by the mix phx.digest task # which you typically run after static files are built. - config :groupher_server, GroupherServerWeb.Endpoint, - load_from_system_env: true, - url: [host: "groupher.com", port: 80] + config :groupher_server, GroupherServerWeb.Endpoint, load_from_system_env: true + # url: [host: "groupher.com", port: 80] # cache_static_manifest: "priv/static/cache_manifest.json" From 95aa93f6131877efd8c373b7a1b19a2a09ec76cd Mon Sep 17 00:00:00 2001 From: mydearxym Date: Sat, 9 Mar 2024 22:53:57 +0800 Subject: [PATCH 11/16] chore: config server in prod --- config/runtime.exs | 1 + lib/groupher_server/application.ex | 5 ++--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/config/runtime.exs b/config/runtime.exs index 79a9c49..2ad66ad 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -101,6 +101,7 @@ if config_env() == :prod do # which you typically run after static files are built. config :groupher_server, GroupherServerWeb.Endpoint, load_from_system_env: true # url: [host: "groupher.com", port: 80] + config :groupher_server, GroupherServerWeb.Endpoint, server: true # cache_static_manifest: "priv/static/cache_manifest.json" diff --git a/lib/groupher_server/application.ex b/lib/groupher_server/application.ex index eec3470..f9eae8a 100644 --- a/lib/groupher_server/application.ex +++ b/lib/groupher_server/application.ex @@ -19,9 +19,9 @@ defmodule GroupherServer.Application do # Start the PubSub system {Phoenix.PubSub, name: MyApp.PubSub}, # Start the Ecto repository - supervisor(GroupherServer.Repo, []), + GroupherServer.Repo, # Start the endpoint when the application starts - supervisor(GroupherServerWeb.Endpoint, []), + GroupherServerWeb.Endpoint, # Start your own worker by calling: GroupherServer.Worker.start_link(arg1, arg2, arg3) # worker(Helper.Scheduler, []), {Rihanna.Supervisor, [postgrex: GroupherServer.Repo.config()]} @@ -42,7 +42,6 @@ defmodule GroupherServer.Application do defp cache_workers() do import Supervisor.Spec - # worker(GroupherServer.Worker, [arg1, arg2, arg3]), # worker(Cachex, [:common, Cache.config(:common)], id: :common), # worker(Cachex, [:user_login, Cache.config(:user_login)], id: :user_login), From c2d514a4c93d302148403400bd0663f60ac7f745 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Sat, 9 Mar 2024 23:35:52 +0800 Subject: [PATCH 12/16] chore: upgrade phoenix to 1.7 --- mix.exs | 4 +--- mix.lock | 14 ++++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/mix.exs b/mix.exs index eb8de0d..39df3a6 100644 --- a/mix.exs +++ b/mix.exs @@ -9,8 +9,6 @@ defmodule GroupherServer.Mixfile do version: "2.1.2", elixir: "~> 1.9", elixirc_paths: elixirc_paths(Mix.env()), - # compilers: [:phoenix, :gettext] ++ Mix.compilers(), - compilers: [:phoenix] ++ Mix.compilers(), dialyzer: [plt_add_deps: :transitive, ignore_warnings: ".dialyzer_ignore.exs"], test_coverage: [tool: ExCoveralls], preferred_cli_env: [ @@ -54,7 +52,7 @@ defmodule GroupherServer.Mixfile do # Type `mix help deps` for examples and options. defp deps do [ - {:phoenix, "~> 1.6.16"}, + {:phoenix, "~> 1.7.0"}, {:phoenix_pubsub, "~> 2.0"}, {:phoenix_html, "~> 2.14.3"}, {:ecto_sql, "~> 3.10.1"}, diff --git a/mix.lock b/mix.lock index da1d964..9ab5f81 100644 --- a/mix.lock +++ b/mix.lock @@ -11,14 +11,14 @@ "base64url": {:hex, :base64url, "0.0.1", "36a90125f5948e3afd7be97662a1504b934dd5dac78451ca6e9abf85a10286be", [:rebar], [], "hexpm", "fab09b20e3f5db886725544cbcf875b8e73ec93363954eb8a1a9ed834aa8c1f9"}, "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"}, "cachex": {:hex, :cachex, "3.3.0", "6f2ebb8f27491fe39121bd207c78badc499214d76c695658b19d6079beeca5c2", [:mix], [{:eternal, "~> 1.2", [hex: :eternal, repo: "hexpm", optional: false]}, {:jumper, "~> 1.0", [hex: :jumper, repo: "hexpm", optional: false]}, {:sleeplocks, "~> 1.1", [hex: :sleeplocks, repo: "hexpm", optional: false]}, {:unsafe, "~> 1.0", [hex: :unsafe, repo: "hexpm", optional: false]}], "hexpm", "d90e5ee1dde14cef33f6b187af4335b88748b72b30c038969176cd4e6ccc31a1"}, - "castore": {:hex, :castore, "1.0.4", "ff4d0fb2e6411c0479b1d965a814ea6d00e51eb2f58697446e9c41a97d940b28", [:mix], [], "hexpm", "9418c1b8144e11656f0be99943db4caf04612e3eaecefb5dae9a2a87565584f8"}, + "castore": {:hex, :castore, "1.0.5", "9eeebb394cc9a0f3ae56b813459f990abb0a3dedee1be6b27fdb50301930502f", [:mix], [], "hexpm", "8d7c597c3e4a64c395980882d4bca3cebb8d74197c590dc272cfd3b6a6310578"}, "certifi": {:hex, :certifi, "2.12.0", "2d1cca2ec95f59643862af91f001478c9863c2ac9cb6e2f89780bfd8de987329", [:rebar3], [], "hexpm", "ee68d85df22e554040cdb4be100f33873ac6051387baf6a8f6ce82272340ff1c"}, "combine": {:hex, :combine, "0.10.0", "eff8224eeb56498a2af13011d142c5e7997a80c8f5b97c499f84c841032e429f", [:mix], [], "hexpm", "1b1dbc1790073076580d0d1d64e42eae2366583e7aecd455d1215b0d16f2451b"}, "comeonin": {:hex, :comeonin, "5.3.2", "5c2f893d05c56ae3f5e24c1b983c2d5dfb88c6d979c9287a76a7feb1e1d8d646", [:mix], [], "hexpm", "d0993402844c49539aeadb3fe46a3c9bd190f1ecf86b6f9ebd71957534c95f04"}, "connection": {:hex, :connection, "1.1.0", "ff2a49c4b75b6fb3e674bfc5536451607270aac754ffd1bdfe175abe4a6d7a68", [:mix], [], "hexpm", "722c1eb0a418fbe91ba7bd59a47e28008a189d47e37e0e7bb85585a016b2869c"}, "cors_plug": {:hex, :cors_plug, "1.5.0", "6311ea6ac9fb78b987df52a7654136626a7a0c3b77f83da265f952a24f2fc1b0", [], [{:plug, "~> 1.4", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"}, "corsica": {:hex, :corsica, "2.1.2", "0f1bc7648f9a41abca557c8158c110269d61a1465468be2416621991e316ff56", [:mix], [{:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.0 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c778c6ded25ec78c57c64a7b769edb388ec8f162ea3b6f10fa2580fb13fb2afb"}, - "cowboy": {:hex, :cowboy, "2.10.0", "ff9ffeff91dae4ae270dd975642997afe2a1179d94b1887863e43f681a203e26", [:make, :rebar3], [{:cowlib, "2.12.1", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "3afdccb7183cc6f143cb14d3cf51fa00e53db9ec80cdcd525482f5e99bc41d6b"}, + "cowboy": {:hex, :cowboy, "2.11.0", "356bf784599cf6f2cdc6ad12fdcfb8413c2d35dab58404cf000e1feaed3f5645", [:make, :rebar3], [{:cowlib, "2.12.1", [hex: :cowlib, repo: "hexpm", optional: false]}, {:ranch, "1.8.0", [hex: :ranch, repo: "hexpm", optional: false]}], "hexpm", "0fa395437f1b0e104e0e00999f39d2ac5f4082ac5049b67a5b6d56ecc31b1403"}, "cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"}, "cowlib": {:hex, :cowlib, "2.12.1", "a9fa9a625f1d2025fe6b462cb865881329b5caff8f1854d1cbc9f9533f00e1e1", [:make, :rebar3], [], "hexpm", "163b73f6367a7341b33c794c4e88e7dbfe6498ac42dcd69ef44c5bc5507c8db0"}, "credo": {:hex, :credo, "1.5.5", "e8f422026f553bc3bebb81c8e8bf1932f498ca03339856c7fec63d3faac8424b", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "dd8623ab7091956a855dc9f3062486add9c52d310dfd62748779c4315d8247de"}, @@ -84,15 +84,15 @@ "paginator": {:hex, :paginator, "1.0.4", "471e8e59e7a08541c5b7d2ea7166308c8e05ceb412fb444f3bdf320f5d793260", [:mix], [{:ecto, "~> 3.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:ecto_sql, "~> 3.0", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:postgrex, "~> 0.13", [hex: :postgrex, repo: "hexpm", optional: true]}], "hexpm", "9d79d21c0192d8d1fc562e5c99b5ebf7e0bb443c671e256b41fd709170730b91"}, "pangu": {:hex, :pangu, "0.1.0", "9f9e06418212017bb076034865462e92effed4e5b18c063d4448c186f12a6f0a", [:mix], [], "hexpm", "2634cc2463421757aca0a76665de83940d4fda12f8ed316ae929bb29f64d06c5"}, "parse_trans": {:hex, :parse_trans, "3.4.1", "6e6aa8167cb44cc8f39441d05193be6e6f4e7c2946cb2759f015f8c56b76e5ff", [:rebar3], [], "hexpm", "620a406ce75dada827b82e453c19cf06776be266f5a67cff34e1ef2cbb60e49a"}, - "phoenix": {:hex, :phoenix, "1.6.16", "e5bdd18c7a06da5852a25c7befb72246de4ddc289182285f8685a40b7b5f5451", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.0", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 1.0 or ~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: false]}, {:plug, "~> 1.10", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.2", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "e15989ff34f670a96b95ef6d1d25bad0d9c50df5df40b671d8f4a669e050ac39"}, + "phoenix": {:hex, :phoenix, "1.7.10", "02189140a61b2ce85bb633a9b6fd02dff705a5f1596869547aeb2b2b95edd729", [:mix], [{:castore, ">= 0.0.0", [hex: :castore, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:phoenix_pubsub, "~> 2.1", [hex: :phoenix_pubsub, repo: "hexpm", optional: false]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}, {:phoenix_view, "~> 2.0", [hex: :phoenix_view, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:plug_crypto, "~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:websock_adapter, "~> 0.5.3", [hex: :websock_adapter, repo: "hexpm", optional: false]}], "hexpm", "cf784932e010fd736d656d7fead6a584a4498efefe5b8227e9f383bf15bb79d0"}, "phoenix_ecto": {:hex, :phoenix_ecto, "4.4.0", "0672ed4e4808b3fbed494dded89958e22fb882de47a97634c0b13e7b0b5f7720", [:mix], [{:ecto, "~> 3.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:plug, "~> 1.9", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "09864e558ed31ee00bd48fcc1d4fc58ae9678c9e81649075431e69dbabb43cc1"}, "phoenix_html": {:hex, :phoenix_html, "2.14.3", "51f720d0d543e4e157ff06b65de38e13303d5778a7919bcc696599e5934271b8", [:mix], [{:plug, "~> 1.5", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "efd697a7fff35a13eeeb6b43db884705cba353a1a41d127d118fda5f90c8e80f"}, - "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.1", "ba04e489ef03763bf28a17eb2eaddc2c20c6d217e2150a61e3298b0f4c2012b5", [:mix], [], "hexpm", "81367c6d1eea5878ad726be80808eb5a787a23dee699f96e72b1109c57cdd8d9"}, - "phoenix_template": {:hex, :phoenix_template, "1.0.1", "85f79e3ad1b0180abb43f9725973e3b8c2c3354a87245f91431eec60553ed3ef", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "157dc078f6226334c91cb32c1865bf3911686f8bcd6bcff86736f6253e6993ee"}, + "phoenix_pubsub": {:hex, :phoenix_pubsub, "2.1.3", "3168d78ba41835aecad272d5e8cd51aa87a7ac9eb836eabc42f6e57538e3731d", [:mix], [], "hexpm", "bba06bc1dcfd8cb086759f0edc94a8ba2bc8896d5331a1e2c2902bf8e36ee502"}, + "phoenix_template": {:hex, :phoenix_template, "1.0.4", "e2092c132f3b5e5b2d49c96695342eb36d0ed514c5b252a77048d5969330d639", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0 or ~> 4.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}], "hexpm", "2c0c81f0e5c6753faf5cca2f229c9709919aba34fab866d3bc05060c9c444206"}, "phoenix_view": {:hex, :phoenix_view, "2.0.2", "6bd4d2fd595ef80d33b439ede6a19326b78f0f1d8d62b9a318e3d9c1af351098", [:mix], [{:phoenix_html, "~> 2.14.2 or ~> 3.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:phoenix_template, "~> 1.0", [hex: :phoenix_template, repo: "hexpm", optional: false]}], "hexpm", "a929e7230ea5c7ee0e149ffcf44ce7cf7f4b6d2bfe1752dd7c084cdff152d36f"}, "plug": {:hex, :plug, "1.14.2", "cff7d4ec45b4ae176a227acd94a7ab536d9b37b942c8e8fa6dfc0fff98ff4d80", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "842fc50187e13cf4ac3b253d47d9474ed6c296a8732752835ce4a86acdf68d13"}, "plug_canonical_host": {:hex, :plug_canonical_host, "0.3.1", "0c279b7631ccb6ddb53bf58bdfa015ca69109f52a1fd4cc30909f92313d969e0", [:mix], [{:plug, " ~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm"}, - "plug_cowboy": {:hex, :plug_cowboy, "2.6.1", "9a3bbfceeb65eff5f39dab529e5cd79137ac36e913c02067dba3963a26efe9b2", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "de36e1a21f451a18b790f37765db198075c25875c64834bcc82d90b309eb6613"}, + "plug_cowboy": {:hex, :plug_cowboy, "2.6.2", "753611b23b29231fb916b0cdd96028084b12aff57bfd7b71781bd04b1dbeb5c9", [:mix], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:cowboy_telemetry, "~> 0.3", [hex: :cowboy_telemetry, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "951ed2433df22f4c97b85fdb145d4cee561f36b74854d64c06d896d7cd2921a7"}, "plug_crypto": {:hex, :plug_crypto, "1.2.5", "918772575e48e81e455818229bf719d4ab4181fcbf7f85b68a35620f78d89ced", [:mix], [], "hexpm", "26549a1d6345e2172eb1c233866756ae44a9609bd33ee6f99147ab3fd87fd842"}, "poison": {:hex, :poison, "4.0.1", "bcb755a16fac91cad79bfe9fc3585bb07b9331e50cfe3420a24bcc2d735709ae", [:mix], [], "hexpm", "ba8836feea4b394bb718a161fc59a288fe0109b5006d6bdf97b6badfcf6f0f25"}, "poolboy": {:hex, :poolboy, "1.5.1", "6b46163901cfd0a1b43d692657ed9d7e599853b3b21b95ae5ae0a777cf9b6ca8", [:rebar], [], "hexpm"}, @@ -119,5 +119,7 @@ "unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"}, "unsafe": {:hex, :unsafe, "1.0.1", "a27e1874f72ee49312e0a9ec2e0b27924214a05e3ddac90e91727bc76f8613d8", [:mix], [], "hexpm", "6c7729a2d214806450d29766abc2afaa7a2cbecf415be64f36a6691afebb50e5"}, "uuid": {:hex, :uuid, "1.1.8", "e22fc04499de0de3ed1116b770c7737779f226ceefa0badb3592e64d5cfb4eb9", [:mix], [], "hexpm"}, + "websock": {:hex, :websock, "0.5.3", "2f69a6ebe810328555b6fe5c831a851f485e303a7c8ce6c5f675abeb20ebdadc", [:mix], [], "hexpm", "6105453d7fac22c712ad66fab1d45abdf049868f253cf719b625151460b8b453"}, + "websock_adapter": {:hex, :websock_adapter, "0.5.5", "9dfeee8269b27e958a65b3e235b7e447769f66b5b5925385f5a569269164a210", [:mix], [{:bandit, ">= 0.6.0", [hex: :bandit, repo: "hexpm", optional: true]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:plug_cowboy, "~> 2.6", [hex: :plug_cowboy, repo: "hexpm", optional: true]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "4b977ba4a01918acbf77045ff88de7f6972c2a009213c515a445c48f224ffce9"}, "xml_builder": {:hex, :xml_builder, "2.1.4", "e60e21c0a39b9dd8dec1db5a2525c713f7fe4e85ed247caedf22a9bcdd2d5069", [:mix], [], "hexpm", "48188a4df8b9168ceb8318d128299bce064d272e18967349b2592347c434e677"}, } From 2a09ae017a37ea1a6175460bac715a98a3bcc46f Mon Sep 17 00:00:00 2001 From: mydearxym Date: Sun, 24 Mar 2024 17:43:44 +0800 Subject: [PATCH 13/16] chore: wip --- config/runtime.exs | 119 ++++++++++------------------- lib/groupher_server/application.ex | 1 + 2 files changed, 40 insertions(+), 80 deletions(-) diff --git a/config/runtime.exs b/config/runtime.exs index 2ad66ad..c73d8ed 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -1,91 +1,51 @@ import Config -if config_env() == :mock do - config :groupher_server, GroupherServerWeb.Endpoint, - http: [port: 4001], - debug_errors: true, - code_reloader: true, - check_origin: false, - watchers: [] - - config :groupher_server, Helper.Guardian, - issuer: "groupher_server", - secret_key: "hello" - - config :logger, :console, format: "[$level] $message\n" - - config :phoenix, :stacktrace_depth, 20 - - # Configure your database - config :groupher_server, GroupherServer.Repo, - adapter: Ecto.Adapters.Postgres, - username: "postgres", - password: "postgres", - database: "groupher_server_mock", - hostname: "localhost", - pool_size: 50, - queue_target: 5000 - - # config email services - config :groupher_server, GroupherServer.Mailer, adapter: Bamboo.LocalAdapter - - config :ex_aliyun_openapi, :sts, - access_key_id: System.get_env("ALI_OSS_STS_AK"), - access_key_secret: System.get_env("_ALIOSS_STS_AS") - - config :groupher_server, Helper.OSS, - endpoint: "oss-cn-shanghai.aliyuncs.com", - access_key_id: System.get_env("ALI_OSS_STS_AK"), - access_key_secret: System.get_env("_ALIOSS_STS_AS") +# ## Using releases +# +# If you use `mix release`, you need to explicitly enable the server +# by passing the PHX_SERVER=true when you start it: +# +# PHX_SERVER=true bin/groupher_hello start +# +# Alternatively, you can use `mix phx.gen.release` to generate a `bin/server` +# script that automatically sets the env var above. +if System.get_env("PHX_SERVER") do + config :groupher_server, GroupherServerWeb.Endpoint, server: true end -if config_env() == :test do - # We don't run a server during test. If one is required, - # you can enable the server option below. - config :groupher_server, GroupherServerWeb.Endpoint, - http: [port: 4001], - server: false - - # Print only warnings and errors during test - config :logger, level: :warn - - config :groupher_server, Helper.Guardian, - issuer: "groupher_server", - secret_key: "kSTPDbCUSRhiEmv86eYMUplL7xI5fDa/+6MWKzK2VYGxjwL0XGHHVJiSPNPe9hJe" - - config :groupher_server, :test, - # 成都电信 ip, for test use - remote_ip: "171.223.96.88" - - # Configure your database - config :groupher_server, GroupherServer.Repo, - adapter: Ecto.Adapters.Postgres, - username: "postgres", - password: "postgres", - database: "groupher_server_test", - hostname: "localhost", - pool_size: 50, - pool: Ecto.Adapters.SQL.Sandbox +if config_env() == :prod do + # The secret key base is used to sign/encrypt cookies and other secrets. + # A default value is used in config/dev.exs and config/test.exs but you + # want to use a different value for prod and you most likely don't want + # to check this value into version control, so we use an environment + # variable instead. - config :groupher_server, :github_oauth, - client_id: "3b4281c5e54ffd801f85", - client_secret: "51f04dd8239b27f00a39a647ef3704de4c5ddc26" + secret_key_base = + System.get_env("SECRET_KEY_BASE") || + raise """ + environment variable SECRET_KEY_BASE is missing. + You can generate one by calling: mix phx.gen.secret + """ - # config email services - config :groupher_server, GroupherServer.Mailer, adapter: Bamboo.TestAdapter + host = + System.get_env("PHX_HOST") || "groupher-server-withered-violet-5488-quiet-fog-9123.fly.dev" - config :groupher_server, :audit, - token: "24.aa6fb4e4018c371e9ed228db5bea3ec0.2592000.1641816180.282335-25148796" + port = String.to_integer(System.get_env("PORT") || "4000") - config :groupher_server, :plausible, - token: "tDsEjaIBqmfVpkKByebYgrCs1Kl1V3N3prFACyFJq33eeEumg8hAFgm-3ZQamwAq" + config :groupher_server, :dns_cluster_query, System.get_env("DNS_CLUSTER_QUERY") - config :ex_aliyun_openapi, :sts, - access_key_id: "LTAI5tBVR8DcAWAjLmqBE1M3", - access_key_secret: "ND45kwF8bswHzvgJ7chvOtVsqneuh2" -end + config :groupher_server, GroupherServerWeb.Endpoint, + url: [host: host, port: 443, scheme: "https"], + http: [ + # Enable IPv6 and bind on all interfaces. + # Set it to {0, 0, 0, 0, 0, 0, 0, 1} for local network only access. + # See the documentation on https://hexdocs.pm/bandit/Bandit.html#t:options/0 + # for details about using IPv6 vs IPv4 and loopback vs public addresses. + ip: {0, 0, 0, 0, 0, 0, 0, 0}, + port: port + ], + secret_key_base: secret_key_base -if config_env() == :prod do # For production, we often load configuration from external # sources, such as your system environment. For this reason, # you won't find the :http configuration below, but set inside @@ -151,8 +111,7 @@ if config_env() == :prod do # which should be versioned separately. # import_config "prod.secret.exs" - config :groupher_server, GroupherServerWeb.Endpoint, - secret_key_base: System.get_env("SECRET_KEY_BASE") + config :groupher_server, GroupherServerWeb.Endpoint, secret_key_base: secret_key_base config :groupher_server, Helper.Guardian, issuer: "groupher_server", diff --git a/lib/groupher_server/application.ex b/lib/groupher_server/application.ex index f9eae8a..5614e2c 100644 --- a/lib/groupher_server/application.ex +++ b/lib/groupher_server/application.ex @@ -16,6 +16,7 @@ defmodule GroupherServer.Application do # Define workers and child supervisors to be supervised children = [ + {DNSCluster, query: Application.get_env(:groupher_server, :dns_cluster_query) || :ignore}, # Start the PubSub system {Phoenix.PubSub, name: MyApp.PubSub}, # Start the Ecto repository From 254f5f232a1898eba6da8a799a3289a95b94b455 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Sun, 24 Mar 2024 18:38:08 +0800 Subject: [PATCH 14/16] chore: wip --- config/config.exs | 2 +- lib/groupher_server_web/endpoint.ex | 20 ++++++++++---------- mix.exs | 2 ++ mix.lock | 3 +++ 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/config/config.exs b/config/config.exs index e63cfe1..8056e1e 100644 --- a/config/config.exs +++ b/config/config.exs @@ -11,7 +11,7 @@ config :groupher_server, ecto_repos: [GroupherServer.Repo] # Configures the endpoint config :groupher_server, GroupherServerWeb.Endpoint, url: [host: "localhost"], - secret_key_base: "Ru3N3sehqeuFjBV2Z6k7FuyA59fH8bWm8D4aZWu2RifP3xKMBYo3YRILrnXAGezM", + adapter: Bandit.PhoenixAdapter, render_errors: [view: GroupherServerWeb.ErrorView, accepts: ~w(json)], pubsub_server: GroupherServer.PubSub diff --git a/lib/groupher_server_web/endpoint.ex b/lib/groupher_server_web/endpoint.ex index 7f5c45f..d035aff 100644 --- a/lib/groupher_server_web/endpoint.ex +++ b/lib/groupher_server_web/endpoint.ex @@ -1,5 +1,5 @@ defmodule GroupherServerWeb.Endpoint do - use Sentry.PlugCapture + # use Sentry.PlugCapture use Phoenix.Endpoint, otp_app: :groupher_server socket("/socket", GroupherServerWeb.UserSocket) @@ -14,7 +14,7 @@ defmodule GroupherServerWeb.Endpoint do json_decoder: Jason ) - plug(Sentry.PlugContext) + # plug(Sentry.PlugContext) plug(Plug.MethodOverride) plug(Plug.Head) @@ -50,12 +50,12 @@ defmodule GroupherServerWeb.Endpoint do It receives the endpoint configuration and checks if configuration should be loaded from the system environment. """ - def init(_key, config) do - if config[:load_from_system_env] do - {:ok, - Keyword.put(config, :http, [:inet6, ip: {0, 0, 0, 0}, port: System.get_env("PORT") || 8080])} - else - {:ok, config} - end - end + # def init(_key, config) do + # if config[:load_from_system_env] do + # {:ok, + # Keyword.put(config, :http, [:inet6, ip: {0, 0, 0, 0}, port: System.get_env("PORT") || 8080])} + # else + # {:ok, config} + # end + # end end diff --git a/mix.exs b/mix.exs index 39df3a6..172758e 100644 --- a/mix.exs +++ b/mix.exs @@ -112,6 +112,8 @@ defmodule GroupherServer.Mixfile do {:fiet, "~> 0.3"}, {:ogp, "~> 1.0.0"}, {:ex_aliyun_openapi, "0.8.4"}, + {:dns_cluster, "~> 0.1.1"}, + {:bandit, "~> 1.2"}, {:aliyun_oss, "~> 2.0"} ] end diff --git a/mix.lock b/mix.lock index 9ab5f81..ff1339e 100644 --- a/mix.lock +++ b/mix.lock @@ -8,6 +8,7 @@ "apollo_tracing": {:hex, :apollo_tracing, "0.4.4", "de945527568e3377409377f5ed39b2f57a02adfa0ff19c33b232d201f45b83a1", [:mix], [{:absinthe, "~> 1.4", [hex: :absinthe, repo: "hexpm", optional: false]}, {:absinthe_plug, "~> 1.4", [hex: :absinthe_plug, repo: "hexpm", optional: true]}, {:jason, "~> 1.1", [hex: :jason, repo: "hexpm", optional: true]}], "hexpm", "9b6203b72ae582363fb5c9cabae6ed828276f2c54ee553fb11b9d5ab147db438"}, "argon2_elixir": {:hex, :argon2_elixir, "1.2.14", "0fc4bfbc1b7e459954987d3d2f3836befd72d63f3a355e3978f5005dd6e80816", [], [{:elixir_make, "~> 0.4", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm"}, "bamboo": {:hex, :bamboo, "1.3.0", "9ab7c054f1c3435464efcba939396c29c5e1b28f73c34e1f169e0881297a3141", [:mix], [{:hackney, ">= 1.13.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: false]}], "hexpm", "e1197188512d4a4458eaaad9a1659ce9eeb54a1b41574a9cd7507217b33e0f3e"}, + "bandit": {:hex, :bandit, "1.3.0", "6a4e8d7c9ea721edd02c389e2cc867890cd96f83116e71ddf1ccbdd80661550c", [:mix], [{:hpax, "~> 0.1.1", [hex: :hpax, repo: "hexpm", optional: false]}, {:plug, "~> 1.14", [hex: :plug, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}, {:thousand_island, "~> 1.0", [hex: :thousand_island, repo: "hexpm", optional: false]}, {:websock, "~> 0.5", [hex: :websock, repo: "hexpm", optional: false]}], "hexpm", "bda37d6c614d74778a5dc43b8bcdc3245cd30619eab0342f58042f968f2165da"}, "base64url": {:hex, :base64url, "0.0.1", "36a90125f5948e3afd7be97662a1504b934dd5dac78451ca6e9abf85a10286be", [:rebar], [], "hexpm", "fab09b20e3f5db886725544cbcf875b8e73ec93363954eb8a1a9ed834aa8c1f9"}, "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"}, "cachex": {:hex, :cachex, "3.3.0", "6f2ebb8f27491fe39121bd207c78badc499214d76c695658b19d6079beeca5c2", [:mix], [{:eternal, "~> 1.2", [hex: :eternal, repo: "hexpm", optional: false]}, {:jumper, "~> 1.0", [hex: :jumper, repo: "hexpm", optional: false]}, {:sleeplocks, "~> 1.1", [hex: :sleeplocks, repo: "hexpm", optional: false]}, {:unsafe, "~> 1.0", [hex: :unsafe, repo: "hexpm", optional: false]}], "hexpm", "d90e5ee1dde14cef33f6b187af4335b88748b72b30c038969176cd4e6ccc31a1"}, @@ -27,6 +28,7 @@ "db_connection": {:hex, :db_connection, "2.5.0", "bb6d4f30d35ded97b29fe80d8bd6f928a1912ca1ff110831edcd238a1973652c", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c92d5ba26cd69ead1ff7582dbb860adeedfff39774105a4f1c92cbb654b55aa2"}, "decimal": {:hex, :decimal, "1.9.0", "83e8daf59631d632b171faabafb4a9f4242c514b0a06ba3df493951c08f64d07", [:mix], [], "hexpm", "b1f2343568eed6928f3e751cf2dffde95bfaa19dd95d09e8a9ea92ccfd6f7d85"}, "dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"}, + "dns_cluster": {:hex, :dns_cluster, "0.1.3", "0bc20a2c88ed6cc494f2964075c359f8c2d00e1bf25518a6a6c7fd277c9b0c66", [:mix], [], "hexpm", "46cb7c4a1b3e52c7ad4cbe33ca5079fbde4840dedeafca2baf77996c2da1bc33"}, "earmark": {:hex, :earmark, "1.4.14", "d04572cef64dd92726a97d92d714e38d6e130b024ea1b3f8a56e7de66ec04e50", [:mix], [{:earmark_parser, ">= 1.4.12", [hex: :earmark_parser, repo: "hexpm", optional: false]}], "hexpm", "df338b8b1852ee425180b276c56c6941cb12220e04fe8718fe4acbdd35fd699f"}, "earmark_parser": {:hex, :earmark_parser, "1.4.12", "b245e875ec0a311a342320da0551da407d9d2b65d98f7a9597ae078615af3449", [:mix], [], "hexpm", "711e2cc4d64abb7d566d43f54b78f7dc129308a63bc103fbd88550d2174b3160"}, "ecto": {:hex, :ecto, "3.10.3", "eb2ae2eecd210b4eb8bece1217b297ad4ff824b4384c0e3fdd28aaf96edd6135", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "44bec74e2364d491d70f7e42cd0d690922659d329f6465e89feb8a34e8cd3433"}, @@ -114,6 +116,7 @@ "swarm": {:hex, :swarm, "3.4.0", "64f8b30055d74640d2186c66354b33b999438692a91be275bb89cdc7e401f448", [:mix], [{:gen_state_machine, "~> 2.0", [hex: :gen_state_machine, repo: "hexpm", optional: false]}, {:libring, "~> 1.0", [hex: :libring, repo: "hexpm", optional: false]}], "hexpm", "94884f84783fc1ba027aba8fe8a7dae4aad78c98e9f9c76667ec3471585c08c6"}, "telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"}, "tesla": {:hex, :tesla, "1.7.0", "a62dda2f80d4f8a925eb7b8c5b78c461e0eb996672719fe1a63b26321a5f8b4e", [:mix], [{:castore, "~> 0.1 or ~> 1.0", [hex: :castore, repo: "hexpm", optional: true]}, {:exjsx, ">= 3.0.0", [hex: :exjsx, repo: "hexpm", optional: true]}, {:finch, "~> 0.13", [hex: :finch, repo: "hexpm", optional: true]}, {:fuse, "~> 2.4", [hex: :fuse, repo: "hexpm", optional: true]}, {:gun, "~> 1.3", [hex: :gun, repo: "hexpm", optional: true]}, {:hackney, "~> 1.6", [hex: :hackney, repo: "hexpm", optional: true]}, {:ibrowse, "4.4.0", [hex: :ibrowse, repo: "hexpm", optional: true]}, {:jason, ">= 1.0.0", [hex: :jason, repo: "hexpm", optional: true]}, {:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:mint, "~> 1.0", [hex: :mint, repo: "hexpm", optional: true]}, {:msgpax, "~> 2.3", [hex: :msgpax, repo: "hexpm", optional: true]}, {:poison, ">= 1.0.0", [hex: :poison, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: true]}], "hexpm", "2e64f01ebfdb026209b47bc651a0e65203fcff4ae79c11efb73c4852b00dc313"}, + "thousand_island": {:hex, :thousand_island, "1.3.5", "6022b6338f1635b3d32406ff98d68b843ba73b3aa95cfc27154223244f3a6ca5", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "2be6954916fdfe4756af3239fb6b6d75d0b8063b5df03ba76fd8a4c87849e180"}, "timex": {:hex, :timex, "3.7.11", "bb95cb4eb1d06e27346325de506bcc6c30f9c6dea40d1ebe390b262fad1862d1", [:mix], [{:combine, "~> 0.10", [hex: :combine, repo: "hexpm", optional: false]}, {:gettext, "~> 0.20", [hex: :gettext, repo: "hexpm", optional: false]}, {:tzdata, "~> 1.1", [hex: :tzdata, repo: "hexpm", optional: false]}], "hexpm", "8b9024f7efbabaf9bd7aa04f65cf8dcd7c9818ca5737677c7b76acbc6a94d1aa"}, "tzdata": {:hex, :tzdata, "1.1.1", "20c8043476dfda8504952d00adac41c6eda23912278add38edc140ae0c5bcc46", [:mix], [{:hackney, "~> 1.17", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm", "a69cec8352eafcd2e198dea28a34113b60fdc6cb57eb5ad65c10292a6ba89787"}, "unicode_util_compat": {:hex, :unicode_util_compat, "0.7.0", "bc84380c9ab48177092f43ac89e4dfa2c6d62b40b8bd132b1059ecc7232f9a78", [:rebar3], [], "hexpm", "25eee6d67df61960cf6a794239566599b09e17e668d3700247bc498638152521"}, From cf63b21b2f95dba420612581fb166e7b541378c7 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Mon, 25 Mar 2024 11:02:38 +0800 Subject: [PATCH 15/16] chore: wip groupher_server config --- config/runtime.exs | 2 +- fly.toml | 6 +++--- lib/groupher_server/repo.ex | 6 +++--- mix.exs | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/config/runtime.exs b/config/runtime.exs index c73d8ed..514cca4 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -28,7 +28,7 @@ if config_env() == :prod do """ host = - System.get_env("PHX_HOST") || "groupher-server-withered-violet-5488-quiet-fog-9123.fly.dev" + System.get_env("PHX_HOST") || "groupher-server.fly.dev" port = String.to_integer(System.get_env("PORT") || "4000") diff --git a/fly.toml b/fly.toml index 543bf00..e1befc0 100644 --- a/fly.toml +++ b/fly.toml @@ -1,9 +1,9 @@ -# fly.toml app configuration file generated for groupher-server-withered-violet-5488-quiet-fog-9123 on 2024-03-03T20:11:00+08:00 +# fly.toml app configuration file generated for groupher-server on 2024-03-03T20:11:00+08:00 # # See https://fly.io/docs/reference/configuration/ for information about how to use this file. # -app = 'groupher-server-withered-violet-5488-quiet-fog-9123' +app = 'groupher-server' primary_region = 'hkg' kill_signal = 'SIGTERM' @@ -13,7 +13,7 @@ kill_signal = 'SIGTERM' release_command = '/app/bin/migrate' [env] - PHX_HOST = 'groupher-server-withered-violet-5488-quiet-fog-9123.fly.dev' + PHX_HOST = 'groupher-server.fly.dev' PORT = '8080' [http_service] diff --git a/lib/groupher_server/repo.ex b/lib/groupher_server/repo.ex index 5824131..9de4e50 100644 --- a/lib/groupher_server/repo.ex +++ b/lib/groupher_server/repo.ex @@ -10,7 +10,7 @@ defmodule GroupherServer.Repo do Dynamically loads the repository url from the DATABASE_URL environment variable. """ - def init(_, opts) do - {:ok, Keyword.put(opts, :url, System.get_env("DATABASE_URL"))} - end + # def init(_, opts) do + # {:ok, Keyword.put(opts, :url, System.get_env("DATABASE_URL"))} + # end end diff --git a/mix.exs b/mix.exs index 172758e..93abe7a 100644 --- a/mix.exs +++ b/mix.exs @@ -6,7 +6,7 @@ defmodule GroupherServer.Mixfile do def project do [ app: :groupher_server, - version: "2.1.2", + version: "2.1.3", elixir: "~> 1.9", elixirc_paths: elixirc_paths(Mix.env()), dialyzer: [plt_add_deps: :transitive, ignore_warnings: ".dialyzer_ignore.exs"], From 57ff89a7dac490cf10e8116cdf4f567377c6d665 Mon Sep 17 00:00:00 2001 From: mydearxym Date: Mon, 25 Mar 2024 14:53:27 +0800 Subject: [PATCH 16/16] chore: done --- config/runtime.exs | 13 ++++++------- .../cms/delegates/article_community.ex | 2 +- lib/helper/utils/utils.ex | 9 +++++++++ mix.exs | 2 +- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/config/runtime.exs b/config/runtime.exs index 514cca4..edd55f1 100644 --- a/config/runtime.exs +++ b/config/runtime.exs @@ -1,5 +1,7 @@ import Config +import Helper.Utils, only: [get_host_from_url: 1] + # ## Using releases # # If you use `mix release`, you need to explicitly enable the server @@ -123,16 +125,13 @@ if config_env() == :prod do # see https://neon.tech/docs/guides/elixir-ecto for Neon DB on vercel config :groupher_server, GroupherServer.Repo, adapter: Ecto.Adapters.Postgres, - username: System.get_env("DB_USERNAME"), - password: System.get_env("DB_PASSWORD"), - database: System.get_env("DB_NAME" || "cps_server_prod"), - hostname: System.get_env("DB_HOST"), - port: String.to_integer(System.get_env("DB_PORT") || "5432"), + url: System.get_env("DATABASE_URL"), pool_size: String.to_integer(System.get_env("DB_POOL_SIZE") || "20"), ssl: true, ssl_opts: [ - # server_name_indication: String.to_charlist("debug here if need"), - server_name_indication: System.get_env("DB_HOST") |> String.to_charlist(), + # server_name_indication: System.get_env("DB_HOST") |> String.to_charlist(), + server_name_indication: + get_host_from_url(System.get_env("DATABASE_URL")) |> String.to_charlist(), verify: :verify_none ] diff --git a/lib/groupher_server/cms/delegates/article_community.ex b/lib/groupher_server/cms/delegates/article_community.ex index c4bac8a..bf25eb1 100644 --- a/lib/groupher_server/cms/delegates/article_community.ex +++ b/lib/groupher_server/cms/delegates/article_community.ex @@ -6,7 +6,7 @@ defmodule GroupherServer.CMS.Delegate.ArticleCommunity do import Ecto.Query, warn: false import Helper.ErrorCode - import Helper.Utils, only: [strip_struct: 1, done: 1] + import Helper.Utils, only: [done: 1] import GroupherServer.CMS.Helper.Matcher alias Helper.Types, as: T diff --git a/lib/helper/utils/utils.ex b/lib/helper/utils/utils.ex index 871967e..d11b5a7 100644 --- a/lib/helper/utils/utils.ex +++ b/lib/helper/utils/utils.ex @@ -235,4 +235,13 @@ defmodule Helper.Utils do # number is invalid for html id(if first letter) Nanoid.generate(5, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ") end + + @doc """ + get host from url for config, like + postgres://default:blajdife@example-db-host.aws.neon.tech:5432/verceldb?sslmode=require + => example-db-host + """ + def get_host_from_url(url) do + URI.parse(url).host + end end diff --git a/mix.exs b/mix.exs index 93abe7a..0482521 100644 --- a/mix.exs +++ b/mix.exs @@ -6,7 +6,7 @@ defmodule GroupherServer.Mixfile do def project do [ app: :groupher_server, - version: "2.1.3", + version: "2.1.4", elixir: "~> 1.9", elixirc_paths: elixirc_paths(Mix.env()), dialyzer: [plt_add_deps: :transitive, ignore_warnings: ".dialyzer_ignore.exs"],