浏览代码

Setup production release

theenglishway (time) 4 年之前
父节点
当前提交
2a84cd665d
共有 4 个文件被更改,包括 37 次插入15 次删除
  1. 6 6
      README.md
  2. 1 3
      config/prod.exs
  3. 2 6
      config/prod.secret.exs
  4. 28 0
      config/releases.exs

+ 6 - 6
README.md

@@ -10,10 +10,10 @@ Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.
 
 Ready to run in production? Please [check our deployment guides](https://hexdocs.pm/phoenix/deployment.html).
 
-## Learn more
+## Production
 
-  * Official website: https://www.phoenixframework.org/
-  * Guides: https://hexdocs.pm/phoenix/overview.html
-  * Docs: https://hexdocs.pm/phoenix
-  * Forum: https://elixirforum.com/c/phoenix-forum
-  * Source: https://github.com/phoenixframework/phoenix
+Generate a secret key with : `mix phx.gen.secret`
+
+Compile and make release with : `MIX_ENV=prod SECRET_KEY_BASE=xxx mix release`
+
+Get external IP address and run production server : `HOST_IP=xxx PORT=xxx _build/prod/rel/vaccins/bin/vaccins start`

+ 1 - 3
config/prod.exs

@@ -9,9 +9,7 @@ use Mix.Config
 # manifest is generated by the `mix phx.digest` task,
 # which you should run after static files are built and
 # before starting your production server.
-config :vaccins, VaccinsWeb.Endpoint,
-  url: [host: "example.com", port: 80],
-  cache_static_manifest: "priv/static/cache_manifest.json"
+config :vaccins, VaccinsWeb.Endpoint, cache_static_manifest: "priv/static/cache_manifest.json"
 
 # Do not print debug messages in production
 config :logger, level: :info

+ 2 - 6
config/prod.secret.exs

@@ -11,12 +11,7 @@ secret_key_base =
     You can generate one by calling: mix phx.gen.secret
     """
 
-config :vaccins, VaccinsWeb.Endpoint,
-  http: [
-    port: String.to_integer(System.get_env("PORT") || "4000"),
-    transport_options: [socket_opts: [:inet6]]
-  ],
-  secret_key_base: secret_key_base
+config :vaccins, VaccinsWeb.Endpoint, secret_key_base: secret_key_base
 
 # ## Using releases (Elixir v1.9+)
 #
@@ -27,3 +22,4 @@ config :vaccins, VaccinsWeb.Endpoint,
 #
 # Then you can assemble a release by calling `mix release`.
 # See `mix help release` for more information.
+config :vaccins, VaccinsWeb.Endpoint, server: true

+ 28 - 0
config/releases.exs

@@ -0,0 +1,28 @@
+# In this file, we load production configuration and secrets
+# from environment variables. You can also hardcode secrets,
+# although such is generally not recommended and you have to
+# remember to add this file to your .gitignore.
+import Config
+
+host_ip =
+  System.get_env("HOST_IP") ||
+    raise "environment variable HOST_IP is missing."
+
+port =
+  System.get_env("PORT") ||
+    raise "environment variable PORT is missing."
+
+config :vaccins, VaccinsWeb.Endpoint,
+  url: [host: host_ip, port: port],
+  http: [
+    port: String.to_integer(port),
+    net: :inet,
+    transport_options: [socket_opts: [:inet6]]
+  ],
+  check_origin: [
+    "http://localhost:#{port}",
+    "http://192.168.0.13:#{port}",
+    "http://#{host_ip}:#{port}"
+  ]
+
+config :vaccins, VaccinsWeb.Endpoint, server: true