Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
107 lines (91 loc) · 5.38 KB
/
Copy pathMakefile
File metadata and controls
107 lines (91 loc) · 5.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# DeployEx developer convenience targets (local).
#
# Thin wrappers over the existing mix / release flow, for discoverability and
# to smooth first-run. These are shell/process/cross-repo commands that do not
# map cleanly to mix aliases (interactive iex with OTP distribution, process
# stop, and a cross-repo sample-app build), so they live here. `make test` is
# just `mix test`.
#
# Run these in a shell whose toolchain matches .tool-versions.
# Local sample monitored app. Override: make dev-app APP_DIR=/path/to/app
APP_DIR ?= ../myphoenixapp
APP_NAME ?= myphoenixapp
BUCKET ?= /tmp/deployex/bucket
COOKIE ?= cookie
# JSON list for the published version map, e.g. make dev-app PRE_COMMANDS='["eval 1"]'
PRE_COMMANDS ?= []
export PRE_COMMANDS
# TLS distribution, as in section 9 of guides/docs/local-elixir/README.md
TLS_CONF := /tmp/inet_tls.conf
TLS_OPTIONS := -proto_dist inet_tls -ssl_dist_optfile $(TLS_CONF)
.DEFAULT_GOAL := help
.PHONY: help preflight setup start stop test format-check credo dialyzer check dev-app dev-app-clean dev-tls
preflight: ## Verify the local toolchain (.tool-versions) + tools for dev/test
@fail=0; \
exp_erl=$$(awk '/^erlang /{print $$2}' .tool-versions); \
exp_ex=$$(awk '/^elixir /{print $$2}' .tool-versions); exp_ex_short=$${exp_ex%%-*}; \
if command -v mise >/dev/null 2>&1; then \
run="mise exec --"; printf ' ok %-10s %s\n' mise "$$(mise --version 2>/dev/null | head -1)"; \
else \
run=""; printf ' warn %-10s not found; checking ambient toolchain. Install mise (or asdf) to match .tool-versions\n' mise; \
fi; \
if $$run elixir --version >/dev/null 2>&1; then \
ver=$$($$run elixir --version 2>/dev/null | tr '\n' ' ' | tr -s ' '); \
printf ' ok %-10s %s\n' elixir "$$ver"; \
echo "$$ver" | grep -q "Elixir $$exp_ex_short" || \
printf ' warn %-10s expected Elixir %s / Erlang %s per .tool-versions; run: mise install\n' "" "$$exp_ex_short" "$$exp_erl"; \
else \
printf ' MISS %-10s not runnable. Run: mise install (expected Erlang %s / Elixir %s)\n' elixir "$$exp_erl" "$$exp_ex"; fail=1; \
fi; \
if command -v jq >/dev/null 2>&1; then printf ' ok %-10s %s\n' jq "$$(jq --version 2>/dev/null)"; \
else printf ' MISS %-10s install: brew install jq (used by make dev-app)\n' jq; fail=1; fi; \
if [ $$fail -eq 0 ]; then echo "Local prerequisites OK - no need to run 'make setup'."; \
else echo "Missing prerequisites (see MISS above). Run 'make setup' to install the toolchain + deps."; exit 1; fi
setup: ## Install the pinned toolchain (mise) + fetch deps
@command -v mise >/dev/null 2>&1 || { echo "mise not found. Install mise (https://mise.jdx.dev) or use asdf with .tool-versions."; exit 1; }
mise install
mise exec -- mix deps.get
help: ## Show this help
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) \
| awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-14s\033[0m %s\n", $$1, $$2}'
start: ## Run DeployEx locally with OTP distribution (interactive), with TLS when make dev-tls ran
$(if $(wildcard $(TLS_CONF)),ELIXIR_ERL_OPTIONS="$(TLS_OPTIONS)") iex --sname deployex --cookie $(COOKIE) -S mix phx.server
stop: ## Stop a locally running DeployEx node (best effort)
-@pkill -f "sname deployex .*-S mix phx.server" && echo "stopped" || echo "not running"
test: ## Run the full umbrella test suite
mix test
format-check: ## Check formatting without writing changes
mix format --check-formatted
credo: ## Run credo static analysis (strict)
mix credo --strict
dialyzer: ## Run dialyzer static type analysis
mix dialyzer
check: format-check credo dialyzer test ## Run all pre-PR checks: format, credo, dialyzer, test
dev-app: preflight ## Build + publish the sample app to the local bucket so DeployEx manages it
@printf '%s' "$$PRE_COMMANDS" | jq -e 'type == "array"' >/dev/null 2>&1 || \
{ echo "PRE_COMMANDS must be a JSON list, e.g. PRE_COMMANDS='[\"eval 1\"]'"; exit 1; }
@test -d "$(APP_DIR)" || { \
echo "APP_DIR '$(APP_DIR)' not found. Clone the sample app or pass APP_DIR=/path/to/app."; \
echo " git clone https://github.com/thiagoesteves/myphoenixapp $(APP_DIR)"; \
exit 1; }
mkdir -p "$(BUCKET)/dist/$(APP_NAME)" "$(BUCKET)/versions/$(APP_NAME)/local"
cd "$(APP_DIR)" && mix deps.get && MIX_ENV=prod mix assets.deploy && MIX_ENV=prod mix release
@TARBALL=$$(ls -t "$(APP_DIR)"/_build/prod/$(APP_NAME)-*.tar.gz | head -1); \
VERSION=$$(basename "$$TARBALL" | sed -E 's/^$(APP_NAME)-(.*)\.tar\.gz$$/\1/'); \
cp "$$TARBALL" "$(BUCKET)/dist/$(APP_NAME)/"; \
jq -n --arg version "$$VERSION" --argjson pre_commands "$$PRE_COMMANDS" \
'{version: $$version, pre_commands: $$pre_commands, hash: "local"}' \
> "$(BUCKET)/versions/$(APP_NAME)/local/current.json"; \
echo "Published $(APP_NAME) $$VERSION to $(BUCKET). DeployEx picks it up on its next tick."
dev-app-clean: ## Remove the local bucket
rm -rf "$(BUCKET)"
dev-tls: ## Create TLS distribution certificates and /tmp/inet_tls.conf for make start and the sample app
@if [ -f /tmp/ca.crt ] && [ -f /tmp/deployex.crt ] && [ -f /tmp/deployex.key ]; then \
echo "Certificates already in /tmp"; \
else \
mkdir -p _build/dev-tls && cd _build/dev-tls && \
elixir ../../devops/scripts/certificates/otp-28/tls-distribution-certs && \
cp ca.crt deployex.crt deployex.key /tmp/; \
fi
@DEPLOYEX_OTP_TLS_CERT_PATH=/tmp sh -c "$$(sed -n '/^test -f \/tmp\/inet_tls.conf/,/^)$$/p' rel/env.sh.eex)"
@test -f $(TLS_CONF) && echo "TLS distribution ready: $(TLS_CONF). make start now uses it."