Skip to content

Commit f6d8a6f

Browse files
authored
Poetry (#347)
1 parent 534d2bb commit f6d8a6f

File tree

13 files changed

+1863
-240
lines changed

13 files changed

+1863
-240
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
*
2+
!requirements.txt
23
!dist

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@ jobs:
3434
environment: dev
3535
dev_workspace: ${{ vars.DEV_TFC_WORKSPACE_JSON }}
3636
variables: |
37-
platform_container_runtime=${{ needs.release.outputs.version }}
37+
platform_container_runtime_version=${{ needs.release.outputs.version }}

.github/workflows/test.yaml

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,18 @@ jobs:
1717
uses: actions/setup-python@v5
1818
with:
1919
python-version-file: .python-version
20-
- name: Cache packages
20+
- name: Install pipx
21+
run: python3 -m pip install --user pipx && python3 -m pipx ensurepath
22+
- name: Install Poetry with pipx
23+
run: |
24+
pipx install poetry
25+
- name: Setup Python dependencies cache
2126
uses: actions/cache@v4
2227
with:
23-
path: ~/.cache/pip
24-
key: ${{ runner.os }}-py-3.9-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('setup.cfg') }}
28+
path: ~/.cache/pypoetry
29+
key: poetry-${{ hashFiles('**/poetry.lock') }}
2530
restore-keys: |
26-
${{ runner.os }}-pip-
31+
poetry-
2732
- name: Install dependencies
2833
run: make setup
2934
- name: Lint
@@ -44,13 +49,18 @@ jobs:
4449
uses: actions/setup-python@v5
4550
with:
4651
python-version-file: .python-version
47-
- name: Cache packages
52+
- name: Install pipx
53+
run: python3 -m pip install --user pipx && python3 -m pipx ensurepath
54+
- name: Install Poetry with pipx
55+
run: |
56+
pipx install poetry
57+
- name: Setup Python dependencies cache
4858
uses: actions/cache@v4
4959
with:
50-
path: ~/.cache/pip
51-
key: ${{ runner.os }}-py-3.9-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('setup.cfg') }}
60+
path: ~/.cache/pypoetry
61+
key: poetry-${{ hashFiles('**/poetry.lock') }}
5262
restore-keys: |
53-
${{ runner.os }}-pip-
63+
poetry-
5464
- name: Install dependencies
5565
run: make setup
5666
- name: Run unit tests
@@ -91,15 +101,18 @@ jobs:
91101
uses: actions/setup-python@v5
92102
with:
93103
python-version-file: .python-version
94-
95-
- name: Cache packages
104+
- name: Install pipx
105+
run: python3 -m pip install --user pipx && python3 -m pipx ensurepath
106+
- name: Install Poetry with pipx
107+
run: |
108+
pipx install poetry
109+
- name: Setup Python dependencies cache
96110
uses: actions/cache@v4
97111
with:
98-
path: ~/.cache/pip
99-
key: ${{ runner.os }}-py-3.9-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('setup.cfg') }}
112+
path: ~/.cache/pypoetry
113+
key: poetry-${{ hashFiles('**/poetry.lock') }}
100114
restore-keys: |
101-
${{ runner.os }}-pip-
102-
115+
poetry-
103116
- name: Install dependencies
104117
run: make setup
105118

@@ -128,6 +141,15 @@ jobs:
128141
- name: Run integration tests
129142
run: make test_integration
130143

144+
- name: Dump pod logs for debugging
145+
if: failure()
146+
run: |
147+
echo "Collecting logs from all pods:"
148+
kubectl --context minikube get pods -o name | while read -r pod; do
149+
echo "=== Logs for $pod ==="
150+
kubectl --context minikube logs "$pod" || true
151+
echo
152+
done
131153
- name: Upload coverage to Codecov
132154
uses: codecov/codecov-action@v3
133155
with:
@@ -149,13 +171,18 @@ jobs:
149171
uses: actions/setup-python@v5
150172
with:
151173
python-version-file: .python-version
152-
- name: Cache packages
174+
- name: Install pipx
175+
run: python3 -m pip install --user pipx && python3 -m pipx ensurepath
176+
- name: Install Poetry with pipx
177+
run: |
178+
pipx install poetry
179+
- name: Setup Python dependencies cache
153180
uses: actions/cache@v4
154181
with:
155-
path: ~/.cache/pip
156-
key: ${{ runner.os }}-py-3.9-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('setup.cfg') }}
182+
path: ~/.cache/pypoetry
183+
key: poetry-${{ hashFiles('**/poetry.lock') }}
157184
restore-keys: |
158-
${{ runner.os }}-pip-
185+
poetry-
159186
- name: Install dependencies
160187
run: make setup
161188
- name: Build Docker image

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,11 @@ dmypy.json
128128

129129
# VSCode
130130
.vscode/
131+
.idea/
131132

132-
containerd/
133-
github/
134-
k8s/
133+
!containerd/
134+
!github/
135+
!k8s/
135136
scripts/temp/
136137

137138
temp_deploy/

.pre-commit-config.yaml

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,22 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: 'v4.6.0'
3+
rev: 'v5.0.0'
44
hooks:
5+
- id: check-added-large-files
56
- id: check-merge-conflict
67
exclude: "rst$"
7-
- repo: https://github.com/asottile/yesqa
8-
rev: v1.5.0
9-
hooks:
10-
- id: yesqa
8+
- id: check-case-conflict
9+
- id: check-json
10+
- id: check-toml
11+
- id: check-xml
12+
- id: debug-statements
13+
- id: check-added-large-files
14+
- id: end-of-file-fixer
15+
exclude: "^github|^k8s|^containerd"
16+
- id: requirements-txt-fixer
17+
- id: trailing-whitespace
18+
- id: check-symlinks
19+
exclude: ^charts/
1120
- repo: https://github.com/sondrelg/pep585-upgrade
1221
rev: v1.0
1322
hooks:
@@ -16,60 +25,41 @@ repos:
1625
- --futures=true
1726
exclude: "^github|^k8s|^containerd"
1827
- repo: https://github.com/Zac-HD/shed
19-
rev: 2024.3.1
28+
rev: 2024.10.1
2029
hooks:
2130
- id: shed
2231
args:
2332
- --refactor
24-
- --py39-plus
2533
types_or:
2634
- python
2735
- markdown
2836
- rst
2937
exclude: "^github|^k8s|^containerd"
30-
- repo: https://github.com/PyCQA/flake8
31-
rev: '7.0.0'
32-
hooks:
33-
- id: flake8
34-
exclude: "^github|^k8s|^containerd"
35-
- repo: https://github.com/pre-commit/pre-commit-hooks
36-
rev: 'v4.6.0'
38+
- repo: https://github.com/astral-sh/ruff-pre-commit
39+
rev: v0.8.6
3740
hooks:
38-
- id: check-case-conflict
39-
- id: check-json
40-
- id: check-xml
41-
- id: debug-statements
42-
- id: check-added-large-files
43-
- id: end-of-file-fixer
41+
- id: ruff-format
42+
- id: ruff
43+
args: [--fix, --exit-non-zero-on-fix]
4444
exclude: "^github|^k8s|^containerd"
45-
- id: requirements-txt-fixer
46-
- id: trailing-whitespace
47-
- id: check-symlinks
48-
- id: debug-statements
49-
# Another entry is required to apply file-contents-sorter to another file
5045
- repo: https://github.com/pre-commit/pre-commit-hooks
51-
rev: 'v4.6.0'
46+
rev: 'v5.0.0'
5247
hooks:
5348
- id: file-contents-sorter
5449
files: |
5550
docs/spelling_wordlist.txt|
5651
.gitignore
57-
# - repo: https://github.com/rhysd/actionlint
58-
# rev: v1.6.8
59-
# hooks:
60-
# - id: actionlint-docker
61-
# args:
62-
# - -ignore
63-
# - 'SC2155:'
64-
# - -ignore
65-
# - 'SC2086:'
66-
# - -ignore
67-
# - 'SC1004:'
6852
- repo: https://github.com/sirosen/check-jsonschema
69-
rev: 0.28.3
53+
rev: 0.30.0
7054
hooks:
7155
- id: check-github-actions
7256
- id: check-github-workflows
57+
- repo: https://github.com/python-poetry/poetry
58+
rev: '2.1.1'
59+
hooks:
60+
- id: poetry-check
61+
- id: poetry-lock
62+
- id: poetry-install
7363
ci:
7464
skip:
7565
# - actionlint-docker

Dockerfile

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,37 @@
11
ARG PY_VERSION=3.9.18
22

3-
FROM python:${PY_VERSION}-slim-bullseye AS installer
3+
FROM python:${PY_VERSION}-slim-bullseye AS builder
44

55
ENV PATH=/root/.local/bin:$PATH
66

7-
# Copy to tmp folder to don't pollute home dir
8-
RUN mkdir -p /tmp/dist
9-
COPY dist /tmp/dist
7+
WORKDIR /tmp
8+
COPY requirements.txt /tmp/
109

11-
RUN ls /tmp/dist
12-
RUN pip install --user --find-links /tmp/dist platform-container-runtime
10+
RUN pip install --user --no-cache-dir -r requirements.txt
1311

14-
FROM python:${PY_VERSION}-slim-bullseye as service
12+
COPY dist /tmp/dist/
13+
RUN pip install --user --no-cache-dir --find-links /tmp/dist platform-container-runtime \
14+
&& rm -rf /tmp/dist
15+
16+
FROM python:${PY_VERSION}-slim-bullseye AS runtime
1517

1618
LABEL org.opencontainers.image.source = "https://github.com/neuro-inc/platform-container-runtime"
1719

18-
WORKDIR /app
20+
# Name of your service (folder under /home)
21+
ARG SERVICE_NAME="platform-container-runtime"
1922

20-
COPY --from=installer /root/.local/ /root/.local/
23+
# Tell Python where the "user" site is
24+
ENV HOME=/home/${SERVICE_NAME}
25+
ENV PYTHONUSERBASE=/home/${SERVICE_NAME}/.local
26+
ENV PATH=/home/${SERVICE_NAME}/.local/bin:$PATH
27+
28+
WORKDIR /home/${SERVICE_NAME}
29+
30+
# Copy everything from the builder’s user‐site into your service’s user‐site
31+
COPY --from=builder /root/.local /home/${SERVICE_NAME}/.local
2132

22-
ENV PATH=/root/.local/bin:$PATH
2333
ENV NP_PORT=8080
2434

2535
EXPOSE $NP_PORT
2636

27-
CMD platform-container-runtime
37+
ENTRYPOINT [ "platform-container-runtime" ]

Makefile

Lines changed: 60 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,79 @@
11
GOPATH ?= $(HOME)/go
2+
IMAGE_NAME ?= platformcontainerruntime
23

3-
setup:
4-
pip install -U pip
5-
pip install -e .[build-tools]
6-
scripts/genpb2.sh
7-
pip install -e .[dev]
8-
pre-commit install
4+
.PHONY: venv
5+
venv:
6+
poetry lock
7+
poetry install --with dev --no-root
8+
poetry run scripts/genpb2.sh
9+
poetry install --only-root
910

11+
.PHONY: build
12+
build: venv poetry-plugins
13+
14+
.PHONY: poetry-plugins
15+
poetry-plugins:
16+
poetry self add "poetry-dynamic-versioning[plugin]"; \
17+
poetry self add "poetry-plugin-export";
18+
19+
.PHONY: setup
20+
setup: venv
21+
poetry run pre-commit install;
22+
23+
.PHONY: lint
1024
lint: format
11-
mypy platform_container_runtime tests
25+
poetry run mypy platform_container_runtime tests
1226

27+
.PHONY: format
1328
format:
1429
ifdef CI
15-
pre-commit run --all-files --show-diff-on-failure
30+
poetry run pre-commit run --all-files --show-diff-on-failure
1631
else
17-
pre-commit run --all-files
32+
poetry run pre-commit run --all-files
1833
endif
1934

35+
.PHONY: test_unit
2036
test_unit:
21-
pytest -vv --cov=platform_container_runtime --cov-report xml:.coverage-unit.xml tests/unit
37+
poetry run pytest -vv --cov-config=pyproject.toml --cov-report xml:.coverage-unit.xml tests/unit
38+
39+
.PHONY: ensure-minikube
40+
ensure-minikube:
41+
@kubectl config get-contexts minikube >/dev/null 2>&1 || ( \
42+
echo "⏳ Starting Minikube…" && \
43+
minikube start \
44+
)
2245

23-
test_integration: minikube_image_load
46+
.PHONY: test_integration
47+
test_integration: ensure-minikube minikube_image_load
2448
echo tests/integration/k8s/* | xargs -n 1 kubectl --context minikube apply -f
2549
kubectl --context minikube get po -o name | xargs -n 1 kubectl --context minikube wait --for=jsonpath='{.status.phase}'=Running
2650
kubectl --context minikube get po
2751

28-
pytest -vv --cov=platform_container_runtime --cov-report xml:.coverage-integration.xml tests/integration
52+
poetry run pytest -vv --cov-config=pyproject.toml --cov-report xml:.coverage-integration.xml tests/integration
2953

30-
docker_build:
31-
rm -rf build dist
32-
pip install -U build
33-
python -m build
34-
docker build -t platformcontainerruntime:latest .
54+
.PHONY: docker_build
55+
docker_build: dist
56+
docker build \
57+
--build-arg PY_VERSION=$$(cat .python-version) \
58+
-t $(IMAGE_NAME):latest .
3559

60+
.python-version:
61+
@echo "Error: .python-version file is missing!" && exit 1
62+
63+
.PHONY: dist
64+
dist: build
65+
rm -rf build dist; \
66+
poetry export -f requirements.txt --without-hashes -o requirements.txt; \
67+
poetry build -f wheel;
68+
69+
.PHONY: minikube_image_load
3670
minikube_image_load: docker_build
37-
docker tag platformcontainerruntime:latest localhost/platformcontainerruntime:latest
38-
minikube image load localhost/platformcontainerruntime:latest
71+
@echo "💾 Saving $(IMAGE_NAME):latest to tar…"
72+
docker save $(IMAGE_NAME):latest -o $(IMAGE_NAME).tar
73+
@echo "🚚 Loading into Minikube…"
74+
minikube image load $(IMAGE_NAME).tar
75+
@rm -f $(IMAGE_NAME).tar
76+
77+
.PHONY: clean-protos
78+
clean-protos:
79+
rm -rf scripts/temp

0 commit comments

Comments
 (0)