-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjustfile
More file actions
149 lines (114 loc) · 4.97 KB
/
Copy pathjustfile
File metadata and controls
149 lines (114 loc) · 4.97 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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
# https://github.com/casey/just
set shell := ["bash", "-cu"]
default:
@just --list
# --- Elixir (phoenix/, docker-only toolchain) -------------------------------
# Run a mix task inside the dev container (no local Elixir needed).
mix *args:
cd phoenix && docker compose run --rm app sh -c "mix local.hex --force >/dev/null 2>&1 && mix local.rebar --force >/dev/null 2>&1 && mix {{args}}"
test *args:
@just mix test {{args}}
format:
@just mix format
# compile --warnings-as-errors + format --check-formatted + test
verify:
@just mix precommit
# Shell / IEx inside the dev container
sh:
cd phoenix && docker compose run --rm app bash
iex:
cd phoenix && docker compose run --rm app iex -S mix
# --- Dev environment --------------------------------------------------------
# Dev server on http://localhost:4000.
dev: _maybe-import-db
cd phoenix && docker compose up
dev-detached: _maybe-import-db
cd phoenix && docker compose up -d
dev-down:
cd phoenix && docker compose down
# --- Database ----------------------------------------------------------------
# Snapshot the legacy python-stack DB (./ssm.db) into the elixir dev DB.
# sqlite3 .backup is transaction-safe and only reads the source; the ecto
# baseline migration adopts the snapshot (fills gaps, stamps) on next boot.
import-db:
sqlite3 ssm.db ".backup 'phoenix/ssm_dev.db'"
rm -f phoenix/ssm_dev.db-shm phoenix/ssm_dev.db-wal
@echo "Imported ssm.db -> phoenix/ssm_dev.db ($(sqlite3 phoenix/ssm_dev.db 'select count(*) from host') hosts)"
# Import automatically when the dev DB has no data yet but ./ssm.db does.
_maybe-import-db:
#!/usr/bin/env bash
set -u
if [ -s ssm.db ]; then
hosts=$(sqlite3 phoenix/ssm_dev.db "select count(*) from host" 2>/dev/null || echo 0)
if [ "${hosts:-0}" = "0" ]; then just import-db; fi
fi
# Daily migration workflow:
# just migration add_widget_flag # scaffold priv/repo/migrations/NNN_*.exs
# # edit the migration, then apply it:
# just migrate # mix ecto.migrate (also runs at app boot)
# just rollback # mix ecto.rollback (last migration)
migration name:
@just mix ecto.gen.migration {{name}}
migrate:
@just mix ecto.migrate
rollback *args:
@just mix ecto.rollback {{args}}
# --- Stack (production) ------------------------------------------------------
up:
docker compose -f docker/compose.yml up -d --build
down:
docker compose -f docker/compose.yml down
logs:
docker compose -f docker/compose.yml logs -f --tail=200
ps:
docker compose -f docker/compose.yml ps
# Build the production image locally (mirrors the CI build).
docker-build:
docker build -f phoenix/Dockerfile -t ssm:dev \
--build-arg VERSION=$(cat VERSION) \
--build-arg VCS_REF=$(git rev-parse HEAD) .
# Run the locally built image on http://localhost:8080.
# Uses a scratch data dir under /tmp so it doesn't touch your real ./docker/data.
docker-run: docker-build
@mkdir -p /tmp/ssm-dev/data/db /tmp/ssm-dev/data/config /tmp/ssm-dev/data/keys /tmp/ssm-dev/data/logs
docker rm -f ssm-dev 2>/dev/null || true
docker run -d --name ssm-dev \
-p 8080:80 \
-v /tmp/ssm-dev/data/db:/app/db \
-v /tmp/ssm-dev/data/config:/app/config \
-v /tmp/ssm-dev/data/keys:/app/keys \
-v /tmp/ssm-dev/data/logs:/app/logs \
-e DATABASE_URL=sqlite:////app/db/ssm.db \
-e HTPASSWD=/app/config/.htpasswd \
-e JWT_SECRET=dev-secret-change-me-dev-secret-change-me \
-e LOGLEVEL=debug \
ssm:dev
@echo "→ http://localhost:8080 (logs: just docker-logs)"
docker-logs:
docker logs -f ssm-dev
docker-stop:
docker rm -f ssm-dev 2>/dev/null || true
# --- Release ----------------------------------------------------------------
# Bump version, update CHANGELOG.md, tag, push. CI builds + publishes image.
# Usage: just release patch|minor|major
release type="patch":
./release.sh {{type}}
# --- Licenses / SBOM --------------------------------------------------------
# Regenerate THIRD-PARTY-LICENSES.md AND sbom.cdx.json (CycloneDX 1.6) from the
# shipped runtime deps of the phoenix release. Needs the hex deps fetched
# (`just mix deps.get`). Run after changing any runtime dependency. Covers app
# dependencies only — for an SBOM that also includes base-image OS packages,
# scan the built image with syft.
notices:
python3 scripts/gen_licenses.py
# Alias: same generator, emphasises the SBOM artifact.
sbom: notices
# --- Cleanup ---------------------------------------------------------------
# Drop build caches. Leaves DBs, keys, and config alone.
clean:
rm -rf phoenix/data/build phoenix/data/deps phoenix/data/toolchain
# Optional local extension hook: ADDITIONAL checkout-specific recipes in a
# `local.just` next to this file (gitignored). Note just's precedence: recipes
# in THIS file always beat imported ones — a local.just can add recipes, never
# override these. Missing file = no-op.
import? 'local.just'