Skip to content

Commit d12a950

Browse files
committed
refactor(translator): move into src layout and use uv properly
1 parent b4d6126 commit d12a950

15 files changed

Lines changed: 854 additions & 63 deletions

File tree

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
},
4545
"pathMappings": [
4646
{
47-
"localRoot": "${workspaceFolder}/translator",
47+
"localRoot": "${workspaceFolder}/translator/src/translator",
4848
"remoteRoot": "/app"
4949
}
5050
]
@@ -59,7 +59,7 @@
5959
},
6060
"pathMappings": [
6161
{
62-
"localRoot": "${workspaceFolder}/translator",
62+
"localRoot": "${workspaceFolder}/translator/src/translator",
6363
"remoteRoot": "/app"
6464
}
6565
]

compose.override.local.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,9 @@ services:
105105
replicas: 1
106106

107107
translator:
108+
build:
109+
context: .
110+
dockerfile: ./compose/local/translator/Dockerfile
108111
volumes:
109112
- ./translator/tests/:/app/tests/
110113
env_file:
@@ -117,6 +120,9 @@ services:
117120
- DEBUG=${DEBUG:-}
118121

119122
translator-secondary:
123+
build:
124+
context: .
125+
dockerfile: ./compose/local/translator/Dockerfile
120126
volumes:
121127
- ./translator/tests/:/app/tests/
122128
env_file:

compose.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ services:
101101
translator:
102102
build:
103103
context: .
104-
dockerfile: ./compose/local/translator/Dockerfile
104+
dockerfile: ./compose/production/translator/Dockerfile
105105
depends_on:
106106
redis:
107107
condition: service_healthy
@@ -119,7 +119,7 @@ services:
119119
translator-secondary:
120120
build:
121121
context: .
122-
dockerfile: ./compose/local/translator/Dockerfile
122+
dockerfile: ./compose/production/translator/Dockerfile
123123
depends_on:
124124
redis:
125125
condition: service_healthy
Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
FROM python:3.13-slim-bookworm
1+
FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim
22

3-
ENV PYTHONUNBUFFERED 1
4-
ENV PYTHONDONTWRITEBYTECODE 1
3+
ENV PYTHONUNBUFFERED=1
54

65
RUN apt-get update \
76
# dependencies for building Python packages
@@ -10,24 +9,26 @@ RUN apt-get update \
109
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
1110
&& rm -rf /var/lib/apt/lists/*
1211

13-
# Requirements are installed here to ensure they will be cached.
14-
COPY ./translator/requirements /requirements
15-
RUN pip install uv
16-
RUN uv pip install --system -r /requirements/base.txt
12+
WORKDIR /app
1713

18-
RUN mkdir /app \
19-
&& cd /app \
20-
&& git clone -b v3.33.0 https://github.com/osrg/gobgp.git \
21-
&& cd gobgp/api \
22-
&& python3 -m grpc_tools.protoc -I./ --python_out=/app/ --pyi_out=/app/ --grpc_python_out=/app/ *.proto
14+
COPY ./translator/pyproject.toml ./translator/uv.lock* ./
2315

24-
COPY ./translator/translator.py /app
25-
COPY ./translator/gobgp.py /app
26-
COPY ./translator/exceptions.py /app
27-
COPY ./translator/shared.py /app
16+
# Install deps only (as protobuf stuff doesn't exist yet but we need deps to setup protobufs)
17+
RUN uv sync --locked --no-install-project
2818

29-
RUN chmod +x /app/translator.py
19+
# put the venv into PATH
20+
ENV PATH="/app/.venv/bin:$PATH"
3021

31-
WORKDIR /app
22+
COPY ./translator/src /app/
23+
24+
# Generate protobuf files
25+
# TODO: Make this less jank and don't do the git clone crap?
26+
RUN git clone -b v3.33.0 https://github.com/osrg/gobgp.git gobgp \
27+
&& cd gobgp/api \
28+
&& python3 -m grpc_tools.protoc -I./ --python_out=/app/translator/ --pyi_out=/app/translator/ --grpc_python_out=/app/translator/ *.proto \
29+
&& cd /app && rm -rf gobgp
30+
31+
# Install the project itself (including the protobuff stuff)
32+
RUN uv sync --locked
3233

33-
ENTRYPOINT ["/app/translator.py"]
34+
ENTRYPOINT ["python", "-m", "translator.translator"]
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
FROM ghcr.io/astral-sh/uv:python3.13-bookworm-slim
2+
3+
ENV PYTHONUNBUFFERED=1
4+
ENV UV_NO_DEV=1
5+
6+
RUN apt-get update \
7+
# dependencies for building Python packages
8+
&& apt-get install -y build-essential git \
9+
# cleaning up unused files
10+
&& apt-get purge -y --auto-remove -o APT::AutoRemove::RecommendsImportant=false \
11+
&& rm -rf /var/lib/apt/lists/*
12+
13+
WORKDIR /app
14+
15+
COPY ./translator/pyproject.toml ./translator/uv.lock* ./
16+
17+
# Install deps only (as protobuf stuff doesn't exist yet but we need deps to setup protobufs)
18+
RUN uv sync --locked --no-install-project
19+
20+
# put the venv into PATH
21+
ENV PATH="/app/.venv/bin:$PATH"
22+
23+
COPY ./translator/src /app/
24+
25+
# Generate protobuf files
26+
# TODO: Make this less jank and don't do the git clone crap?
27+
RUN git clone -b v3.33.0 https://github.com/osrg/gobgp.git gobgp \
28+
&& cd gobgp/api \
29+
&& python3 -m grpc_tools.protoc -I./ --python_out=/app/translator/ --pyi_out=/app/translator/ --grpc_python_out=/app/translator/ *.proto \
30+
&& cd /app && rm -rf gobgp
31+
32+
# Install the project itself (including the protobuff stuff)
33+
RUN uv sync --locked
34+
35+
ENTRYPOINT ["python", "-m", "translator.translator"]

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,4 +150,4 @@ django_settings_module = "config.settings.test"
150150

151151

152152
[tool.uv.workspace]
153-
exclude = ["scheduler"]
153+
exclude = ["scheduler", "translator"]

translator/pyproject.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
[project]
2+
name = "translator"
3+
dependencies = [
4+
"aiohttp-sse-client>=0.2.1",
5+
"behave>=1.2.6",
6+
"coverage>=5.5",
7+
"grpcio-tools>=1.69.0",
8+
"websockets>=10.3",
9+
]
10+
requires-python = ">=3.13"
11+
version = "0.1.0"
12+
13+
[dependency-groups]
14+
dev = [
15+
"debugpy",
16+
"pydevd-pycharm",
17+
]
18+
19+
[build-system]
20+
requires = ["setuptools", "wheel"]
21+
build-backend = "setuptools.build_meta"

translator/requirements/base.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.

translator/requirements/local.txt

Lines changed: 0 additions & 5 deletions
This file was deleted.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"""Translator package for SCRAM."""

0 commit comments

Comments
 (0)