-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
30 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,46 +168,54 @@ The JSON retrieval address is | |
|
||
This section documents some methods one can use to deploy the server, for both online and offline usages. | ||
|
||
### Deployment with Gigalixir | ||
[Gigalixir](https://www.gigalixir.com) is a hosting service dedicated to Elixir apps. Compared to Heroku, it has the advantage of providing a server that never sleeps, even on the free tier. It also fully supports Elixir features such as unlimited socket connection, which is helpful for interactive experiments. Therefore, Gigalixir is now the recommended deployment method. | ||
### Deployment with Heroku | ||
|
||
1. Ensure that you have [the Phoenix Framework installed](https://hexdocs.pm/phoenix/installation.html) and working. However, if you just want to deploy this server and do no development work/change on it at all, you may skip this step. | ||
[Heroku](https://www.heroku.com/) makes it easy to deploy an web app without having to manually manage the infrastructure. It has a free starter tier, which should be sufficient for the purpose of running experiments. However, note that it has some constraints. For example, the server sleeps after a period of inactivity, and the number of concurrent socket connections is limited, which might restrict interactive experiments with a high amount of simultaneous participants. If Heroku doesn't satisfy your needs, it's recommended to deploy the app on your own server. You may also take a look at [Gigalixir](https://www.gigalixir.com/), an alternative free hosting service built for Elixir. | ||
|
||
2. Ensure that you have a [Gigalixir account](https://www.gigalixir.com/#/signup) already, and have the [Gigalixir CLI](https://gigalixir.readthedocs.io/en/latest/main.html#install-the-cli) installed and working on your computer. | ||
There is an [official guide](https://hexdocs.pm/phoenix/heroku.html) from Phoenix framework on deploying on Heroku. The deployment procedure is based on this guide, but differs in some places. | ||
|
||
1. Ensure that you have [the Phoenix Framework installed](https://hexdocs.pm/phoenix/installation.html) and working. (However, if you just want to deploy this server and do no development work/change on it at all, you may skip this step.) | ||
|
||
2. Ensure that you have a [Heroku account](https://signup.heroku.com/) already, and have the [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli) installed and working on your computer. | ||
|
||
3. Ensure you have [Git](https://git-scm.com/downloads) installed. Clone this git repo with `git clone https://github.com/magpie-ea/magpie-backend` or `git clone [email protected]:magpie-ea/magpie-backend.git`. | ||
|
||
4. In your Terminal (or cmd.exe on Windows), `cd` into the project directory you just cloned. | ||
4. `cd` into the project directory just cloned from your Terminal (or cmd.exe on Windows). | ||
|
||
5. After `gigalixir login`, run `gigalixir create -n APP_NAME` where `APP_NAME` is the custom name of your magpie-backend instance. | ||
5. Run `heroku create --buildpack "https://github.com/HashNuke/heroku-buildpack-elixir.git"` | ||
|
||
6. Set the environment variables `AUTH_USERNAME` and `AUTH_PASSWORD` for app authentication. | ||
6. Run `heroku buildpacks:add https://github.com/gjaldon/heroku-buildpack-phoenix-static.git` | ||
|
||
```sh | ||
gigalixir config:set AUTH_USERNAME="your_username" | ||
gigalixir config:set AUTH_PASSWORD="your_password" | ||
``` | ||
(N.B.: Although the command line output tells you to run `git push heroku master`, don't do it yet.) | ||
|
||
7. Run `heroku buildpacks:add https://github.com/chrismcg/heroku-buildpack-elixir-mix-release` | ||
|
||
7. Run `gigalixir config:set PROD_COOKIE="COOKIE"`, where `COOKIE` could be generated by launching `iex` in the command line and running `Base.url_encode64(:crypto.strong_rand_bytes(40))`. | ||
7. You may want to change the application name instead of using the default name. In that case, run `heroku apps:rename newname`. | ||
|
||
Note: If you don't have Elixir installed on your computer, you may choose to use some other random generator for this task, which essentially asks for a random secret. On Mac and Linux, you may run `openssl rand -base64 40`. Or you may use an online password generator [such as the one offered by LastPass](https://lastpass.com/generatepassword.php). | ||
8. Run `heroku config:set HOST="[app_name].herokuapp.com"` where `[app_name]` is the app name (shown when you first ran `heroku create`, e.g. `mysterious-meadow-6277`, or the app name that you set at the previous step, e.g. `newname`). | ||
|
||
8. Run `git push gigalixir master` | ||
9. Run | ||
|
||
9. Run `gigalixir pg:create --free` | ||
```sh | ||
heroku addons:create heroku-postgresql:hobby-dev | ||
heroku config:set POOL_SIZE=18 PORT=443 | ||
``` | ||
|
||
10. Run `mix deps.get` then `mix phx.gen.secret`. Then run `heroku config:set SECRET_KEY_BASE="OUTPUT"`, where `OUTPUT` should be the output of the `mix phx.gen.secret` step. | ||
|
||
10. Add your public ssh key to your account with `gigalixir account:ssh_keys:add "$(cat ~/.ssh/id_rsa.pub)"`. | ||
Note: If you don't have Phoenix framework installed on your computer, you may choose to use some other random generator for this step, which essentially asks for a random 64-character secret. On Mac and Linux, you may run `openssl rand -base64 64`. Or you may use an online password generator [such as the one offered by LastPass](https://lastpass.com/generatepassword.php). | ||
Note: If you don't have a ssh key yet, refer to the [guide by Github](https://help.github.com/en/enterprise/2.17/user/authenticating-to-github/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent) on how to create one. | ||
11. By default, the app is accessible without authentication. If you want to protect the app with basic auth, first run ``. Set the environment variables `AUTH_USERNAME` and `AUTH_PASSWORD` for authentication, either in the Heroku web interface or via the command line, i.e. | ||
11. Run `gigalixir ps:migrate` to initialize the database (If you see an error about database not existing, wait for a moment and try again). | ||
```sh | ||
heroku config:set AUTH_USERNAME="your_username" AUTH_PASSWORD="your_password" | ||
``` | ||
12. Now, `gigalixir open` should open the app in your browser. | ||
12. Run `git push heroku master`. This will push the `master` branch of the repo to the git remote at Heroku, and deploy the app. | ||
(Note: On the free tier, the Gigalixir app would shut down after 30 days if there are no new deployments. You will receive an email beforehand. You may prevent the shutdown by running `git push --force gigalixir master` periodically to re-deploy the app.) | ||
13. Run `heroku run "_build/prod/rel/magpie/bin/magpie eval 'Magpie.ReleaseTasks.db_migrate()'"` (Note the `'` in the command.) | ||
### Deployment with Heroku (Deprecated) | ||
N.B.: Due to the advantages of [Gigalixir](https://www.gigalixir.com/), deployment with Heroku is now deprecated. It is still supported via the `heroku` branch of this project. If for whatever reason you still need to deploy on Heroku, you may clone the repo, run `git checkout heroku`, and find the instructions in the relevant README section. | ||
14. Now, `heroku open` should open the frontpage of the app. | ||
### Local (Offline) Deployment | ||
|