Skip to content

Commit

Permalink
Add Elixir sample (#8)
Browse files Browse the repository at this point in the history
* Add Elixir sample

* Change Dockerfile to add files to /app

* Change README.md link to "Google App Engine"

* Add /cover, /doc, /.fetch, erl_crash.dump to .dockerignore
  • Loading branch information
jayjun authored and Jon Wayne Parrott committed Jan 27, 2017
1 parent daf2a43 commit 0633554
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 0 deletions.
17 changes: 17 additions & 0 deletions elixir/.dockerignore
@@ -0,0 +1,17 @@
# The directory Mix will write compiled artifacts to.
/_build

# If you run "mix test --cover", coverage assets end up here.
/cover

# The directory Mix downloads your dependencies sources to.
/deps

# Where 3rd-party dependencies like ExDoc output generated docs.
/doc

# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump
23 changes: 23 additions & 0 deletions elixir/.gitignore
@@ -0,0 +1,23 @@
# The directory Mix will write compiled artifacts to.
/_build

# If you run "mix test --cover", coverage assets end up here.
/cover

# The directory Mix downloads your dependencies sources to.
/deps

# Where 3rd-party dependencies like ExDoc output generated docs.
/doc

# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez

# Ignore mix.lock to always fetch latest dependencies
mix.lock
16 changes: 16 additions & 0 deletions elixir/Dockerfile
@@ -0,0 +1,16 @@
# Use the latest Elixir image from Docker Hub
FROM elixir

# Add current Mix project
ADD . /app
WORKDIR /app

# Install package managers
RUN mix local.hex --force
RUN mix local.rebar --force

# Fetch dependencies
RUN mix deps.get

# Compile and run the app
ENTRYPOINT ["mix", "run", "--no-halt"]
12 changes: 12 additions & 0 deletions elixir/README.md
@@ -0,0 +1,12 @@
# Elixir Custom Runtime for App Engine

Simple sample of an [Elixir](http://elixir-lang.org) (Plug + Cowboy) app that runs on [Google App Engine](https://cloud.google.com/appengine).

## Run locally

$ mix deps.get
$ mix run --no-halt

## Deploy

$ gcloud app deploy
2 changes: 2 additions & 0 deletions elixir/app.yaml
@@ -0,0 +1,2 @@
runtime: custom
env: flex
1 change: 1 addition & 0 deletions elixir/config/config.exs
@@ -0,0 +1 @@
use Mix.Config
7 changes: 7 additions & 0 deletions elixir/lib/my_app.ex
@@ -0,0 +1,7 @@
defmodule MyApp do
use Application

def start(_type, _args) do
Plug.Adapters.Cowboy.http(MyApp.Router, [], [port: 8080])
end
end
12 changes: 12 additions & 0 deletions elixir/lib/my_app/router.ex
@@ -0,0 +1,12 @@
defmodule MyApp.Router do
import Plug.Conn

def init(opts), do: opts

def call(%Plug.Conn{request_path: "/_ah/health"} = conn, _opts) do
send_resp(conn, 200, "👌")
end
def call(conn, _opts) do
send_resp(conn, 200, "Elixir running on Google App Engine!")
end
end
21 changes: 21 additions & 0 deletions elixir/mix.exs
@@ -0,0 +1,21 @@
defmodule MyApp.Mixfile do
use Mix.Project

def project do
[app: :my_app,
version: "0.1.0",
elixir: "~> 1.4",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
deps: deps()]
end

def application do
[mod: {MyApp, []}]
end

defp deps do
[{:plug, "~> 1.0"},
{:cowboy, "~> 1.0"}]
end
end

0 comments on commit 0633554

Please sign in to comment.