Skip to content

Commit fce5fde

Browse files
committed
refactor(agent): port agent from script to python module
1 parent d9e4810 commit fce5fde

File tree

9 files changed

+26
-24
lines changed

9 files changed

+26
-24
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
# Byte-compiled / optimized / DLL files
22
__pycache__/
33

4+
# Distribution / packaging
5+
dist/
6+
47
# Docs
58
_build/
69

agent/Dockerfile

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,12 @@
11
# didn't work with apline
22
FROM python:3.11.3-slim-buster
33

4-
ENV PIP_DEFAULT_TIMEOUT=100
5-
64
RUN apt-get update
75
# working with timezones
86
RUN apt-get install --no-install-recommends --yes tzdata
97
# confluent-kafka-python needs these
108
RUN apt-get install --no-install-recommends --yes gcc librdkafka-dev python3-dev
119

12-
# upgrading pip solves many installation problems
13-
RUN pip3 install --upgrade pip
14-
15-
WORKDIR /app
16-
17-
# leverage Docker cache
18-
COPY requirements.lock ./
19-
RUN PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir -r requirements.lock
20-
21-
ARG VCS_REVISION
22-
RUN echo "$VCS_REVISION" > ./version
23-
24-
COPY src .
10+
RUN --mount=source=dist,target=/dist PYTHONDONTWRITEBYTECODE=1 pip install --no-cache-dir /dist/*.whl
2511

26-
CMD ["python3", "rkagent/main.py"]
12+
CMD ["python3", "-m", "rkagent"]

agent/justfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ check: fmt-check lint
1919

2020
# Build the container image.
2121
image-build:
22+
rye build --wheel --clean
2223
docker build --tag restknot-agent:latest --build-arg VCS_REVISION=$(git rev-parse --short HEAD) .
2324

2425
# Run the container image.

agent/pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ requires = ["hatchling"]
1818
build-backend = "hatchling.build"
1919

2020
[tool.rye]
21-
virtual = true
2221
managed = true
2322
dev-dependencies = [
2423
"pytest>=8.3.2",
@@ -29,4 +28,4 @@ dev-dependencies = [
2928
allow-direct-references = true
3029

3130
[tool.hatch.build.targets.wheel]
32-
packages = ["src/agent"]
31+
packages = ["src/rkagent"]

agent/requirements-dev.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@
99
# generate-hashes: false
1010
# universal: false
1111

12+
-e file:.
1213
confluent-kafka==2.0.2
14+
# via rkagent
1315
iniconfig==2.0.0
1416
# via pytest
1517
libknot==3.2.5
18+
# via rkagent
1619
packaging==24.1
1720
# via pytest
1821
pluggy==1.5.0
@@ -21,3 +24,4 @@ pytest==8.3.2
2124
# via pytest-mock
2225
pytest-mock==3.14.0
2326
pyyaml==6.0
27+
# via rkagent

agent/requirements.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
# generate-hashes: false
1010
# universal: false
1111

12+
-e file:.
1213
confluent-kafka==2.0.2
14+
# via rkagent
1315
libknot==3.2.5
16+
# via rkagent
1417
pyyaml==6.0
18+
# via rkagent

agent/src/rkagent/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
__version__ = "0.7.0"
1+
from rkagent import consumer
2+
3+
4+
def main() -> int:
5+
consumer.main()
6+
return 0

agent/src/rkagent/__main__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import rkagent
2+
import sys
3+
4+
sys.exit(rkagent.main())

agent/src/rkagent/main.py renamed to agent/src/rkagent/consumer.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
from confluent_kafka import Consumer, KafkaException
88

9-
import knot
9+
from rkagent import knot
1010

1111
logger = logging.getLogger(__name__)
1212

@@ -73,7 +73,3 @@ def print_assignment(consumer, partitions):
7373
finally:
7474
# Close down consumer to commit final offsets.
7575
consumer.close()
76-
77-
78-
if __name__ == "__main__":
79-
main()

0 commit comments

Comments
 (0)