Skip to content

Commit 5b9533b

Browse files
authored
Use uv only for waypoint backend installation (#216)
* working changes * Use uv * uv run populate cmd * Node 22 * venv -> .venv * bye bye pipenv
1 parent 27fb177 commit 5b9533b

4 files changed

Lines changed: 43 additions & 78 deletions

File tree

docker/waypoint/Dockerfile

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,25 @@ RUN apt-get update && apt-get install -y locales
1616
RUN locale-gen en_US.UTF-8
1717
RUN update-locale LANG=en_US.UTF-8 LC_ALL=en_US.UTF-8
1818

19-
RUN pip3 install uv pipenv
19+
RUN pip3 install uv
2020

2121
# --- labs setup
2222
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y tzdata \
23-
&& ln -fs /usr/share/zoneinfo/America/New_York /etc/localtime \
24-
&& dpkg-reconfigure -f noninteractive tzdata
23+
&& ln -fs /usr/share/zoneinfo/America/New_York /etc/localtime \
24+
&& dpkg-reconfigure -f noninteractive tzdata
2525

2626
RUN apt-get update && apt-get install -y postgresql postgresql-contrib redis-server systemd
2727

2828
# Install nvm, node, and npm, yarn
2929
ENV NVM_DIR=/usr/local/nvm
30-
ENV NODE_VERSION=20
30+
ENV NODE_VERSION=22
3131

3232
RUN mkdir -p $NVM_DIR && \
33-
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash && \
34-
. $NVM_DIR/nvm.sh && \
35-
nvm install $NODE_VERSION && \
36-
nvm alias default $NODE_VERSION && \
37-
nvm use default
33+
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.1/install.sh | bash && \
34+
. $NVM_DIR/nvm.sh && \
35+
nvm install $NODE_VERSION && \
36+
nvm alias default $NODE_VERSION && \
37+
nvm use default
3838

3939
RUN . $NVM_DIR/nvm.sh && npm install -g yarn
4040

docker/waypoint/src/main.py

Lines changed: 19 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,7 @@
44
import subprocess
55
import sys
66

7-
PRODUCTS = {
8-
"office-hours-queue": {
9-
"node_version": "22",
10-
},
11-
"penn-clubs": {
12-
"node_version": "20",
13-
},
14-
"penn-mobile": {
15-
"node_version": "22",
16-
},
17-
"penn-courses": {
18-
"node_version": "22",
19-
},
20-
"platform": {
21-
"node_version": "22",
22-
},
23-
}
7+
PRODUCTS = ["office-hours-queue", "penn-clubs", "penn-mobile", "penn-courses", "platform"]
248

259
WAYPOINT_DIR = "/opt/waypoint"
2610
CODE_DIR = "/labs"
@@ -52,7 +36,7 @@ def clone_and_init_product(product: str) -> None:
5236

5337
if product not in PRODUCTS:
5438
print(f"Error: Unknown product '{product}'")
55-
print(f"Available products: {', '.join(PRODUCTS.keys())}")
39+
print(f"Available products: {', '.join(PRODUCTS)}")
5640
sys.exit(1)
5741

5842
clone_product(product)
@@ -64,18 +48,17 @@ def clone_and_init_product(product: str) -> None:
6448
print(f"Product '{product}' is already initialized.")
6549
sys.exit(1)
6650

67-
# Run manage.py commands in product venv
68-
venv_path = os.path.join(product_path, "venv", "bin", "activate")
51+
# Run manage.py commands
6952
try:
7053
subprocess.run(
71-
f"bash -c 'source {venv_path} && cd {backend_path} && python manage.py migrate'",
54+
f"bash -c 'cd {backend_path} && uv run manage.py migrate'",
7255
shell=True,
7356
check=True,
7457
)
7558

7659
if product not in ["penn-mobile", "penn-courses", "platform"]:
7760
subprocess.run(
78-
f"bash -c 'source {venv_path} && cd {backend_path} && python manage.py populate'",
61+
f"bash -c 'cd {backend_path} && uv run manage.py populate'",
7962
shell=True,
8063
check=True,
8164
)
@@ -135,15 +118,10 @@ def clone_and_init_product(product: str) -> None:
135118
print(f"Product '{product}' initialized successfully.")
136119

137120

138-
def clone_and_init_products() -> None:
139-
"""Clone all products from GitHub if they don't exist and init their product environments."""
140-
for product in PRODUCTS:
141-
clone_and_init_product(product)
142-
143-
144121
def init() -> None:
145122
"""Set up waypoint, install dependencies."""
146-
clone_and_init_products()
123+
for product in PRODUCTS:
124+
clone_and_init_product(product)
147125

148126
if not os.path.exists(os.path.join(WAYPOINT_DIR, "secrets")):
149127
print("No secrets found. Skipping...")
@@ -169,7 +147,7 @@ def sync_env(product: str) -> None:
169147
"""Sync .env file from product to waypoint."""
170148
if product not in PRODUCTS:
171149
print(f"Error: Unknown product '{product}'")
172-
print(f"Available products: {', '.join(PRODUCTS.keys())}")
150+
print(f"Available products: {', '.join(PRODUCTS)}")
173151
sys.exit(1)
174152

175153
product_backend_path = os.path.join(CODE_DIR, product, "backend")
@@ -182,7 +160,7 @@ def sync_env(product: str) -> None:
182160
os.makedirs(waypoint_product_path, exist_ok=True)
183161

184162
try:
185-
for file in ["Pipfile", "Pipfile.lock"]:
163+
for file in ["pyproject.toml", "uv.lock"]:
186164
src = os.path.join(product_backend_path, file)
187165
dst = os.path.join(waypoint_product_path, file)
188166

@@ -195,17 +173,8 @@ def sync_env(product: str) -> None:
195173
f_dst.write(f_src.read())
196174
print(f"Copied {file} from {product_backend_path} to {waypoint_product_path}")
197175

198-
venv_path = os.path.join(waypoint_product_path, "venv")
199-
if not os.path.exists(venv_path):
200-
subprocess.run(
201-
["uv", "venv", venv_path, "--python", "3.11", "--prompt", product],
202-
check=True,
203-
)
204-
205176
subprocess.run(
206-
f"cd {waypoint_product_path} && . venv/bin/activate && "
207-
f"pipenv requirements --dev > requirements.txt && "
208-
f"uv pip install -r requirements.txt",
177+
f"cd {waypoint_product_path} && uv sync --frozen --all-groups",
209178
shell=True,
210179
check=True,
211180
)
@@ -220,7 +189,7 @@ def switch_product(product: str, no_vsc: bool) -> None:
220189
"""Switch to a different product environment"""
221190
if product not in PRODUCTS:
222191
print(f"Error: Unknown product '{product}'")
223-
print(f"Available products: {', '.join(PRODUCTS.keys())}")
192+
print(f"Available products: {', '.join(PRODUCTS)}")
224193
sys.exit(1)
225194

226195
product_path = os.path.join(WAYPOINT_DIR, product)
@@ -300,12 +269,15 @@ def start_development(mode: str) -> None:
300269

301270
product_code_path = os.path.join(CODE_DIR, product_name)
302271

272+
backend_start_cmd = f"source {current_link}/.venv/bin/activate && cd {product_code_path}/backend && python manage.py runserver 0.0.0.0:8000"
273+
frontend_start_cmd = f"cd {product_code_path}/frontend && yarn dev"
274+
303275
if mode == "backend":
304-
start_cmd = f"bash -c 'source {current_link}/venv/bin/activate && cd {product_code_path}/backend && python manage.py runserver 0.0.0.0:8000'"
276+
start_cmd = f"bash -c '{backend_start_cmd}'"
305277
elif mode == "frontend":
306-
start_cmd = f"bash -c 'cd {product_code_path}/frontend && yarn dev'"
278+
start_cmd = f"bash -c '{frontend_start_cmd}'"
307279
else:
308-
start_cmd = f"bash -c 'source {current_link}/venv/bin/activate && cd {product_code_path}/backend && python manage.py runserver 0.0.0.0:8000 && cd {product_code_path}/frontend && yarn dev'"
280+
start_cmd = f"bash -c '{backend_start_cmd} && {frontend_start_cmd}'"
309281

310282
try:
311283
subprocess.run(start_cmd, shell=True, check=True)
@@ -324,7 +296,7 @@ def main() -> None:
324296
)
325297
init_parser.add_argument(
326298
"product",
327-
help="Product to initalize to, options: " + ", ".join(PRODUCTS.keys()),
299+
help="Product to initalize to, options: " + ", ".join(PRODUCTS),
328300
nargs="?",
329301
default=None,
330302
)
@@ -334,7 +306,7 @@ def main() -> None:
334306
help="Switch to a product environment. Starts the uv virtual environment associated with the product and opens the product in VSCode if in a dev container. Use --no-vsc to not open VSCode.",
335307
)
336308
switch_parser.add_argument(
337-
"product", help="Product to switch to, options: " + ", ".join(PRODUCTS.keys())
309+
"product", help="Product to switch to, options: " + ", ".join(PRODUCTS)
338310
)
339311
switch_parser.add_argument("--no-vsc", action="store_true", help="Do not open VSCode on switch")
340312

docker/waypoint/waypoint-bashrc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ waypoint-switch-shell-context() {
44
PRODUCT_NAME=$(basename "$symlink_path")
55

66
cd "/labs/$PRODUCT_NAME"
7-
source "/opt/waypoint/$PRODUCT_NAME/venv/bin/activate"
7+
source "/opt/waypoint/$PRODUCT_NAME/.venv/bin/activate"
88
else
99
echo 'Run "waypoint switch <product>" to jump into a product environment.'
1010
fi
@@ -23,4 +23,4 @@ alias wp=waypoint
2323
source $NVM_DIR/nvm.sh
2424
echo 'Welcome to Waypoint!'
2525
echo 'Run "waypoint services" to start services.'
26-
waypoint-switch-shell-context
26+
waypoint-switch-shell-context

docker/waypoint/waypoint-init

100644100755
Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,30 @@
11
#!/bin/bash
22

33
declare -A PRODUCT_TO_SHA
4-
declare -A PRODUCT_TO_NODE_VERSION
54

5+
# TODO: Add remaining products back since they aren't migrated to uv
66
PRODUCT_TO_SHA=(
7-
["office-hours-queue"]="524282d029a330b59158e80299e3be23988f1765"
8-
["penn-clubs"]="1bcd3ce4f3040395e081989df81fd3105047b24b"
9-
["penn-mobile"]="f0a65d07764f4e3bce56b3f5349c0b556d708780"
10-
["penn-courses"]="01e3dac5f5465ad39f810b2c81969f0165c70dcf"
11-
["platform"]="42c56ff509f60de5389262a9de5e38faf1d9aac2"
7+
["office-hours-queue"]="7fdcdaeba0b83600950edfbdfb155ba62cd2febd"
8+
["penn-clubs"]="a69532b40c40c6ad0a2c6856e11034c70fbab26c"
9+
# ["penn-mobile"]="093a9f58ec7d778acc12dad40d0ece109e6346e8"
10+
# ["penn-courses"]="e787256c332741db357baf3d005b20158d7b35c7"
11+
# ["platform"]="022d2671a7811e8e2b6f772948ff28d18fa6422a"
1212
)
1313

14-
PRODUCT_TO_NODE_VERSION=(
15-
["office-hours-queue"]="22"
16-
["penn-clubs"]="20"
17-
["penn-mobile"]="22"
18-
["penn-courses"]="22"
19-
["platform"]="22"
20-
)
21-
22-
14+
# uv native installation using [uv sync]
2315
for product in "${!PRODUCT_TO_SHA[@]}"; do
24-
echo "Installing dependencies for $product"
2516
sha="${PRODUCT_TO_SHA[$product]}"
2617
PRODUCT_PATH="/opt/waypoint/$product"
18+
BACKEND_BASE="https://raw.githubusercontent.com/pennlabs/$product/$sha/backend"
19+
20+
echo "Installing dependencies for $product @ $sha with uv"
2721
mkdir -p "$PRODUCT_PATH"
2822

29-
curl -o $PRODUCT_PATH/Pipfile "https://raw.githubusercontent.com/pennlabs/$product/$sha/backend/Pipfile"
30-
curl -o $PRODUCT_PATH/Pipfile.lock "https://raw.githubusercontent.com/pennlabs/$product/$sha/backend/Pipfile.lock"
23+
curl -o $PRODUCT_PATH/pyproject.toml "$BACKEND_BASE/pyproject.toml"
24+
curl -o $PRODUCT_PATH/uv.lock "$BACKEND_BASE/uv.lock"
3125

32-
uv venv "$PRODUCT_PATH/venv" --python 3.11 --prompt "$product"
3326
cd $PRODUCT_PATH
34-
source "$PRODUCT_PATH/venv/bin/activate" && pipenv requirements --dev > requirements.txt && uv pip install -r $PRODUCT_PATH/requirements.txt
27+
uv sync --frozen --all-groups
3528
done
3629

3730
echo "Setup complete!"

0 commit comments

Comments
 (0)