Created
January 8, 2019 15:41
-
-
Save bochsdbg/849060cd48cabaee19cabd232ff72a39 to your computer and use it in GitHub Desktop.
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
defmodule App do | |
def start(_type, _args) do | |
port = String.to_integer(System.get_env("PORT")) | |
:cowboy.start_clear(:http, | |
[{:port, port}], | |
%{env: %{ dispatch: build_dispatch_config() }} | |
) | |
end | |
def build_dispatch_config do | |
:cowboy_router.compile([ | |
{ :_, [ | |
{"/", App.PageHandler, []}, | |
] | |
} | |
]) | |
end | |
end |
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
defmodule App.PageHandler do | |
def init(req, state) do | |
handle(req, state) | |
end | |
def handle(request, state) do | |
req = :cowboy_req.reply(200, %{"content-type" => "application/json"}, "{}", request) | |
{:ok, req, state} | |
end | |
end |
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
defmodule App.MixProject do | |
use Mix.Project | |
def project do | |
[ | |
app: :app, | |
version: "0.1.0", | |
elixir: "~> 1.7", | |
start_permanent: Mix.env() == :prod, | |
deps: deps() | |
] | |
end | |
# Run "mix help compile.app" to learn about applications. | |
def application do | |
[ | |
extra_applications: [:logger], | |
mod: { App, [] }, | |
applications: [:cowboy, :ranch], | |
] | |
end | |
# Run "mix help deps" to learn about dependencies. | |
defp deps do | |
[ | |
{:cowboy, "~> 2.6.0"}, | |
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}, | |
] | |
end | |
end |
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
FROM elixir:latest | |
# Set exposed ports | |
EXPOSE 80 | |
ENV PORT=80 | |
ENV MIX_ENV=prod | |
ADD app/ ./ | |
ADD script.sh ./ | |
RUN mix local.hex --force && \ | |
mix local.rebar --force && \ | |
mix deps.clean --all && \ | |
mix deps.get | |
CMD . ./script.sh |
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
#!/bin/bash | |
iex -S mix run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment