From 527170e79bea6de74892923f04a0e2f12f145548 Mon Sep 17 00:00:00 2001 From: liamwhite Date: Mon, 3 Aug 2020 15:37:02 -0400 Subject: [PATCH] Mix releases (#13) --- config/prod.exs | 4 --- config/prod.secret.exs | 77 ------------------------------------------ config/releases.exs | 60 ++++++++++++++++++++++++++++++++ mix.exs | 3 +- mix.lock | 1 - post-receive | 18 +++++----- rel/config.exs | 59 -------------------------------- rel/plugins/.gitignore | 3 -- rel/vm.args | 30 ---------------- 9 files changed, 70 insertions(+), 185 deletions(-) delete mode 100644 config/prod.secret.exs create mode 100644 config/releases.exs delete mode 100644 rel/config.exs delete mode 100644 rel/plugins/.gitignore delete mode 100644 rel/vm.args diff --git a/config/prod.exs b/config/prod.exs index 8dbbd841..3a7bfce0 100644 --- a/config/prod.exs +++ b/config/prod.exs @@ -49,7 +49,3 @@ config :logger, level: :warn # force_ssl: [hsts: true] # # Check `Plug.SSL` for all available options in `force_ssl`. - -# Finally import the config/prod.secret.exs which loads secrets -# and configuration from environment variables. -import_config "prod.secret.exs" diff --git a/config/prod.secret.exs b/config/prod.secret.exs deleted file mode 100644 index ef81571a..00000000 --- a/config/prod.secret.exs +++ /dev/null @@ -1,77 +0,0 @@ -# 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 - -database_url = - System.get_env("DATABASE_URL") || - raise """ - environment variable DATABASE_URL is missing. - For example: ecto://USER:PASS@HOST/DATABASE - """ - -config :bcrypt_elixir, - log_rounds: String.to_integer(System.get_env("BCRYPT_ROUNDS") || "12") - -config :philomena, - channel_image_file_root: System.get_env("CHANNEL_IMAGE_FILE_ROOT"), - channel_banner_file_root: System.get_env("CHANNEL_BANNER_FILE_ROOT"), - anonymous_name_salt: System.get_env("ANONYMOUS_NAME_SALT"), - advert_file_root: System.get_env("ADVERT_FILE_ROOT"), - avatar_file_root: System.get_env("AVATAR_FILE_ROOT"), - channel_url_root: System.get_env("CHANNEL_URL_ROOT"), - badge_file_root: System.get_env("BADGE_FILE_ROOT"), - password_pepper: System.get_env("PASSWORD_PEPPER"), - avatar_url_root: System.get_env("AVATAR_URL_ROOT"), - advert_url_root: System.get_env("ADVERT_URL_ROOT"), - image_file_root: System.get_env("IMAGE_FILE_ROOT"), - tumblr_api_key: System.get_env("TUMBLR_API_KEY"), - otp_secret_key: System.get_env("OTP_SECRET_KEY"), - image_url_root: System.get_env("IMAGE_URL_ROOT"), - badge_url_root: System.get_env("BADGE_URL_ROOT"), - mailer_address: System.get_env("MAILER_ADDRESS"), - tag_file_root: System.get_env("TAG_FILE_ROOT"), - tag_url_root: System.get_env("TAG_URL_ROOT"), - proxy_host: System.get_env("PROXY_HOST"), - camo_host: System.get_env("CAMO_HOST"), - camo_key: System.get_env("CAMO_KEY"), - cdn_host: System.get_env("CDN_HOST") - -config :philomena, Philomena.Repo, - # ssl: true, - url: database_url, - pool_size: String.to_integer(System.get_env("POOL_SIZE") || "32") - -config :philomena, Philomena.Mailer, - adapter: Bamboo.SMTPAdapter, - server: System.get_env("SMTP_RELAY"), - hostname: System.get_env("SMTP_DOMAIN"), - port: System.get_env("SMTP_PORT") || 587, - username: System.get_env("SMTP_USERNAME"), - password: System.get_env("SMTP_PASSWORD"), - tls: :always, - auth: :always - -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 :philomena, PhilomenaWeb.Endpoint, - http: [ip: {127, 0, 0, 1}, port: {:system, "PORT"}], - url: [host: System.get_env("APP_HOSTNAME"), scheme: "https", port: 443], - secret_key_base: secret_key_base, - server: true - -# ## Using releases (Elixir v1.9+) -# -# If you are doing OTP releases, you need to instruct Phoenix -# to start each relevant endpoint: -# -# config :philomena, PhilomenaWeb.Endpoint, server: true -# -# Then you can assemble a release by calling `mix release`. -# See `mix help release` for more information. diff --git a/config/releases.exs b/config/releases.exs new file mode 100644 index 00000000..86248c91 --- /dev/null +++ b/config/releases.exs @@ -0,0 +1,60 @@ +import Config + +# ## Using releases (Elixir v1.9+) +# +# If you are doing OTP releases, you need to instruct Phoenix +# to start each relevant endpoint: +# +# config :philomena, PhilomenaWeb.Endpoint, server: true +# +# Then you can assemble a release by calling `mix release`. +# See `mix help release` for more information. + +config :bcrypt_elixir, + log_rounds: String.to_integer(System.get_env("BCRYPT_ROUNDS") || "12") + +config :philomena, + channel_image_file_root: System.fetch_env!("CHANNEL_IMAGE_FILE_ROOT"), + channel_banner_file_root: System.fetch_env!("CHANNEL_BANNER_FILE_ROOT"), + anonymous_name_salt: System.fetch_env!("ANONYMOUS_NAME_SALT"), + elasticsearch_url: System.get_env("ELASTICSEARCH_URL") || "http://localhost:9200", + advert_file_root: System.fetch_env!("ADVERT_FILE_ROOT"), + avatar_file_root: System.fetch_env!("AVATAR_FILE_ROOT"), + channel_url_root: System.fetch_env!("CHANNEL_URL_ROOT"), + badge_file_root: System.fetch_env!("BADGE_FILE_ROOT"), + password_pepper: System.fetch_env!("PASSWORD_PEPPER"), + avatar_url_root: System.fetch_env!("AVATAR_URL_ROOT"), + advert_url_root: System.fetch_env!("ADVERT_URL_ROOT"), + image_file_root: System.fetch_env!("IMAGE_FILE_ROOT"), + tumblr_api_key: System.fetch_env!("TUMBLR_API_KEY"), + otp_secret_key: System.fetch_env!("OTP_SECRET_KEY"), + image_url_root: System.fetch_env!("IMAGE_URL_ROOT"), + badge_url_root: System.fetch_env!("BADGE_URL_ROOT"), + mailer_address: System.fetch_env!("MAILER_ADDRESS"), + tag_file_root: System.fetch_env!("TAG_FILE_ROOT"), + tag_url_root: System.fetch_env!("TAG_URL_ROOT"), + redis_host: System.get_env("REDIS_HOST") || "localhost", + proxy_host: System.get_env("PROXY_HOST"), + camo_host: System.fetch_env!("CAMO_HOST"), + camo_key: System.fetch_env!("CAMO_KEY"), + cdn_host: System.fetch_env!("CDN_HOST") + +config :philomena, Philomena.Repo, + url: System.fetch_env!("DATABASE_URL"), + pool_size: String.to_integer(System.get_env("POOL_SIZE") || "32") + +config :philomena, Philomena.Mailer, + adapter: Bamboo.SMTPAdapter, + server: System.fetch_env!("SMTP_RELAY"), + hostname: System.fetch_env!("SMTP_DOMAIN"), + port: System.get_env("SMTP_PORT") || 587, + username: System.fetch_env!("SMTP_USERNAME"), + password: System.fetch_env!("SMTP_PASSWORD"), + tls: :always, + auth: :always + +config :philomena, PhilomenaWeb.Endpoint, + http: [ip: {127, 0, 0, 1}, port: {:system, "PORT"}], + url: [host: System.fetch_env!("APP_HOSTNAME"), scheme: "https", port: 443], + secret_key_base: System.fetch_env!("SECRET_KEY_BASE"), + server: true diff --git a/mix.exs b/mix.exs index efe2d100..3249a15c 100644 --- a/mix.exs +++ b/mix.exs @@ -4,7 +4,7 @@ defmodule Philomena.MixProject do def project do [ app: :philomena, - version: "0.1.0", + version: "1.1.0", elixir: "~> 1.5", elixirc_paths: elixirc_paths(Mix.env()), compilers: [:phoenix, :gettext] ++ Mix.compilers(), @@ -61,7 +61,6 @@ defmodule Philomena.MixProject do {:briefly, "~> 0.3.0"}, {:phoenix_mtm, "~> 1.0.0"}, {:yaml_elixir, "~> 2.4.0"}, - {:distillery, "~> 2.1"}, {:ranch_connection_drainer, "~> 0.1"}, {:tesla, "~> 1.3"}, {:castore, "~> 0.1"}, diff --git a/mix.lock b/mix.lock index 79121f87..1a569eef 100644 --- a/mix.lock +++ b/mix.lock @@ -16,7 +16,6 @@ "db_connection": {:hex, :db_connection, "2.2.2", "3bbca41b199e1598245b716248964926303b5d4609ff065125ce98bcd368939e", [:mix], [{:connection, "~> 1.0.2", [hex: :connection, repo: "hexpm", optional: false]}], "hexpm", "642af240d8a8affb93b4ba5a6fcd2bbcbdc327e1a524b825d383711536f8070c"}, "decimal": {:hex, :decimal, "1.8.1", "a4ef3f5f3428bdbc0d35374029ffcf4ede8533536fa79896dd450168d9acdf3c", [:mix], [], "hexpm", "3cb154b00225ac687f6cbd4acc4b7960027c757a5152b369923ead9ddbca7aec"}, "dialyxir": {:hex, :dialyxir, "1.0.0", "6a1fa629f7881a9f5aaf3a78f094b2a51a0357c843871b8bc98824e7342d00a5", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "aeb06588145fac14ca08d8061a142d52753dbc2cf7f0d00fc1013f53f8654654"}, - "distillery": {:hex, :distillery, "2.1.1", "f9332afc2eec8a1a2b86f22429e068ef35f84a93ea1718265e740d90dd367814", [:mix], [{:artificery, "~> 0.2", [hex: :artificery, repo: "hexpm", optional: false]}], "hexpm", "bbc7008b0161a6f130d8d903b5b3232351fccc9c31a991f8fcbf2a12ace22995"}, "ecto": {:hex, :ecto, "3.4.5", "2bcd262f57b2c888b0bd7f7a28c8a48aa11dc1a2c6a858e45dd8f8426d504265", [: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", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "8c6d1d4d524559e9b7a062f0498e2c206122552d63eacff0a6567ffe7a8e8691"}, "ecto_network": {:hex, :ecto_network, "1.3.0", "1e77fa37c20e0f6a426d3862732f3317b0fa4c18f123d325f81752a491d7304e", [:mix], [{:ecto_sql, ">= 3.0.0", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:phoenix_html, ">= 0.0.0", [hex: :phoenix_html, repo: "hexpm", optional: true]}, {:postgrex, ">= 0.14.0", [hex: :postgrex, repo: "hexpm", optional: false]}], "hexpm", "053a5e46ef2837e8ea5ea97c82fa0f5494699209eddd764e663c85f11b2865bd"}, "ecto_sql": {:hex, :ecto_sql, "3.4.5", "30161f81b167d561a9a2df4329c10ae05ff36eca7ccc84628f2c8b9fa1e43323", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.4.3", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.3.0 or ~> 0.4.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.0", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "31990c6a3579b36a3c0841d34a94c275e727de8b84f58509da5f1b2032c98ac2"}, diff --git a/post-receive b/post-receive index 0849bcd3..a3078e8e 100755 --- a/post-receive +++ b/post-receive @@ -35,14 +35,14 @@ if git diff --name-only $oldrev $newrev | grep "^assets/"; then mix phx.digest || die "assets compile failed" fi -# TODO: fix this when I can figure out how to avoid recompiling -# the entire project when the version changes -# -# # Generate release name to always be the current timestamp so that -# # it will be considered an upgrade -# export PHILOMENA_VERSION="0.1.$(date +%s)" - echo "Building release" -mix distillery.release --quiet || die "failed to generate release" +mix release --overwrite || die "failed to generate release" -_build/prod/rel/philomena/bin/philomena reboot || die "failed to upgrade app; log in to the server and restart the app manually" +# Include a task to restart your running appserver instances here. +# +# In general, you should have many app instances configured on different +# ports using the PORT environment variable, so as to allow you to roll +# releases and deploy new code with no visible downtime. +# +# You can use a reverse proxy like haproxy or nginx to load balance between +# different server instances automatically. diff --git a/rel/config.exs b/rel/config.exs deleted file mode 100644 index 819bf4a3..00000000 --- a/rel/config.exs +++ /dev/null @@ -1,59 +0,0 @@ -# Import all plugins from `rel/plugins` -# They can then be used by adding `plugin MyPlugin` to -# either an environment, or release definition, where -# `MyPlugin` is the name of the plugin module. -~w(rel plugins *.exs) -|> Path.join() -|> Path.wildcard() -|> Enum.map(&Code.eval_file(&1)) - -use Distillery.Releases.Config, - # This sets the default release built by `mix distillery.release` - default_release: :default, - # This sets the default environment used by `mix distillery.release` - default_environment: Mix.env() - -# For a full list of config options for both releases -# and environments, visit https://hexdocs.pm/distillery/config/distillery.html - - -# You may define one or more environments in this file, -# an environment's settings will override those of a release -# when building in that environment, this combination of release -# and environment configuration is called a profile - -environment :dev do - # If you are running Phoenix, you should make sure that - # server: true is set and the code reloader is disabled, - # even in dev mode. - # It is recommended that you build with MIX_ENV=prod and pass - # the --env flag to Distillery explicitly if you want to use - # dev mode. - set dev_mode: true - set include_erts: false - set cookie: :"5MEZn{TTU:$GyE/DgOAV0GhEWU>Gj>YwWXmo&pd3t~L8gHVrlSR>8W9API~YL=&^" -end - -# N.B.: this cookie has to do with how distributed Erlang authenticates -# communication between nodes. With correct firewall configuration, you do not -# need to change it. -environment :prod do - set include_erts: true - set include_src: false - set cookie: :";?PAn6iwn<<(~GAez2sS/|aNd{tV(k7j%0v3`eD]YN}Ii@?ws$RW|%iuBD - -## Heartbeat management; auto-restarts VM if it dies or becomes unresponsive -## (Disabled by default..use with caution!) -##-heart - -## Enable kernel poll and a few async threads -##+K true -##+A 5 -## For OTP21+, the +A flag is not used anymore, -## +SDio replace it to use dirty schedulers -##+SDio 5 - -## Increase number of concurrent ports/sockets -##-env ERL_MAX_PORTS 4096 - -## Tweak GC to run more often -##-env ERL_FULLSWEEP_AFTER 10 - -# Enable SMP automatically based on availability -# On OTP21+, this is not needed anymore. --smp auto