Skip to content

Commit 5a8b72a

Browse files
revert: undo lazy loading and dockerfile changes breaking staging (#1737)
* Revert "feat(tree): add lazy loading for commit history endpoint (#1729)" This reverts commit 793b8ef. * Revert "fix(backend): improve Dockerfile multistep build (#1727)" This reverts commit 5a5f50f.
1 parent 793b8ef commit 5a8b72a

9 files changed

Lines changed: 67 additions & 191 deletions

File tree

backend/Dockerfile

Lines changed: 25 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,50 @@
11
# syntax=docker/dockerfile:1
22

3-
# Build stage: Install dependencies and build the application
4-
FROM alpine:3.20 as builder
5-
WORKDIR /backend
3+
# Create server docker image (all non-code dependencies)
4+
FROM alpine:3.20 as backend-base
5+
6+
WORKDIR /
67

7-
RUN apk update && \
8-
apk add --no-cache \
8+
ENV POETRY_HOME=/opt/poetry
9+
10+
RUN apk update \
11+
&& apk add --no-cache \
912
python3 \
1013
python3-dev \
1114
gcc \
1215
libffi-dev \
1316
libc-dev \
1417
libpq-dev \
15-
curl
16-
17-
COPY pyproject.toml poetry.lock /backend/
18-
19-
ENV POETRY_HOME=/opt/poetry \
20-
POETRY_VIRTUALENVS_IN_PROJECT=1
21-
22-
RUN python3 -m venv $POETRY_HOME
23-
RUN $POETRY_HOME/bin/pip install poetry==1.8.3
18+
postgresql \
19+
curl \
20+
&& python3 -m venv $POETRY_HOME \
21+
&& $POETRY_HOME/bin/pip install poetry==1.8.3 \
22+
&& ln -s $POETRY_HOME/bin/poetry /bin/poetry
23+
24+
FROM backend-base
25+
COPY . /backend
26+
COPY ./utils/docker/entrypoint.sh /entrypoint.sh
27+
WORKDIR /backend
2428

2529
ARG INSTALL_DEV_DEPS=false
2630
RUN if [ "$INSTALL_DEV_DEPS" = "true" ]; then \
27-
$POETRY_HOME/bin/poetry install --no-interaction; \
31+
poetry install --no-interaction; \
2832
else \
29-
$POETRY_HOME/bin/poetry install --no-interaction --only main; \
33+
poetry install --no-interaction --only main; \
3034
fi
3135

32-
# Copy application code
33-
COPY . /backend/
36+
ENV DJANGO_APP="kernelCI"
3437

3538
# Precompile Python modules
3639
RUN O='0 1 2' \
37-
PY_MAJMIN=`$POETRY_HOME/bin/poetry run python -c "import sys; print('%s.%s'%sys.version_info[0:2])"` \
38-
PY_D=`$POETRY_HOME/bin/poetry env info --path` \
39-
D="$PY_D kernelCI"; \
40+
PY_MAJMIN=`poetry run python -c "import sys; print('%s.%s'%sys.version_info[0:2])"` \
41+
PY_D=`poetry env info --path` \
42+
D="$PY_D $DJANGO_APP"; \
4043
for N in $O; do \
4144
echo "compile python $PY_MAJMIN byte code at -O$N: $D"; \
42-
PYTHONOPTIMIZE=$N $POETRY_HOME/bin/poetry run python -m compileall -q $D || exit 1; \
45+
PYTHONOPTIMIZE=$N poetry run python -m compileall -q $D || exit 1; \
4346
done
4447

45-
# Runtime stage: Create a clean image with only runtime dependencies
46-
FROM alpine:3.20 as app
47-
WORKDIR /backend
48-
49-
# Install only runtime dependencies (no build tools)
50-
RUN apk update && \
51-
apk add --no-cache \
52-
python3 \
53-
libpq \
54-
postgresql-client \
55-
curl
56-
57-
COPY --from=builder /opt/poetry /opt/poetry
58-
COPY --from=builder /backend/.venv /backend/.venv
59-
60-
ENV PATH="/backend/.venv/bin:/opt/poetry/bin:$PATH"
61-
62-
COPY --from=builder /backend /backend
63-
COPY --from=builder /backend/utils/docker/entrypoint.sh /entrypoint.sh
64-
6548
ARG BACKEND_VOLUME_DIR
6649
ENV BACKEND_VOLUME_DIR=${BACKEND_VOLUME_DIR}
6750
RUN echo "Building with volume on: $BACKEND_VOLUME_DIR"

backend/kernelCI_app/queries/tree.py

Lines changed: 29 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -518,13 +518,7 @@ def get_tree_commit_history(
518518
git_url: Optional[str],
519519
git_branch: Optional[str],
520520
tree_name: Optional[str],
521-
include_types: Optional[list[str]] = None,
522521
) -> Optional[list[tuple]]:
523-
if not include_types:
524-
include_types = ["builds", "boots", "tests"]
525-
526-
include_types = [t.lower() for t in include_types]
527-
528522
field_values = {
529523
"commit_hash": commit_hash,
530524
"origin_param": origin,
@@ -547,62 +541,6 @@ def get_tree_commit_history(
547541
git_url=git_url, git_branch=git_branch, tree_name=tree_name
548542
)
549543

550-
include_builds = "builds" in include_types
551-
include_boots = "boots" in include_types
552-
include_tests = "tests" in include_types
553-
include_test_data = include_tests or include_boots
554-
555-
build_prefix = "b." if include_builds else "NULL AS "
556-
test_prefix = "t." if include_test_data else "NULL AS "
557-
build_id = "b.id" if include_builds else "NULL"
558-
build_misc = "b.misc" if include_builds else "NULL"
559-
test_misc_runtime = "t.misc->>'runtime'" if include_test_data else "NULL"
560-
test_id = "t.id" if include_test_data else "NULL"
561-
562-
select_clause = f"""c.git_commit_hash,
563-
c.git_commit_name,
564-
c.git_commit_tags,
565-
c.start_time,
566-
{build_prefix}duration,
567-
{build_prefix}architecture,
568-
{build_prefix}compiler,
569-
{build_prefix}config_name,
570-
{build_prefix}status,
571-
{build_prefix}origin,
572-
{build_id} AS build_id,
573-
{build_misc} AS build_misc,
574-
{test_prefix}path,
575-
{test_prefix}status,
576-
{test_prefix}duration,
577-
{test_prefix}environment_compatible,
578-
{test_prefix}environment_misc,
579-
{test_prefix}origin,
580-
{test_misc_runtime} AS test_lab,
581-
{test_id} AS test_id,
582-
ic.id AS incidents_id,
583-
ic.test_id AS incidents_test_id,
584-
i.id AS issues_id,
585-
i.version AS issues_version"""
586-
587-
if include_boots and not include_tests:
588-
test_filter = "AND (t.path IS NULL OR t.path LIKE 'boot%%')"
589-
elif include_tests and not include_boots:
590-
test_filter = "AND (t.path IS NULL OR t.path NOT LIKE 'boot%%')"
591-
else:
592-
test_filter = ""
593-
594-
if include_test_data:
595-
test_join = f"LEFT JOIN tests AS t ON t.build_id = b.id {test_filter}"
596-
incidents_condition = "t.id = ic.test_id OR b.id = ic.build_id"
597-
else:
598-
test_join = ""
599-
incidents_condition = "b.id = ic.build_id"
600-
601-
join_clause = f"""LEFT JOIN builds AS b ON c.id = b.checkout_id
602-
{test_join}
603-
LEFT JOIN incidents AS ic ON {incidents_condition}
604-
LEFT JOIN issues AS i ON ic.issue_id = i.id"""
605-
606544
query = f"""
607545
WITH HEAD_START_TIME AS (
608546
SELECT
@@ -692,10 +630,37 @@ def get_tree_commit_history(
692630
c.start_time DESC
693631
)
694632
SELECT
695-
{select_clause}
633+
c.git_commit_hash,
634+
c.git_commit_name,
635+
c.git_commit_tags,
636+
c.start_time,
637+
b.duration,
638+
b.architecture,
639+
b.compiler,
640+
b.config_name,
641+
b.status,
642+
b.origin,
643+
t.path,
644+
t.status,
645+
t.duration,
646+
t.environment_compatible,
647+
t.environment_misc,
648+
t.origin,
649+
t.misc->>'runtime' AS test_lab,
650+
b.id AS build_id,
651+
b.misc AS build_misc,
652+
t.id AS test_id,
653+
ic.id AS incidents_id,
654+
ic.test_id AS incidents_test_id,
655+
i.id AS issues_id,
656+
i.version AS issues_version
696657
FROM
697658
SELECTED_CHECKOUTS AS c
698-
{join_clause}
659+
LEFT JOIN builds AS b ON c.id = b.checkout_id
660+
LEFT JOIN tests AS t ON t.build_id = b.id
661+
LEFT JOIN incidents AS ic ON t.id = ic.test_id
662+
OR b.id = ic.build_id
663+
LEFT JOIN issues AS i ON ic.issue_id = i.id
699664
"""
700665

701666
with connection.cursor() as cursor:

backend/kernelCI_app/typeModels/treeCommits.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from datetime import datetime
2-
from enum import Enum
32
from typing import List, Optional
4-
from pydantic import BaseModel, RootModel, field_validator
3+
from pydantic import BaseModel, RootModel
54

65
from kernelCI_app.constants.general import DEFAULT_ORIGIN
76
from kernelCI_app.constants.localization import DocStrings
@@ -15,12 +14,6 @@
1514
)
1615

1716

18-
class TreeEntityTypes(str, Enum):
19-
BUILDS = "builds"
20-
BOOTS = "boots"
21-
TESTS = "tests"
22-
23-
2417
class DirectTreeCommitsQueryParameters(BaseModel):
2518
origin: str = Field(
2619
DEFAULT_ORIGIN, description=DocStrings.TREE_COMMIT_ORIGIN_DESCRIPTION
@@ -31,21 +24,8 @@ class DirectTreeCommitsQueryParameters(BaseModel):
3124
end_time_stamp_in_seconds: Optional[str] = Field(
3225
None, description=DocStrings.TREE_COMMIT_END_TS_DESCRIPTION
3326
)
34-
types: Optional[list[TreeEntityTypes]] = Field(
35-
None,
36-
description="List of types to include (builds, boots, tests)",
37-
)
3827
# TODO: Add filters field in this model
3928

40-
@field_validator("types", mode="before")
41-
@classmethod
42-
def validate_types(cls, value):
43-
if not value:
44-
return []
45-
if isinstance(value, str):
46-
value = [t.strip() for t in value.split(",") if t.strip()]
47-
return value
48-
4929

5030
class TreeCommitsQueryParameters(DirectTreeCommitsQueryParameters):
5131
git_branch: Optional[str] = Field(

backend/kernelCI_app/views/treeCommitsHistory.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ def setup_filters(self):
6868
def sanitize_rows(self, rows: dict) -> list:
6969
result = []
7070
for row in rows:
71-
build_misc = row[11]
71+
build_misc = row[18]
7272
sanitized_build_misc = sanitize_dict(build_misc)
7373
build_lab = (
7474
sanitized_build_misc.get("lab", UNKNOWN_STRING)
@@ -88,15 +88,15 @@ def sanitize_rows(self, rows: dict) -> list:
8888
"config_name": row[7],
8989
"build_status": NULL_STATUS if row[8] is None else row[8],
9090
"build_origin": row[9],
91-
"build_id": row[10],
91+
"test_path": row[10],
92+
"test_status": row[11],
93+
"test_duration": row[12],
94+
"hardware_compatibles": row[13],
95+
"test_environment_misc": row[14],
96+
"test_origin": row[15],
97+
"test_lab": row[16],
98+
"build_id": row[17],
9299
"build_misc": build_misc,
93-
"test_path": row[12],
94-
"test_status": row[13],
95-
"test_duration": row[14],
96-
"hardware_compatibles": row[15],
97-
"test_environment_misc": row[16],
98-
"test_origin": row[17],
99-
"test_lab": row[18],
100100
"test_id": row[19],
101101
"incidents_id": row[20],
102102
"incidents_test_id": row[21],
@@ -403,7 +403,6 @@ def get(
403403
"start_timestamp_in_seconds"
404404
),
405405
end_timestamp_in_seconds=request.GET.get("end_timestamp_in_seconds"),
406-
types=request.GET.get("types"),
407406
)
408407
except ValidationError as e:
409408
return create_api_error_response(
@@ -431,7 +430,6 @@ def get(
431430
git_url=params.git_url,
432431
git_branch=params.git_branch or git_branch,
433432
tree_name=tree_name,
434-
include_types=params.types,
435433
)
436434

437435
if not rows:

backend/schema.yml

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,17 +1207,6 @@ paths:
12071207
default: null
12081208
title: Start Time Stamp In Seconds
12091209
description: Start time filter in seconds for tree commits
1210-
- in: query
1211-
name: types
1212-
schema:
1213-
anyOf:
1214-
- items:
1215-
$ref: '#/components/schemas/TreeEntityTypes'
1216-
type: array
1217-
- type: 'null'
1218-
default: null
1219-
title: Types
1220-
description: List of types to include (builds, boots, tests)
12211210
tags:
12221211
- tree
12231212
security:
@@ -1539,17 +1528,6 @@ paths:
15391528
type: string
15401529
description: Name of the tree
15411530
required: true
1542-
- in: query
1543-
name: types
1544-
schema:
1545-
anyOf:
1546-
- items:
1547-
$ref: '#/components/schemas/TreeEntityTypes'
1548-
type: array
1549-
- type: 'null'
1550-
default: null
1551-
title: Types
1552-
description: List of types to include (builds, boots, tests)
15531531
tags:
15541532
- tree
15551533
security:
@@ -3998,13 +3976,6 @@ components:
39983976
- builds
39993977
title: TreeDetailsFullResponse
40003978
type: object
4001-
TreeEntityTypes:
4002-
enum:
4003-
- builds
4004-
- boots
4005-
- tests
4006-
title: TreeEntityTypes
4007-
type: string
40083979
TreeLatestResponse:
40093980
properties:
40103981
git_repository_url:

backend/utils/docker/entrypoint.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
export PYTHONOPTIMIZE=${PYTHONOPTIMIZE:-2}
33
export PYTHONUNBUFFERED=${PYTHONUNBUFFERED:-1}
44

5+
source $(poetry env info -C ./backend --path)/bin/activate
56
set -e
67

78
# usage: file_env VAR [DEFAULT]

0 commit comments

Comments
 (0)