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

Use mix because I want the elixir depdency for QR generation #3

Merged
merged 23 commits into from
Jun 1, 2020
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
18 changes: 13 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
FROM gleamlang/gleam:0.9.0-rc1
FROM gleamlang/gleam:0.9.0-rc1 as build

RUN apt-get update && apt-get install -y inotify-tools
FROM elixir:1.10.3

COPY --from=build /bin/gleam /bin
RUN gleam --version

# NOTE the WORKDIR should not be the users home dir as the will copy container cookie into host machine
WORKDIR /opt/app
RUN mix local.hex --force && mix local.rebar --force

# TODO mount volumes including gen
COPY . .
RUN mix deps.get
# RUN mix compile mix_gleam
RUN mix compile
RUN mix test

# Done so generated files are available to heroku run bash
RUN rebar3 upgrade && rebar3 release
CMD ["_build/default/rel/app/bin/app","foreground"]
CMD ["./bin/start"]
7 changes: 7 additions & 0 deletions bin/start
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env sh
set -eu

mix local.hex --force && mix local.rebar --force
mix deps.get --force

elixir --sname app -S mix run --no-halt
6 changes: 5 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
version: "3"

volumes:
underscore_build:
deps:
services:
app:
build:
context: "."
dockerfile: "Dockerfile"
volumes:
- .:/opt/app
# - underscore_build:/opt/app/_build
# - deps:/opt/app/deps
network_mode: host
environment:
- PORT=8080
- FRONTEND_URL=http://localhost:5000
command: "./watch.sh"
2 changes: 0 additions & 2 deletions heroku.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
build:
docker:
web: Dockerfile
run:
web: _build/default/rel/app/bin/app foreground
40 changes: 40 additions & 0 deletions mix.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
defmodule QrPush.Mixfile do
use Mix.Project

def project do
[
app: :qr_push,
version: "0.1.0",
elixir: "~> 1.10",
erlc_paths: ["src", "gen"],
compilers: [:gleam | Mix.compilers()],
# aliases: [
# "compile.gleam": fn _ ->
# System.cmd("gleam", ["build"])
# :ok
# end
# ],
start_permanent: Mix.env() == :prod,
deps: deps()
]
end

# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger],
mod: {:qr_push@application, []}
]
end

# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:mix_gleam, "~> 0.1.0"},
# {:gleam_stdlib, "~> 0.9.0"}
{:gleam_stdlib, github: "gleam-lang/stdlib", manager: :rebar3, override: true},
{:base32, "~> 0.1.0"},
{:midas, github: "midas-framework/midas", manager: :rebar3}
]
end
end
6 changes: 6 additions & 0 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
%{
"base32": {:hex, :base32, "0.1.0", "044f6dc95709727ca2176f3e97a41ddaa76b5bc690d3536908618c0cb32616a2", [:rebar3], [], "hexpm", "10a73951d857d8cb1eceea8eb96c6941f6a76e105947ad09c2b73977dee07638"},
"gleam_stdlib": {:git, "https://github.com/gleam-lang/stdlib.git", "f88c132f3407f85a4580968d149c0f53a50d06b6", []},
"midas": {:git, "https://github.com/midas-framework/midas.git", "c07a7b7875927b4e1e3cbf4d07eeebcf0820de66", []},
"mix_gleam": {:hex, :mix_gleam, "0.1.0", "a0cee5d30de865124a32ca6cd53b64c3e2ac57f12adf6e47b88fb673f47c716e", [:mix], [], "hexpm", "9ff518e6aab444c7f2e74038f9383020ef89810cf1f4402911f33b202ffd72e7"},
}
32 changes: 0 additions & 32 deletions rebar.config

This file was deleted.

22 changes: 0 additions & 22 deletions rebar.lock

This file was deleted.

20 changes: 0 additions & 20 deletions src/qr_push.app.src

This file was deleted.

2 changes: 0 additions & 2 deletions src/qr_push/mailbox.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@ fn loop(receive, target, pull_check, push_check, follower, message) {
}
}
// Front end
// Clean up registry notes
// make public
// suggestions of default release in template project
Some(Redirect(from, push_secret)) -> {
let True = push_check == push_secret
process.reply(from, target)
Expand Down
14 changes: 0 additions & 14 deletions src/registry/local.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,10 @@ pub fn spawn_link() {
process.spawn_link(loop(_, map.new(), map.new()))
}

// returns Result(Option), None is because Key already registered, normal operation.
// error is for failure to contact registry, dead pid, or in larger systems no consensus.
// new_or_create works for returning existing value
// Return a Registered(pid), Existing(pid)
// Is it just OK(pid) | error Pid
pub fn register(registry, key, create) {
process.call(registry, Register(_, key, create), Infinity)
}

pub fn lookup(registry, key) {
process.call(registry, Lookup(_, key), Infinity)
}
// register_new
// register_replace (if pid what you do)
// update === register_replace(option)
// pub fn register(registry: Registry(a, b), key: a, create: fn(Option(b)) -> Option(b)) -> Result(b, Nil) {
// Option is an already started value response
// Ok(Ok(b) Exists)
// pub fn lookup()
// update(key, modify)
// Can have a call function that sends a Down message from registry if needed
20 changes: 10 additions & 10 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(async function(){
console.log("hello")

var response = await fetch("http://localhost:8080/start", {
var response = await fetch("https://qrpu.sh/start", {
method: "POST",
body: "target=http://localhost:7000/foo"
})
Expand All @@ -15,20 +15,20 @@
var [_, push_token] = redirect_uri.split(".sh/")
console.log(push_token);

var pullPromise = fetch("http://localhost:8080/pull", {
var pullPromise = fetch("https://qrpu.sh/pull", {
headers: {
authorization: "Bearer " + pull_token
}
})

var response = await fetch("http://localhost:8080/push", {
method: "POST",
headers: {
authorization: "Bearer " + push_token
},
body: "Hello there"
})
console.log(response);
// var response = await fetch("https://qrpu.sh/push", {
// method: "POST",
// headers: {
// authorization: "Bearer " + push_token
// },
// body: "Hello there"
// })
// console.log(response);

var response = await pullPromise
console.log(response);
Expand Down
8 changes: 8 additions & 0 deletions test/qr_push_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
defmodule QrPushTest do
use ExUnit.Case

test "hello" do
assert "foo" == :[email protected]("Foo")
assert nil == :[email protected]("hello")
end
end
1 change: 1 addition & 0 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ExUnit.start()
12 changes: 0 additions & 12 deletions watch.sh

This file was deleted.