Skip to content

Commit 34eee07

Browse files
tallysmartinsPragTob
authored andcommitted
Adds gigalixir deploy setup and documentation (#39)
* Adds gigalixir deploy setup and documentation Signed-off-by: Tallys Martins <[email protected]> * Apply review changes
1 parent 16c9df6 commit 34eee07

File tree

4 files changed

+59
-10
lines changed

4 files changed

+59
-10
lines changed

.buildpacks

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
https://github.com/gigalixir/gigalixir-buildpack-clean-cache.git
2+
https://github.com/HashNuke/heroku-buildpack-elixir
3+
https://github.com/gigalixir/gigalixir-buildpack-distillery.git

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,40 @@ Now you can visit [`localhost:4000/api/graphiql`](http://localhost:4000/api/grap
3232

3333
## Deployment
3434

35-
To build the release you can use `mix release`. The relese requires a `PORT` environment variable.
35+
This project uses `distillery` for deployments. The relese requires `PORT` and
36+
`DATABASE_URL` environment variables. Built releases are placed under `_build/prod/rel/elixir_bench`
37+
directory
38+
39+
```
40+
$ MIX_ENV=prod mix release --env=prod
41+
```
42+
43+
Start the application passing the required variables
44+
45+
```
46+
DATABASE_URL="postgresql://user:password@localhost:5432/elixir_bench_dev" PORT=4000 _build/prod/rel/elixir_bench/bin/elixir_bench foreground
47+
```
48+
49+
**PS:** If you try to build a release with an environment other than prod, **IT WILL FAIL**
50+
as development and test environments rely on Mix wich is not shipped within the releases and
51+
require substantial changes to work.
52+
53+
## Deploy on Gigalixir
54+
55+
This project ships the configuration needed to deploy on [Gigalixir](https://gigalixir.com), a Heroku like
56+
service. To make a deploy on Gigalixir you will have to follow this simple guide and refer
57+
to the documentation for further information, see [Getting Started](https://gigalixir.readthedocs.io/en/latest/main.html#getting-started-guide)
58+
59+
- Install the Gigalixir CLI, all steps are performed through it
60+
- Create an account and login
61+
- Create an app and give it a name
62+
- Add a database to your app
63+
- Push your code to gigalixir and see the magic happening
64+
65+
**This project uses the `uuid-ossp extension` from postgresql which is added
66+
in `priv/repo/migrations/20171210214237_add_uuid_to_job.exs`. Gigalixir does not
67+
allow any extensions in the free tier plan, so a workaround is to remove it from
68+
the migration to not use this extension or drop a few bucks :)**
3669

3770
## License
3871

config/prod.exs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,20 @@ use Mix.Config
1414
# manifest is generated by the mix phx.digest task
1515
# which you typically run after static files are built.
1616
config :elixir_bench, ElixirBenchWeb.Endpoint,
17+
# Dynamically verify and set Endpoint env variables
1718
load_from_system_env: true,
19+
http: [],
20+
server: true,
1821
url: [host: "elixirbench.org", port: 80],
19-
cache_static_manifest: "priv/static/cache_manifest.json"
22+
secret_key_base: "${SECRET_KEY_BASE}"
23+
24+
# Configure your database
25+
config :elixir_bench, ElixirBench.Repo,
26+
# Dynamically verify and set Repo env variables
27+
load_from_system_env: true,
28+
adapter: Ecto.Adapters.Postgres,
29+
ssl: true,
30+
pool_size: 1
2031

2132
# Do not print debug messages in production
2233
config :logger, level: :info
@@ -46,11 +57,5 @@ config :logger, level: :info
4657
#
4758
# Check `Plug.SSL` for all available options in `force_ssl`.
4859

49-
config :elixir_bench, ElixirBenchWeb.Endpoint, server: true
50-
51-
# Finally import the config/prod.secret.exs
52-
# which should be versioned separately.
53-
import_config "prod.secret.exs"
54-
5560
# Set the Github client
5661
config :elixir_bench, :github_client, ElixirBench.Github.ClientHTTP

lib/elixir_bench/repo.ex

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@ defmodule ElixirBench.Repo do
1212
Dynamically loads the repository url from the
1313
DATABASE_URL environment variable.
1414
"""
15-
def init(_, opts) do
16-
{:ok, Keyword.put(opts, :url, System.get_env("DATABASE_URL"))}
15+
def init(_, config) do
16+
if config[:load_from_system_env] do
17+
database_url =
18+
System.get_env("DATABASE_URL") ||
19+
raise "expected the DATABASE_URL environment variable to be set"
20+
21+
{:ok, Keyword.put(config, :url, database_url)}
22+
else
23+
{:ok, config}
24+
end
1725
end
1826
end

0 commit comments

Comments
 (0)