Skip to content

Commit 1548efb

Browse files
committed
adding in core files and adding two more checklists
1 parent c44b090 commit 1548efb

File tree

9 files changed

+189
-12
lines changed

9 files changed

+189
-12
lines changed

.gitignore

+13
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,16 @@ erl_crash.dump
2222
# Ignore package tarball (built via "mix hex.build").
2323
ex_macro_inspect-*.tar
2424

25+
# Ignore distilery releases
26+
/_release
27+
28+
# Ignore benchmarks
29+
/_benchmarks
30+
31+
/db
32+
/deps
33+
/*.ez
34+
/docs
35+
36+
# Ignore vs-code project files
37+
/.vs

README.md

+63-1
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ end
3737
* [x] deployment package - erlang release with distillery
3838
* [x] phx configuration 4 package - config.exs setup with aliases
3939
* [x] distillery config - update config/prod.exs with "config :phoenix, :serve_endpoints, true"
40-
* [ ] logging - elixir logging
4140
* [x] benchmarking setup - elixir benchee setup
4241
* [x] load testing setup - elixir wrk
42+
* [ ] logging - elixir logging TODO: Add example logging and checklist
4343

4444
## setup README checklist
4545
* [ ] create README
@@ -147,6 +147,7 @@ end
147147
- [ ] check no git dependencies
148148
- [ ] run: `mix hex.publish`
149149
- [ ] if first publish update references to hexdocs in readme and mix.exs
150+
- [ ] test published package
150151

151152
```
152153
defp package() do
@@ -162,6 +163,67 @@ end
162163
end
163164
```
164165

166+
# deployment package checklist
167+
* [ ] add to deps `{:distillery, "~> 1.5", runtime: false}`
168+
* [ ] setup by running `mix release.init`
169+
* [ ] create bin/version_check.exs
170+
* [ ] test package `make package package-run`
171+
172+
# version_check.exs
173+
```
174+
try do
175+
# if no args submitted and exception is raised
176+
if hd(System.argv()) =~ ~r{^(\d+\.)(\d+\.)(\d+)$} do
177+
System.stop(0)
178+
else
179+
System.stop(1)
180+
end
181+
rescue
182+
# if exception it's a invalid version
183+
_ -> System.stop(1)
184+
end
185+
186+
# Believe the receive block prevents the race condition so
187+
# that halt will work correctly
188+
receive do
189+
{:hello, msg} -> msg
190+
after
191+
10_000 -> "nothing after 1s"
192+
end
193+
```
194+
195+
## benchmarking setup checklist
196+
* [ ] add to deps `{:benchee, "~> 0.11", only: :dev}`,
197+
* [ ] add to deps `{:benchee_html, "~> 0.4", only: :dev}`,
198+
* [ ] create `benchmarks/sample.exs` see below
199+
* [ ] test `make run-benchmarks`
200+
# sample.exs
201+
```
202+
# https://github.com/PragTob/benchee
203+
204+
205+
map_fun = fn(i) -> i + 1 end
206+
inputs = %{
207+
"Small (1 Thousand)" => Enum.to_list(1..1_000),
208+
"Middle (100 Thousand)" => Enum.to_list(1..100_000),
209+
"Big (10 Million)" => Enum.to_list(1..10_000_000),
210+
}
211+
212+
Benchee.run %{
213+
"flat_map" => fn(_) -> 1+1 end,
214+
"map.flatten" => fn(list) -> list |> IO.inspect |> Enum.map(map_fun) |> List.flatten end
215+
}, time: 15, warmup: 5, inputs: inputs, formatters: [
216+
Benchee.Formatters.HTML,
217+
Benchee.Formatters.Console
218+
],
219+
formatter_options: [html: [file: "_benchmarks/sample.html"]]
220+
```
221+
222+
## load testing setup checklist
223+
* [ ] install wrk `brew install wrk`
224+
* [ ] test `IP=127.0.0.1 PORT=8080 URLPATH=hello/world make load-test`
225+
226+
165227
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
166228
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
167229
be found at [https://hexdocs.pm/ex_macro_inspect](https://hexdocs.pm/ex_macro_inspect).

benchmarks/sample.exs

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# https://github.com/PragTob/benchee
2+
3+
4+
map_fun = fn(i) -> i + 1 end
5+
inputs = %{
6+
"Small (1 Thousand)" => Enum.to_list(1..1_000),
7+
"Middle (100 Thousand)" => Enum.to_list(1..100_000),
8+
"Big (10 Million)" => Enum.to_list(1..10_000_000),
9+
}
10+
11+
Benchee.run %{
12+
"flat_map" => fn(_) -> 1+1 end,
13+
"map.flatten" => fn(list) -> list |> IO.inspect |> Enum.map(map_fun) |> List.flatten end
14+
}, time: 15, warmup: 5, inputs: inputs, formatters: [
15+
Benchee.Formatters.HTML,
16+
Benchee.Formatters.Console
17+
],
18+
formatter_options: [html: [file: "_benchmarks/sample.html"]]

bin/basedir.sh

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#!/bin/sh
2+
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd -P)"; echo $SCRIPT_DIR
3+
ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"; echo $ROOT_DIR

bin/version_check.exs

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
try do
2+
# if no args submitted and exception is raised
3+
if hd(System.argv()) =~ ~r{^(\d+\.)(\d+\.)(\d+)$} do
4+
System.stop(0)
5+
else
6+
System.stop(1)
7+
end
8+
rescue
9+
# if exception it's a invalid version
10+
_ -> System.stop(1)
11+
end
12+
13+
# Believe the receive block prevents the race condition so
14+
# that halt will work correctly
15+
receive do
16+
{:hello, msg} -> msg
17+
after
18+
10_000 -> "nothing after 1s"
19+
end

makefile

+6-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
.PHONY: help clean
44

5+
# Copyright Steve Morin 2015
6+
# https://github.com/smorin
7+
58
### make help - is self documenting
69
# Use double # to make a command self documenting
710

@@ -190,16 +193,12 @@ run-benchmarks: ## run all benchmarks using benchee
190193

191194
# Reference: https://github.com/wg/wrk
192195
# Reference: https://github.com/tsenart/vegeta # alternate load testing framework
193-
load-test-error: wrk ## run a load test with wrk
194-
@echo makefile:load-test
195-
wrk --threads 12 --connections 400 --duration 30s --latency --timeout 30s http://$${IP:-127.0.0.1}:$${PORT:-4000}/v1/100/color.pnnnng
196-
197196
load-test: wrk ## run a load test with wrk
198197
@echo makefile:load-test
199-
wrk --threads 12 --connections 400 --duration 30s --latency --timeout 30s http://$${IP:-127.0.0.1}:$${PORT:-4000}/v1/100/color.jpg
198+
wrk --threads 12 --connections 400 --duration 30s --latency --timeout 30s http://$${IP:-127.0.0.1}:$${PORT:-4000}/$${URLPATH:-}
200199

201-
get-pixel:
202-
curl --request GET "http://$${IP:-127.0.0.1}:$${PORT:-4000}/v1/100/color.jpg"
200+
get:
201+
curl --request GET "http://$${IP:-127.0.0.1}:$${PORT:-4000}/$${URLPATH:-}"
203202

204203
wrk:
205204
@echo makefile:wrk

mix.exs

+9-4
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ defmodule ExMacroInspect.MixProject do
3535
{:credo, "~> 0.9.1", only: [:dev, :test], runtime: false},
3636
{:dialyxir, "~> 1.0.0-rc.2", only: [:dev], runtime: false},
3737
{:ex_doc, "~> 0.16", only: :dev, runtime: false},
38-
{:excoveralls, "~> 0.8", only: [:dev, :test]}
38+
{:excoveralls, "~> 0.8", only: [:dev, :test]},
39+
{:distillery, "~> 1.5", runtime: false},
40+
{:benchee, "~> 0.11", only: :dev},
41+
{:benchee_html, "~> 0.4", only: :dev}
3942
# {:dep_from_hexpm, "~> 0.3.0"},
4043
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"},
4144
]
@@ -76,10 +79,12 @@ defmodule ExMacroInspect.MixProject do
7679
name: "ex_macro_inspect",
7780
organization: "hexpm",
7881
# These are the default files included in the package
79-
files: ["lib", "mix.exs", "README*", "LICENSE*"],
82+
files: ["lib", "mix.exs", "README*", "LICENSE*"],
8083
licenses: ["GNU 3.0"],
81-
links: %{"GitHub" => "https://github.com/smorin/ExMacroInspect", "HexDocs" => "https://hexdocs.pm/ex_macro_inspect/"}
84+
links: %{
85+
"GitHub" => "https://github.com/smorin/ExMacroInspect",
86+
"HexDocs" => "https://hexdocs.pm/ex_macro_inspect/"
87+
}
8288
]
8389
end
84-
8590
end

mix.lock

+5
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
%{
2+
"benchee": {:hex, :benchee, "0.13.1", "bd93ca05be78bcb6159c7176230efeda2f724f7ffd485515175ca411dff4893e", [:mix], [{:deep_merge, "~> 0.1", [hex: :deep_merge, repo: "hexpm", optional: false]}], "hexpm"},
3+
"benchee_html": {:hex, :benchee_html, "0.5.0", "1354ba8005f979c177561fe08b83cafbae43f3046e8a6cf209132b8967b6db17", [:mix], [{:benchee, "~> 0.12", [hex: :benchee, repo: "hexpm", optional: false]}, {:benchee_json, "~> 0.5", [hex: :benchee_json, repo: "hexpm", optional: false]}], "hexpm"},
4+
"benchee_json": {:hex, :benchee_json, "0.5.0", "75878fd9944093ced03e9c214e6e1429da147de43e2f4a4cbc4377294ed5d029", [:mix], [{:benchee, "~> 0.12", [hex: :benchee, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
25
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"},
36
"certifi": {:hex, :certifi, "2.3.1", "d0f424232390bf47d82da8478022301c561cf6445b5b5fb6a84d49a9e76d2639", [:rebar3], [{:parse_trans, "3.2.0", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"},
47
"credo": {:hex, :credo, "0.9.3", "76fa3e9e497ab282e0cf64b98a624aa11da702854c52c82db1bf24e54ab7c97a", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:poison, ">= 0.0.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
8+
"deep_merge": {:hex, :deep_merge, "0.1.1", "c27866a7524a337b6a039eeb8dd4f17d458fd40fbbcb8c54661b71a22fffe846", [:mix], [], "hexpm"},
59
"dialyxir": {:hex, :dialyxir, "1.0.0-rc.3", "774306f84973fc3f1e2e8743eeaa5f5d29b117f3916e5de74c075c02f1b8ef55", [:mix], [], "hexpm"},
10+
"distillery": {:hex, :distillery, "1.5.3", "b2f4fc34ec71ab4f1202a796f9290e068883b042319aa8c9aa45377ecac8597a", [:mix], [], "hexpm"},
611
"earmark": {:hex, :earmark, "1.2.5", "4d21980d5d2862a2e13ec3c49ad9ad783ffc7ca5769cf6ff891a4553fbaae761", [:mix], [], "hexpm"},
712
"ex_doc": {:hex, :ex_doc, "0.18.4", "4406b8891cecf1352f49975c6d554e62e4341ceb41b9338949077b0d4a97b949", [:mix], [{:earmark, "~> 1.1", [hex: :earmark, repo: "hexpm", optional: false]}], "hexpm"},
813
"excoveralls": {:hex, :excoveralls, "0.9.1", "14fd20fac51ab98d8e79615814cc9811888d2d7b28e85aa90ff2e30dcf3191d6", [:mix], [{:hackney, ">= 0.12.0", [hex: :hackney, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},

rel/config.exs

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Import all plugins from `rel/plugins`
2+
# They can then be used by adding `plugin MyPlugin` to
3+
# either an environment, or release definition, where
4+
# `MyPlugin` is the name of the plugin module.
5+
Path.join(["rel", "plugins", "*.exs"])
6+
|> Path.wildcard()
7+
|> Enum.map(&Code.eval_file(&1))
8+
9+
use Mix.Releases.Config,
10+
# This sets the default release built by `mix release`
11+
default_release: :default,
12+
# This sets the default environment used by `mix release`
13+
default_environment: Mix.env()
14+
15+
# For a full list of config options for both releases
16+
# and environments, visit https://hexdocs.pm/distillery/configuration.html
17+
18+
19+
# You may define one or more environments in this file,
20+
# an environment's settings will override those of a release
21+
# when building in that environment, this combination of release
22+
# and environment configuration is called a profile
23+
24+
environment :dev do
25+
# If you are running Phoenix, you should make sure that
26+
# server: true is set and the code reloader is disabled,
27+
# even in dev mode.
28+
# It is recommended that you build with MIX_ENV=prod and pass
29+
# the --env flag to Distillery explicitly if you want to use
30+
# dev mode.
31+
set dev_mode: true
32+
set include_erts: false
33+
set cookie: :"H.~A(,*ly@Z:_sJra000zI/SCtj3(rj$[WRP{)iA?U48E*3cwWYyq@GSt^L/bBvV"
34+
end
35+
36+
environment :prod do
37+
set include_erts: true
38+
set include_src: false
39+
set cookie: :"_h6OSuK?=R~72V;EpP4~GSQy|gQM8wlGV]6wXcuHD@u{8`0ij?O=aC^90Xnd$Vjb"
40+
end
41+
42+
# You may define one or more releases in this file.
43+
# If you have not set a default release, or selected one
44+
# when running `mix release`, the first release in the file
45+
# will be used by default
46+
47+
release :ex_macro_inspect do
48+
set version: current_version(:ex_macro_inspect)
49+
set applications: [
50+
:runtime_tools
51+
]
52+
end
53+

0 commit comments

Comments
 (0)