forked from OpenMined/syft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
justfile
218 lines (162 loc) · 7.51 KB
/
justfile
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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# Guidelines for new commands
# - Start with a verb
# - Keep it short (max. 3 words in a command)
# - Group commands by context. Include group name in the command name.
# - Mark things private that are util functions with [private] or _var
# - Don't over-engineer, keep it simple.
# - Don't break existing commands
# - Run just --fmt --unstable after adding new commands
set dotenv-load := true
# ---------------------------------------------------------------------------------------------------------------------
# Private vars
_red := '\033[1;31m'
_cyan := '\033[1;36m'
_green := '\033[1;32m'
_yellow := '\033[1;33m'
_nc := '\033[0m'
# ---------------------------------------------------------------------------------------------------------------------
# Aliases
alias rs := run-server
alias rc := run-client
alias rj := run-jupyter
alias b := build
# ---------------------------------------------------------------------------------------------------------------------
@default:
just --list
# ---------------------------------------------------------------------------------------------------------------------
# Run a local syftbox server on port 5001
[group('server')]
run-server port="5001" uvicorn_args="":
mkdir -p .server/data
SYFTBOX_DATA_FOLDER=.server/data uv run uvicorn syftbox.server.server:app --reload --reload-dir ./syftbox --port {{ port }} {{ uvicorn_args }}
# ---------------------------------------------------------------------------------------------------------------------
# Run a local syftbox client on any available port between 8080-9000
[group('client')]
run-client name port="auto" server="http://localhost:5001":
#!/bin/bash
set -eou pipefail
# generate a local email from name, but if it looks like an email, then use it as is
EMAIL="{{ name }}@openmined.org"
if [[ "{{ name }}" == *@*.* ]]; then EMAIL="{{ name }}"; fi
# if port is auto, then generate a random port between 8000-8090, else use the provided port
PORT="{{ port }}"
if [[ "$PORT" == "auto" ]]; then PORT="0"; fi
# Working directory for client is .clients/<email>
DATA_DIR=.clients/$EMAIL
mkdir -p $DATA_DIR
echo -e "Email : {{ _green }}$EMAIL{{ _nc }}"
echo -e "Client : {{ _cyan }}http://localhost:$PORT{{ _nc }}"
echo -e "Server : {{ _cyan }}{{ server }}{{ _nc }}"
echo -e "Data Dir : $DATA_DIR"
uv run syftbox/client/cli.py --config=$DATA_DIR/config.json --data-dir=$DATA_DIR --email=$EMAIL --port=$PORT --server={{ server }} --no-open-dir
# ---------------------------------------------------------------------------------------------------------------------
[group('client')]
run-live-client server="https://syftbox.openmined.org/":
uv run syftbox client --server={{ server }}
# ---------------------------------------------------------------------------------------------------------------------
# Run a local syftbox app command
[group('app')]
run-app name command subcommand="":
#!/bin/bash
set -eou pipefail
# generate a local email from name, but if it looks like an email, then use it as is
EMAIL="{{ name }}@openmined.org"
if [[ "{{ name }}" == *@*.* ]]; then EMAIL="{{ name }}"; fi
# Working directory for client is .clients/<email>
DATA_DIR=$(pwd)/.clients/$EMAIL
mkdir -p $DATA_DIR
echo -e "Data Dir : $DATA_DIR"
uv run syftbox/main.py app {{ command }} {{ subcommand }} --config=$DATA_DIR/config.json
# ---------------------------------------------------------------------------------------------------------------------
# Build syftbox wheel
[group('build')]
build:
rm -rf dist
uv build
# Build syftbox wheel
[group('install')]
install:
rm -rf dist
uv build
uv tool install $(ls ./dist/*.whl) --reinstall
# Bump version, commit and tag
[group('build')]
bump-version level="patch":
#!/bin/bash
# We need to uv.lock before we can commit the whole thing in the repo.
# DO not bump the version on the uv.lock file, else other packages with same version might get updated
set -eou pipefail
# sync dev dependencies for bump2version
uv sync --frozen
# get the current and new version
BUMPVERS_CHANGES=$(uv run bump2version --dry-run --allow-dirty --list {{ level }})
CURRENT_VERSION=$(echo "$BUMPVERS_CHANGES" | grep current_version | cut -d'=' -f2)
NEW_VERSION=$(echo "$BUMPVERS_CHANGES" | grep new_version | cut -d'=' -f2)
echo "Bumping version from $CURRENT_VERSION to $NEW_VERSION"
# first bump version
uv run bump2version {{ level }}
# update uv.lock file to reflect new package version
uv lock
# commit the changes
git commit -am "Bump version $CURRENT_VERSION -> $NEW_VERSION"
git tag -a $NEW_VERSION -m "Release $NEW_VERSION"
# ---------------------------------------------------------------------------------------------------------------------
[group('test')]
test-e2e-old test_name:
@echo "Using SyftBox from {{ _green }}'$(which syftbox)'{{ _nc }}"
chmod +x ./tests/e2e/{{ test_name }}/run.bash
bash ./tests/e2e.old/{{ test_name }}/run.bash
[group('test')]
test-e2e test_name:
#!/bin/sh
uv sync --frozen
. .venv/bin/activate
echo "Using SyftBox from {{ _green }}'$(which syftbox)'{{ _nc }}"
pytest -sq --color=yes ./tests/e2e/test_{{ test_name }}.py
# ---------------------------------------------------------------------------------------------------------------------
# Build & Deploy syftbox to a remote server using SSH
[group('deploy')]
upload-dev keyfile remote="[email protected]": build
#!/bin/bash
set -eou pipefail
# there will be only one wheel file in the dist directory, but you never know...
LOCAL_WHEEL=$(ls dist/*.whl | grep syftbox | head -n 1)
# Remote paths to copy the wheel to
REMOTE_DIR="~"
REMOTE_WHEEL="$REMOTE_DIR/$(basename $LOCAL_WHEEL)"
echo -e "Deploying {{ _cyan }}$LOCAL_WHEEL{{ _nc }} to {{ _green }}{{ remote }}:$REMOTE_WHEEL{{ _nc }}"
# change permissions to comply with ssh/scp
chmod 600 {{ keyfile }}
# Use scp to transfer the file to the remote server
scp -i {{ keyfile }} "$LOCAL_WHEEL" "{{ remote }}:$REMOTE_DIR"
# install pip package
ssh -i {{ keyfile }} {{ remote }} "uv venv && uv pip install $REMOTE_WHEEL"
# restart service
# NOTE - syftbox service is created manually on the remote server
ssh -i {{ keyfile }} {{ remote }} "sudo systemctl daemon-reload && sudo systemctl restart syftbox"
echo -e "{{ _green }}Deployed SyftBox local wheel to {{ remote }}{{ _nc }}"
# Deploy syftbox from pypi to a remote server using SSH
[group('deploy')]
upload-pip version keyfile remote="[email protected]":
#!/bin/bash
set -eou pipefail
# change permissions to comply with ssh/scp
chmod 600 {{ keyfile }}
echo -e "Deploying syftbox version {{ version }} to {{ remote }}..."
# install pip package
ssh -i {{ keyfile }} {{ remote }} "uv venv && uv pip install syftbox=={{ version }}"
# restart service
ssh -i {{ keyfile }} {{ remote }} "sudo systemctl daemon-reload && sudo systemctl restart syftbox"
echo -e "{{ _green }}Deployed SyftBox {{ version }} to {{ remote }}{{ _nc }}"
# ---------------------------------------------------------------------------------------------------------------------
[group('utils')]
ssh keyfile remote="[email protected]":
ssh -i {{ keyfile }} {{ remote }}
# remove all local files & directories
[group('utils')]
reset:
rm -rf ./.clients ./.server ./dist ./.e2e
[group('utils')]
run-jupyter jupyter_args="":
uv run --frozen --with "jupyterlab" \
jupyter lab {{ jupyter_args }}