-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJustfile
More file actions
196 lines (149 loc) · 5.78 KB
/
Copy pathJustfile
File metadata and controls
196 lines (149 loc) · 5.78 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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
# OSA Monorepo Justfile
# Production deployment and development orchestration commands
mod server
default:
@just --list
# === Production Deployment ===
# Start all services in production mode
up:
docker compose -f deploy/docker-compose.yml up -d
# Start all services with logs visible
up-attached:
docker compose -f deploy/docker-compose.yml up
# Stop all services
down:
docker compose -f deploy/docker-compose.yml down
# View logs for a service (e.g., just logs server, just logs db)
logs service:
docker compose -f deploy/docker-compose.yml logs -f {{service}}
# Shell into the server container
server-shell:
docker compose -f deploy/docker-compose.yml exec server bash
# Restart just the server
server-restart:
docker compose -f deploy/docker-compose.yml restart server
# Restart all services
restart:
docker compose -f deploy/docker-compose.yml restart
# Rebuild and restart services
rebuild:
docker compose -f deploy/docker-compose.yml up -d --build
# === Development Mode ===
# Start full-stack development with hot-reload
dev:
docker compose -f deploy/docker-compose.yml -f deploy/docker-compose.dev.yml up
# Start development in background
dev-detached:
docker compose -f deploy/docker-compose.yml -f deploy/docker-compose.dev.yml up -d
# Stop development environment
dev-down:
docker compose -f deploy/docker-compose.yml -f deploy/docker-compose.dev.yml down
# Open the web UI in browser
open-ui:
open http://localhost:8080
# === Code Quality ===
# Lint all code (server + web)
lint:
cd server && just lint
cd web && pnpm lint
# === Individual Service Development ===
# Run server independently (requires database)
server-dev:
cd server && just dev
# Run web frontend independently
web-dev:
cd web && pnpm dev
# Build web frontend for production
web-build:
cd web && pnpm build
# Lint web frontend code
web-lint:
cd web && pnpm lint
# === Seed ===
# Seed the database with sample data (run while dev is up)
seed:
docker compose -f deploy/docker-compose.yml -f deploy/docker-compose.dev.yml exec server /app/.venv/bin/python /app/scripts/seed.py
# === Database ===
# Start only the database (dev mode — exposes port to host)
db-up:
docker compose -f deploy/docker-compose.yml -f deploy/docker-compose.dev.yml up -d db --wait
# Stop the database
db-down:
docker compose -f deploy/docker-compose.yml -f deploy/docker-compose.dev.yml stop db
# Connect to PostgreSQL
db-connect:
docker compose -f deploy/docker-compose.yml -f deploy/docker-compose.dev.yml exec db psql -U postgres -d osa
# === Image ===
# Print the current image tag (based on git sha)
image-tag:
@echo "ghcr.io/$(gh repo view --json owner,name -q '.owner.login')/osa:sha-$(git rev-parse --short=7 HEAD)"
# Print the tag of the latest image pushed to GHCR
image-latest:
@GH_PAGER= gh api /orgs/opensciencearchive/packages/container/osa/versions --jq '.[0].metadata.container.tags[0]'
# === Release ===
# Cut a new release (kind: patch | minor | major). Bumps server/pyproject.toml, pushes to main, creates a GitHub release.
release kind:
#!/usr/bin/env bash
set -euo pipefail
case "{{kind}}" in
patch|minor|major) ;;
*) echo "release: kind must be patch, minor, or major (got '{{kind}}')" >&2; exit 1 ;;
esac
# Require clean main, in sync with origin — release builds don't gate on CI,
# so a bad commit will publish a bad image.
branch="$(git rev-parse --abbrev-ref HEAD)"
if [ "$branch" != "main" ]; then
echo "release: must be on 'main' (currently on '$branch')" >&2
exit 1
fi
if ! git diff --quiet HEAD -- ; then
echo "release: working tree is dirty — commit or stash first" >&2
exit 1
fi
git fetch --quiet origin main
if [ "$(git rev-parse HEAD)" != "$(git rev-parse origin/main)" ]; then
echo "release: local main is not in sync with origin/main — pull/push first" >&2
exit 1
fi
# Latest CI on main must be green. Warn-and-confirm rather than hard-block
# so an unrelated flake doesn't strand the release.
ci_status="$(gh run list --workflow=ci.yml --branch=main --limit=1 --json conclusion --jq '.[0].conclusion' 2>/dev/null || echo unknown)"
if [ "$ci_status" != "success" ]; then
echo "release: latest ci.yml run on main is '${ci_status}' (not success)" >&2
read -p "release: continue anyway? [y/N] " yn
case "$yn" in [yY]*) ;; *) echo "release: aborted"; exit 1 ;; esac
fi
current="$(awk -F'"' '/^version = / {print $2; exit}' server/pyproject.toml)"
if [ -z "$current" ]; then
echo "release: could not read version from server/pyproject.toml" >&2
exit 1
fi
IFS=. read -r maj min pat <<< "$current"
case "{{kind}}" in
patch) pat=$((pat + 1)) ;;
minor) min=$((min + 1)); pat=0 ;;
major) maj=$((maj + 1)); min=0; pat=0 ;;
esac
next="${maj}.${min}.${pat}"
tag="v${next}"
echo "release: ${current} -> ${next} (tag ${tag})"
read -p "release: cut ${tag} from main? [y/N] " yn
case "$yn" in [yY]*) ;; *) echo "release: aborted"; exit 1 ;; esac
# -i.bak portable across BSD (macOS) and GNU sed.
sed -i.bak -e "s/^version = \".*\"/version = \"${next}\"/" server/pyproject.toml
rm -f server/pyproject.toml.bak
git add server/pyproject.toml
git commit -m "chore: bump version to ${next}"
git push origin main
gh release create "${tag}" \
--target main \
--title "${tag}" \
--generate-notes
echo "release: ${tag} cut. Watch the image build with: gh run watch"
# === Maintenance ===
# Clean up Docker resources (volumes, images, etc.)
clean:
docker compose -f deploy/docker-compose.yml down -v --rmi local
# Show service status
status:
docker compose -f deploy/docker-compose.yml ps