Skip to content

Instantly share code, notes, and snippets.

@bochsdbg
Created January 8, 2019 15:41
Show Gist options
  • Save bochsdbg/849060cd48cabaee19cabd232ff72a39 to your computer and use it in GitHub Desktop.
Save bochsdbg/849060cd48cabaee19cabd232ff72a39 to your computer and use it in GitHub Desktop.
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
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
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
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
#!/bin/bash
iex -S mix run
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment