Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Super ultra update to Elixir 1.5 #105

Merged
merged 3 commits into from
Oct 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
language: elixir

otp_release:
- 18.3
- 19.0
- 20.0
elixir:
- 1.2.6
- 1.3.0
- 1.5.1
sudo: false
env:
- MIX_ENV=test
Expand Down
16 changes: 9 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
FROM msaraiva/elixir-dev:1.2.4
FROM elixir:1.5.2-alpine

ENV APP_NAME poxa
ENV MIX_ENV prod

RUN apk --update add erlang-xmerl erlang-crypto erlang-sasl && rm -rf /var/cache/apk/*
RUN apk --update add bash git erlang-xmerl erlang-crypto erlang-sasl && rm -rf /var/cache/apk/*

COPY . /source
WORKDIR /source

RUN mix local.hex --force && mix local.rebar --force
RUN MIX_ENV=prod mix deps.get
RUN MIX_ENV=prod mix compile
RUN MIX_ENV=prod mix release --verbosity=verbose --no-confirm-missing
RUN mkdir /app && cp -r rel/$APP_NAME /app && rm -rf /source
RUN mix deps.get
RUN mix compile
RUN mix release

CMD trap exit TERM; /app/$APP_NAME/bin/$APP_NAME foreground & wait
RUN mkdir /app && cp -r _build/prod/rel/$APP_NAME /app && rm -rf /source

CMD /app/$APP_NAME/bin/$APP_NAME foreground
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ How do I speak 'poxa'?

Poxa is a standalone elixir server implementation of the Pusher protocol.

You need [Elixir](http://elixir-lang.org) 1.2.6 at least and Erlang 18.0
You need [Elixir](http://elixir-lang.org) 1.5 at least and Erlang 20.0

Clone this repository

Expand Down Expand Up @@ -137,14 +137,14 @@ MIX_ENV=prod mix do deps.get, compile, release
Then you can run it using:

```console
$ ./rel/poxa/bin/poxa
$ _build/prod/rel/poxa/bin/poxa
Usage: poxa {start|start_boot <file>|foreground|stop|restart|reboot|ping|rpc <m> <f> [<a>]|console|console_clean|console_boot <file>|attach|remote_console|upgrade}
```

To start as daemon you just need to:

```console
./rel/poxa/bin/poxa start
$ _build/prod/rel/poxa/bin/poxa start
```

### Release configuration
Expand All @@ -169,6 +169,30 @@ poxa.app_id = "app_id"

You can change anything on this file and just start the release and this configuration will be used.

#### Environment variables

The .conf file is not the only way to configure a release. The following environment variables are supported:

* `PORT`
* `POXA_APP_KEY`
* `POXA_SECRET`
* `POXA_APP_ID`
* `POXA_REGISTRY_ADAPTER`
* `WEB_HOOK`
* `POXA_SSL`
* `SSL_PORT`
* `SSL_CACERTFILE`
* `SSL_CERTFILE`
* `SSL_KEYFILE`

Even if the file is not used at all, an empty file must exist or you will get this error:

```
missing .conf, expected it at /Users/eduardo/workspace/poxa/_build/dev/rel/poxa/releases/0.7.0/poxa.conf
```

It is very important that the .conf file does not have the same configuration. For example if both `PORT` and `poxa.port` (inside the .conf file) are defined, then the file will have precedence.

## Using Docker

Docker images are automatically built by [Docker Hub](https://hub.docker.com/r/edgurgel/poxa-automated/builds/). They are available at Docker Hub: https://hub.docker.com/r/edgurgel/poxa-automated/tags/
Expand Down
32 changes: 0 additions & 32 deletions config/poxa.conf

This file was deleted.

44 changes: 44 additions & 0 deletions config/poxa.dev.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# HTTP Port
# If not set, will use value of PORT environment variable
poxa.port = 8080

# Pusher app key
# If not set, will use value of POXA_APP_KEY environment variable
poxa.app_key = "app_key"

# Pusher secret
# If not set, will use value of POXA_SECRET environment variable
poxa.app_secret = "secret"

# Pusher app id
# If not set, will use value of POXA_APP_ID environment variable
poxa.app_id = "app_id"

# Registry adapter
# If not set, will use value of POXA_REGISTRY_ADAPTER environment variable
poxa.registry_adapter = "gproc"

# Web hook endpoint
# If not set, will use value of WEB_HOOK environment variable
# poxa.web_hook =

# HTTPS switch
# If not set, will use value of POXA_SSL environment variable
poxa.ssl.enabled = false

# HTTPS port
# If not set, will use value of SSL_PORT environment variable
# poxa.ssl.port =

# PEM-encoded CA certificate path
# If not set, will use value of SSL_CACERTFILE environment variable
# poxa.ssl.cacertfile =

# Path to user certificate
# If not set, will use value of SSL_CERTFILE environment variable
# poxa.ssl.certfile =

# Path to the file containing the user's private PEM-encoded key
# If not set, will use value of SSL_KEYFILE environment variable
# poxa.ssl.keyfile =

56 changes: 39 additions & 17 deletions config/poxa.schema.exs
Original file line number Diff line number Diff line change
@@ -1,75 +1,97 @@
[
extends: [],
import: [],
mappings: [
"poxa.port": [
doc: "HTTP port",
to: "poxa.port",
commented: false,
datatype: :integer,
default: 8080
default: 8080,
doc: "HTTP Port",
hidden: false,
env_var: "PORT",
to: "poxa.port"
],
"poxa.app_key": [
doc: "Pusher app key",
to: "poxa.app_key",
commented: false,
datatype: :binary,
default: "app_key"
default: "app_key",
doc: "Pusher app key",
hidden: false,
env_var: "POXA_APP_KEY",
to: "poxa.app_key"
],
"poxa.app_secret": [
doc: "Pusher secret",
to: "poxa.app_secret",
commented: false,
datatype: :binary,
default: "secret"
default: "secret",
doc: "Pusher secret",
hidden: false,
env_var: "POXA_SECRET",
to: "poxa.app_secret"
],
"poxa.app_id": [
doc: "Pusher app id",
to: "poxa.app_id",
commented: false,
datatype: :binary,
default: "app_id"
default: "app_id",
doc: "Pusher app id",
hidden: false,
env_var: "POXA_APP_ID",
to: "poxa.app_id"
],
"poxa.registry_adapter": [
commented: false,
datatype: :binary,
default: "gproc",
doc: "Registry adapter",
hidden: false,
env_var: "POXA_REGISTRY_ADAPTER",
to: "poxa.registry_adapter"
],
"poxa.web_hook": [
commented: true,
datatype: :atom,
commented: false,
datatype: :binary,
doc: "Web hook endpoint",
hidden: false,
default: "",
env_var: "WEB_HOOK",
to: "poxa.web_hook"
],
],
"poxa.ssl.enabled": [
doc: "HTTPS switch",
to: "poxa.ssl.enabled",
datatype: :boolean,
env_var: "POXA_SSL",
default: false,
],
"poxa.ssl.port": [
doc: "HTTPS port",
to: "poxa.ssl.port",
env_var: "SSL_PORT",
default: 8443,
datatype: :integer,
],
"poxa.ssl.cacertfile": [
doc: "PEM-encoded CA certificate path",
to: "poxa.ssl.cacertfile",
env_var: "SSL_CACERTFILE",
default: "",
datatype: :binary,
],
"poxa.ssl.certfile": [
doc: "Path to user certificate",
to: "poxa.ssl.certfile",
env_var: "SSL_CERTFILE",
default: "",
datatype: :binary,
],
"poxa.ssl.keyfile": [
doc: "Path to the file containing the user's private PEM-encoded key",
to: "poxa.ssl.keyfile",
env_var: "SSL_KEYFILE",
default: "",
datatype: :binary,
]
],
translations: [
]
transforms: [],
validators: []
]
2 changes: 1 addition & 1 deletion lib/poxa.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ defmodule Poxa do
{ '/apps/:app_id/channels/:channel_name/users', Poxa.UsersHandler, [] },
{ '/app/:app_key', Poxa.WebsocketHandler, [] } ] }
])
case load_config do
case load_config() do
{:ok, config} ->
Logger.info "Starting Poxa using app_key: #{config.app_key}, app_id: #{config.app_id}, app_secret: #{config.app_secret} on port #{config.port}"
{:ok, _} = :cowboy.start_http(:poxa, 100,
Expand Down
8 changes: 4 additions & 4 deletions lib/poxa/adapter/gproc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,18 @@ defmodule Poxa.Adapter.GProc do
def channels(pid \\ :_) do
Ex2ms.fun do
{{:p, :l, {:pusher, channel}}, ^pid, _} -> channel
end |> select |> Enum.uniq
end |> select |> Enum.uniq_by(&(&1))
end

def unique_subscriptions(channel) do
for {_pid, {user_id, user_info}} <- lookup_values({:p, :l, {:pusher, channel}}) do
for {_pid, {user_id, user_info}} <- lookup_values({:p, :l, {:pusher, channel}}), into: %{} do
{user_id, user_info}
end |> Enum.uniq(fn {user_id, _} -> user_id end)
end
end

def fetch(key) do
get_value({:p, :l, {:pusher, key}})
end

def clean_up, do: goodbye
def clean_up, do: goodbye()
end
4 changes: 2 additions & 2 deletions lib/poxa/channels_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ defmodule Poxa.ChannelsHandler do
defp show(channel, attributes, req, state) do
occupied = Channel.occupied?(channel)
attribute_list = mount_attribute_list(attributes, channel)
{JSX.encode!([occupied: occupied] ++ attribute_list), req, state}
{Poison.encode!([occupied: occupied] ++ attribute_list), req, state}
end

defp mount_attribute_list(attributes, channel) do
Expand All @@ -101,7 +101,7 @@ defmodule Poxa.ChannelsHandler do

defp index(filter, attributes, req, state) do
channels = channels(filter, attributes)
{JSX.encode!(channels: channels), req, state}
{Poison.encode!(channels: channels), req, state}
end

defp channels(filter, attributes) do
Expand Down
4 changes: 2 additions & 2 deletions lib/poxa/console/console.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Poxa.Console do
import JSX, only: [encode!: 1]
import Poison, only: [encode!: 1]
use GenEvent

@doc false
Expand Down Expand Up @@ -62,7 +62,7 @@ defmodule Poxa.Console do
end

defp message(type, socket_id, details) do
%{ type: type, socket: socket_id, details: details, time: time }
%{ type: type, socket: socket_id, details: details, time: time() }
end

defp time do
Expand Down
4 changes: 2 additions & 2 deletions lib/poxa/console/ws_handler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ defmodule Poxa.Console.WSHandler do
{qs_vals, req} = :cowboy_req.qs_vals(req)

if Authentication.check(method, path, "", qs_vals) do
:ok = Poxa.Event.add_handler({Poxa.Console, self}, self)
:ok = Poxa.Event.add_handler({Poxa.Console, self()}, self())
{:ok, req, nil}
else
Logger.error "Failed to authenticate on Console Websocket"
Expand All @@ -31,7 +31,7 @@ defmodule Poxa.Console.WSHandler do

@doc false
def websocket_terminate(_reason, _req, _state) do
Poxa.Event.remove_handler({Poxa.Console, self}, self)
Poxa.Event.remove_handler({Poxa.Console, self()}, self())
:ok
end
end
Loading