From 26649c1fea49012b68ce6b9bf19c279e0eda1a80 Mon Sep 17 00:00:00 2001 From: Jason Stiebs Date: Tue, 17 May 2016 10:18:12 -0500 Subject: [PATCH 01/16] Releasing, exrm and ssl MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://dash.readme.io/project/phoenixframework/v1.1.4/suggested/update/5738581913fb8f0e00999b55 As I run into some errors with my release and ssl app, I thought I shared some insight. Might also apply to release with exrm section. But people who want to do ssl are propably more likely to look under the ssl section for troubleshooting, so suggesting it here. -Milan Köpke --- bonus_guides/P_using_ssl.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/bonus_guides/P_using_ssl.md b/bonus_guides/P_using_ssl.md index b61b8cde..04e05864 100644 --- a/bonus_guides/P_using_ssl.md +++ b/bonus_guides/P_using_ssl.md @@ -26,3 +26,17 @@ Without the `otp_app:` key, we need to provide absolute paths to the files where ```elixir Path.expand("../../../some/path/to/ssl/key.pem", __DIR__) ``` + +Releasing with Exrm: + +In order to build and run a release with exrm, make sure you also include the ssl app in `mix.exs`: + +```elixir +def application do + [mod: {HelloPhoenix, []}, + applications: [:phoenix, :phoenix_html, :cowboy, :logger, :gettext, + :phoenix_ecto, :postgrex, :ssl]] +end +``` + +Else you might run into errors: `** (MatchError) no match of right hand side value: {:error, {:ssl, {'no such file or directory', 'ssl.app'}}}` From e117f95a9d6ecdf38f587b4ae00c8746285df927 Mon Sep 17 00:00:00 2001 From: Jason Stiebs Date: Tue, 17 May 2016 10:23:07 -0500 Subject: [PATCH 02/16] Various Fomatting changes https://dash.readme.io/project/phoenixframework/v1.1.4/suggested/update/57321cdea825f30e00b51b68% https://dash.readme.io/project/phoenixframework/v1.1.4/suggested/update/57321c110ef9be17002c7148 https://dash.readme.io/project/phoenixframework/v1.1.4/suggested/update/57321b85752a1f190012eb2b -Filip Allberg --- A_up_and_running.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/A_up_and_running.md b/A_up_and_running.md index 1c2f5787..56842ada 100644 --- a/A_up_and_running.md +++ b/A_up_and_running.md @@ -117,6 +117,6 @@ By default Phoenix accepts requests on port 4000. If we point our favorite web b If your screen looks like the image above, congratulations! You now have a working Phoenix application. In case you can't see the page above, try accessing it via [http://127.0.0.1:4000](http://127.0.0.1:4000) and later make sure your OS has defined "localhost" as "127.0.0.1". -Locally, our application is running in an iex session. To stop it, we hit ctrl-c twice, just as we would to stop iex normally. +Locally, our application is running in an `iex` session. To stop it, we hit `ctrl-c` twice, just as we would to stop `iex` normally. -The next step is customizing our application just a bit to give us a sense of how a Phoenix app is put together. +The [The next step step](http://www.phoenixframework.org/docs/adding-pages) is customizing our application just a bit to give us a sense of how a Phoenix app is put together. From c34a9eca0127c3982dc1ce9eef86d96b58266533 Mon Sep 17 00:00:00 2001 From: Jason Stiebs Date: Tue, 17 May 2016 10:27:15 -0500 Subject: [PATCH 03/16] Guide Typo https://dash.readme.io/project/phoenixframework/v1.1.4/suggested/update/5717c8caa096be0e001af27b Jeff Owens --- deployment/I_exrm_releases.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/I_exrm_releases.md b/deployment/I_exrm_releases.md index 66504ec8..e04a4717 100644 --- a/deployment/I_exrm_releases.md +++ b/deployment/I_exrm_releases.md @@ -246,7 +246,7 @@ drwxr-xr-x 8 lance staff 272 May 13 18:47 0.0.1 -rw-r--r-- 1 lance staff 9 May 13 18:47 start_erl.data ``` -The `hello_phoenix-0.0.1.tar.gz` tarball in `rel/hello_phoenix` is our release in archive form, ready to be shipped off to our hosting environment. +The `hello_phoenix-0.0.1.tar.gz` tarball in `rel/hello_phoenix/releases/0.0.1` is our release in archive form, ready to be shipped off to our hosting environment. ### Testing Our Release From e2f307e11de85a123751452b5808597085ae51a3 Mon Sep 17 00:00:00 2001 From: Jason Stiebs Date: Tue, 17 May 2016 10:28:49 -0500 Subject: [PATCH 04/16] Heroku guide improvement https://dash.readme.io/project/phoenixframework/v1.1.4/suggested/update/571388a645e2090e001e5c50 -- Andrey Voronkov --- deployment/E_heroku.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deployment/E_heroku.md b/deployment/E_heroku.md index 4a0c4a27..5d8fd484 100644 --- a/deployment/E_heroku.md +++ b/deployment/E_heroku.md @@ -153,7 +153,7 @@ config :hello_phoenix, HelloPhoenix.Repo, ssl: true ``` -Finally, we need to decrease the timeout for the websocket transport: +Finally, we need to decrease the timeout for the websocket transport in `web/channels/user_socket.ex`: ```elixir defmodule HelloPhoenix.UserSocket do From 60d96641d4b62cf177a60f8182a7b3a9191782e3 Mon Sep 17 00:00:00 2001 From: Jason Stiebs Date: Tue, 17 May 2016 10:30:09 -0500 Subject: [PATCH 05/16] Add () to preload in pipes https://dash.readme.io/project/phoenixframework/v1.1.4/suggested/update/570ef7114a84800e0059a99d --Stephen Schor --- H_ecto_models.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/H_ecto_models.md b/H_ecto_models.md index 5450ca04..5bc14ff1 100644 --- a/H_ecto_models.md +++ b/H_ecto_models.md @@ -593,12 +593,12 @@ We can use our newly declared relationships in our `web/controllers/user_control defmodule HelloPhoenix.UserController do . . . def index(conn, _params) do - users = User |> Repo.all |> Repo.preload [:videos] + users = User |> Repo.all |> Repo.preload([:videos]) render(conn, "index.html", users: users) end def show(conn, %{"id" => id}) do - user = User |> Repo.get!(id) |> Repo.preload [:videos] + user = User |> Repo.get!(id) |> Repo.preload([:videos]) render(conn, "show.html", user: user) end . . . From 0d13764e1624adf503f9c754ad170d017b635c5b Mon Sep 17 00:00:00 2001 From: Jason Stiebs Date: Tue, 17 May 2016 10:31:26 -0500 Subject: [PATCH 06/16] Note about brunch https://dash.readme.io/project/phoenixframework/v1.1.4/suggested/update/57046a78849f721900f27772 Michael Johnston --- bonus_guides/G_static_assets.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bonus_guides/G_static_assets.md b/bonus_guides/G_static_assets.md index 9131fc0c..8da4c995 100644 --- a/bonus_guides/G_static_assets.md +++ b/bonus_guides/G_static_assets.md @@ -150,7 +150,7 @@ Important detail: according to the default configuration there is no ES6 support #### JavaScript Libraries -We may need to use a JavaScript library like jQuery or underscore in our application. As we mentioned above, we could copy the libraries into `web/static/vendor`. It may be a little bit easier to use `npm` to install it: We can simply add `"jquery": ">= 2.1"` to the dependencies in the `package.json` file in our projects root and run `npm install --save`. Now we can `import $ from "jquery"` in our `app.js`. +We may need to use a JavaScript library like jQuery or underscore in our application. As we mentioned above, we could copy the libraries into `web/static/vendor`. It may be a little bit easier to use `npm` to install it: We can simply add `"jquery": ">= 2.1"` to the dependencies in the `package.json` file in our projects root and run `npm install --save`. If the `npm` section in our `brunch-config.js` has a `whitelist` property, we will also need to add "jquery" to that. Now we can `import $ from "jquery"` in our `app.js`. #### Brunch Plugin Pipeline From 06d3344eef9339b0f30e44dffdadc5a2923c91d3 Mon Sep 17 00:00:00 2001 From: Jason Stiebs Date: Tue, 17 May 2016 10:35:26 -0500 Subject: [PATCH 07/16] Skeleton Installing instructions https://dash.readme.io/project/phoenixframework/v1.1.4/suggested/update/56fdb05fe7f3080e008e3f13 -- Brian --- introduction/E_installation.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/introduction/E_installation.md b/introduction/E_installation.md index 26eeaa57..e022b577 100644 --- a/introduction/E_installation.md +++ b/introduction/E_installation.md @@ -84,3 +84,9 @@ Postgrex is a direct Phoenix dependency, and it will be automatically installed This is a Linux-only filesystem watcher that Phoenix uses for live code reloading. (Mac OS X or Windows users can safely ignore it.) Linux users need to install this dependency. Please consult the [inotify-tools wiki](https://github.com/rvoicilas/inotify-tools/wiki) for distribution-specific installation instructions. + +### Skeleton Installation + +Sometimes you want an installation without anything except the bare minimum phoenix setup. The follow command will give you that. + +`mix phoenix.new web --no-brunch --no-ecto` From 3e714f99accd02c7cb32d09975a011a051ec6129 Mon Sep 17 00:00:00 2001 From: Jason Stiebs Date: Tue, 17 May 2016 10:46:56 -0500 Subject: [PATCH 08/16] Adds instructions to override the root path of the project in config/prod.exs so that static assets will correctly update during a hot upgrade. See https://github.com/bitwalker/exrm/issues/206 for additional details. https://dash.readme.io/project/phoenixframework/v1.1.4/suggested/update/5617e0e326e3db230054fbf9 -- Jason Harrelson --- deployment/I_exrm_releases.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/deployment/I_exrm_releases.md b/deployment/I_exrm_releases.md index e04a4717..5d35cb0e 100644 --- a/deployment/I_exrm_releases.md +++ b/deployment/I_exrm_releases.md @@ -65,19 +65,22 @@ Doing this helps us overcome one of [exrm's common issues](https://hexdocs.pm/ex Even if we list all of our dependencies, our application may still fail. Typically, this happens because one of our dependencies does not properly list its own dependencies. A quick fix for this is to include the missing dependency or dependencies in our list of applications. If this happens to you, and you feel like helping the community, you can create an issue or a pull request to that project's repo. -We also need to configure our Endpoint to act as a server in `config/prod.exs`. +Within `config/prod.exs` we need to make two changes. First we must configure our Endpoint to act as a server `server: true`. Additionally we must set the root to be `.`. ```elixir # Configures the endpoint config :hello_phoenix, HelloPhoenix.Endpoint, http: [port: 8888], url: [host: "example.com"], +root: ".", cache_static_manifest: "priv/static/manifest.json", server: true ``` When we run `mix phoenix.server` to start our application, the `server` parameter is automatically set to true. When we're creating a release, however, we need to configure this manually. If we get through this release guide, and we aren't seeing any pages coming from our server, this is a likely culprit. +When generating a release and performing a hot upgrade, the static assets being served will not be the newest version without setting the root to `.`. If you do not set root to `.` you will be forced to perform a restart so that the correct static assets are served, effectively changing the hot upgrade to a rolling restart. + If we take a quick look at our `config/prod.exs` again, we'll see that our port is set to `8888`. ```elixir From 9daa030f9a9f16a2230bf62a67d42a8bb9af60b1 Mon Sep 17 00:00:00 2001 From: Jason Stiebs Date: Tue, 17 May 2016 10:51:58 -0500 Subject: [PATCH 09/16] Some psql suggested edits https://dash.readme.io/project/phoenixframework/v1.1.4/suggested/update/566a38991e08750d00a0c4a2 Greg Mefford --- bonus_guides/D_mix_tasks.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bonus_guides/D_mix_tasks.md b/bonus_guides/D_mix_tasks.md index abbf07ec..55dcca69 100644 --- a/bonus_guides/D_mix_tasks.md +++ b/bonus_guides/D_mix_tasks.md @@ -508,7 +508,7 @@ $ mix ecto.create ** (Mix) The database for HelloPhoenix.Repo couldn't be created, reason given: psql: FATAL: role "postgres" does not exist ``` -We can fix this by creating the "postgres" role with the permissions needed to log in and create a database. +We can fix this by creating the "postgres" role in the `psql` console with the permissions needed to log in and create a database. ```console =# CREATE ROLE postgres LOGIN CREATEDB; @@ -536,7 +536,7 @@ $ mix ecto.create ** (Mix) The database for HelloPhoenix.Repo couldn't be created, reason given: ERROR: permission denied to create database ``` -To fix this, we need to change the permissions on our "postgres" user to allow database creation. +To fix this, we need to change the permissions on our "postgres" user in the `psql` console to allow database creation. ```console =# ALTER ROLE postgres CREATEDB; From 1cc0a440313c03b86e893c1ca1e840a86ad2e8b3 Mon Sep 17 00:00:00 2001 From: Jason Stiebs Date: Tue, 17 May 2016 10:54:07 -0500 Subject: [PATCH 10/16] URL over PATH for emails https://dash.readme.io/project/phoenixframework/v1.1.4/suggested/update/56918b383490d80d004185f0 --- bonus_guides/I_sending_email.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bonus_guides/I_sending_email.md b/bonus_guides/I_sending_email.md index 00b5eca3..92487f5a 100644 --- a/bonus_guides/I_sending_email.md +++ b/bonus_guides/I_sending_email.md @@ -323,7 +323,7 @@ We'll also need a new `email` directory in `web/templates` with a `welcome.html. > Note: If we need to use any path or url helpers in our template, we will need to pass the endpoint instead of a connection struct for the first argument. This is because we won't be in the context of a request, so `@conn` won't be available. For example, we will need to write this ```elixir alias HelloPhoenix -Router.Helpers.page_path(Endpoint, :index) +Router.Helpers.page_url(Endpoint, :index) ``` instead of this. ```elixir From 66e473dbba7b91b3415b38cac17aed096e9ab0e3 Mon Sep 17 00:00:00 2001 From: Jason Stiebs Date: Tue, 17 May 2016 10:57:08 -0500 Subject: [PATCH 11/16] Typo fix https://dash.readme.io/project/phoenixframework/v1.1.4/suggested/update/56aed47dbc304a0d00ace09f --- C_routing.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/C_routing.md b/C_routing.md index 7ba6e49d..069981e6 100644 --- a/C_routing.md +++ b/C_routing.md @@ -85,7 +85,7 @@ page_path GET / HelloPhoenix.PageController :index ``` The output tells us that any HTTP GET request for the root of the application will be handled by the `index` action of the `HelloPhoenix.PageController`. -`page_path` is an example of a what Phoenix calls a path helper, and we'll talk about those very soon. +`page_path` is an example of what Phoenix calls a path helper, and we'll talk about those very soon. ### Resources From 1ed18c094e7d7caa7102fc8c24eb07b9fc5afc06 Mon Sep 17 00:00:00 2001 From: Jason Stiebs Date: Tue, 17 May 2016 10:58:49 -0500 Subject: [PATCH 12/16] Adding information about convig_vars_to_export https://dash.readme.io/project/phoenixframework/v1.1.4/suggested/update/56bb3b9d68be933500aeea53 --- deployment/E_heroku.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/deployment/E_heroku.md b/deployment/E_heroku.md index 5d8fd484..a1369231 100644 --- a/deployment/E_heroku.md +++ b/deployment/E_heroku.md @@ -194,6 +194,8 @@ Setting config vars and restarting mysterious-meadow-6277... done, v3 SECRET_KEY_BASE: xvafzY4y01jYuzLm3ecJqo008dVnU3CN4f+MamNd1Zue4pXvfvUjbiXT8akaIF53 ``` +If you need to make any of your config variables available at compile time you will need to explicitly define which ones in a configuration file. Create a file `elixir_buildpack.config` in your applications root directory and add a line like: `config_vars_to_export=(DATABASE_URL MY_VAR)`. See [here](https://github.com/HashNuke/heroku-buildpack-elixir#specifying-config-vars-to-export-at-compile-time) for more information. + ## Deploy Time! Our project is now ready to be deployed on Heroku. From 48622e18845b2102afdd33b45768bd98b90b5d13 Mon Sep 17 00:00:00 2001 From: Jason Stiebs Date: Tue, 17 May 2016 10:59:41 -0500 Subject: [PATCH 13/16] Simple grammartical modification https://dash.readme.io/project/phoenixframework/v1.1.4/suggested/update/56c3343ebc41330d009f258e --- D_controllers.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/D_controllers.md b/D_controllers.md index f7ab06a0..aff9dad8 100644 --- a/D_controllers.md +++ b/D_controllers.md @@ -1,6 +1,6 @@ Phoenix controllers act as intermediary modules. Their functions - called actions - are invoked from the router in response to HTTP requests. The actions, in turn, gather all the necessary data and perform all the necessary steps before invoking the view layer to render a template or returning a JSON response. -Phoenix controllers also build on the Plug package, and are themselves plugs. Controllers provide the functions to do almost anything we need to in an action. If we do find ourselves looking for something that Phoenix controllers don't provide, however, we might find what we're looking for in Plug itself. Please see the [Plug Guide](http://www.phoenixframework.org/docs/understanding-plug) or [Plug Documentation](http://hexdocs.pm/plug/) for more information. +Phoenix controllers also build on the Plug package, and are themselves plugs. Controllers provide the functions to do almost anything we need to in an action. If we do find ourselves looking for something that Phoenix controllers don't provide; however, we might find what we're looking for in Plug itself. Please see the [Plug Guide](http://www.phoenixframework.org/docs/understanding-plug) or [Plug Documentation](http://hexdocs.pm/plug/) for more information. A newly generated Phoenix app will have a single controller, the `PageController`, which can be found at `web/controllers/page_controller.ex` and looks like this. From 108e3b68551c4bab02cd213cb81819f1dcf8f3cc Mon Sep 17 00:00:00 2001 From: Jason Stiebs Date: Tue, 17 May 2016 11:01:34 -0500 Subject: [PATCH 14/16] Heroku procfile https://dash.readme.io/project/phoenixframework/v1.1.4/suggested/update/56c3fabde1e4190d003429cf --- deployment/E_heroku.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/deployment/E_heroku.md b/deployment/E_heroku.md index a1369231..9225c8b9 100644 --- a/deployment/E_heroku.md +++ b/deployment/E_heroku.md @@ -169,6 +169,13 @@ end This ensures that any idle connections are closed by Phoenix before they reach Heroku's 55 second timeout window. +Lastly, we'll need to create a [Procfile](https://devcenter.heroku.com/articles/procfile) with the following: + +``` +web: MIX_ENV=prod mix phoenix.server + +``` + ## Creating Environment Variables in Heroku The `DATABASE_URL` config var is automatically created by Heroku when we add the [Heroku Postgres add-on](https://elements.heroku.com/addons/heroku-postgresql). We can create the database via the heroku toolbelt: @@ -284,7 +291,7 @@ remote: -----> Finalizing build remote: Creating runtime environment remote: remote: -----> Discovering process types -remote: Procfile declares types -> (none) +remote: Procfile declares types -> (web) remote: Default types for Multipack -> web remote: remote: -----> Compressing... done, 82.1MB From 5100e9205ec1a2bcdde085164aa21adbbe1ce3b4 Mon Sep 17 00:00:00 2001 From: Jason Stiebs Date: Tue, 17 May 2016 11:04:30 -0500 Subject: [PATCH 15/16] Bump version of exrm --- deployment/I_exrm_releases.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deployment/I_exrm_releases.md b/deployment/I_exrm_releases.md index 5d35cb0e..0d7ade77 100644 --- a/deployment/I_exrm_releases.md +++ b/deployment/I_exrm_releases.md @@ -24,7 +24,7 @@ Let's separate our release process into a few tasks so we can keep track of wher ## Add exrm as a Dependency -To get started, we'll need to add `{:exrm, "~> 0.19.9"}` into the list of dependencies in our `mix.exs` file. +To get started, we'll need to add `{:exrm, "~> 1.0"}` into the list of dependencies in our `mix.exs` file. ```elixir defp deps do @@ -34,7 +34,7 @@ To get started, we'll need to add `{:exrm, "~> 0.19.9"}` into the list of depend {:phoenix_html, "~> 2.3"}, {:phoenix_live_reload, "~> 1.0", only: :dev}, {:cowboy, "~> 1.0"}, - {:exrm, "~> 0.19.9"}] + {:exrm, "~> 1.0"}] end ``` From 23f30e4776b826625fe5989aaa1950ee07b3bd8b Mon Sep 17 00:00:00 2001 From: Jason Stiebs Date: Tue, 17 May 2016 11:05:11 -0500 Subject: [PATCH 16/16] Updating cast arity --- H_ecto_models.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/H_ecto_models.md b/H_ecto_models.md index 5bc14ff1..792724e4 100644 --- a/H_ecto_models.md +++ b/H_ecto_models.md @@ -241,7 +241,7 @@ def changeset(model, params \\ :empty) do end ``` -At this point, we only have one transformation in our pipeline. This `cast/4` function's main job is to separate required fields from optional ones. We define the fields for each category in the module attributes `@required_fields` and `@optional_fields`. By default all of the fields are required. +At this point, we only have one transformation in our pipeline. This `cast/3` function's main job is to separate required fields from optional ones. We define the fields for each category in the module attributes `@required_fields` and `@optional_fields`. By default all of the fields are required. Let's take a look at two ways to validate that this is the case. The first and easiest way is to simply start our application by running the `mix phoenix.server` task at the root of our project. Then we can go to the [new users page](http://localhost:4000/users/new) and click the "submit" button without filling in any fields. We should get an error telling us that something went wrong and enumerating all the fields which can't be blank. That should be all the fields in our schema at this point.