-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDockerfile
More file actions
150 lines (105 loc) · 4.19 KB
/
Dockerfile
File metadata and controls
150 lines (105 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
ARG PYTHON_VER
FROM python:${PYTHON_VER:?} AS python-base
SHELL ["/bin/bash", "-euo", "pipefail", "-c"]
ENV PIP_DISABLE_PIP_VERSION_CHECK=1
FROM python-base AS poetry
RUN --mount=type=cache,target=/root/.cache pip install poetry
RUN python -m venv /venv
ENV VIRTUAL_ENV=/venv \
PATH="/venv/bin:$PATH"
RUN poetry config virtualenvs.create false
WORKDIR /workspace
COPY pyproject.toml poetry.lock /workspace/
# Poetry needs these to exist to setup the editable install
RUN mkdir -p src/denokv && touch src/denokv/__init__.py README.md
RUN --mount=type=cache,target=/root/.cache poetry install
FROM poetry AS test
ARG REPORT_CODE_COVERAGE=false REPORT_CODE_BRANCH_COVERAGE=false
RUN --mount=source=.,target=/workspace,rw \
--mount=type=cache,uid=1000,target=.pytest_cache \
--mount=type=cache,uid=1000,target=.hypothesis \
<<EOF
mkdir /out
pytest_options=(--junit-xml=pytest.xml)
if [[ ${REPORT_CODE_COVERAGE:-} == true ]]; then
pytest_options+=(--cov=denokv --cov-report=html:/out/htmlcov);
if [[ ${REPORT_CODE_BRANCH_COVERAGE:-} == true ]]; then
pytest_options+=(--cov-branch);
fi
fi
pytest "${pytest_options[@]}"
cp -a pytest.xml /out/
if [[ ${REPORT_CODE_COVERAGE:-} == true ]]; then
cp -a .coverage /out/coverage;
fi
EOF
FROM scratch AS test-report
COPY --from=test /out/ /
FROM poetry AS lint-setup
# invalidate cache so that the lint tasks run. We use no-cache-filter here but
# not on the lint-* tasks so that the tasks can mount cache dirs themselves.
RUN touch .now
FROM lint-setup AS lint-check
RUN --mount=source=.,target=/workspace,rw \
ruff check src stubs test testing/smoketest
FROM lint-setup AS lint-format
RUN --mount=source=.,target=/workspace,rw \
ruff format --check --diff src stubs test testing/smoketest
FROM lint-setup AS lint-mypy
RUN --mount=source=.,target=/workspace,rw \
--mount=type=cache,target=.mypy_cache \
mypy src stubs test testing/smoketest
FROM lint-setup AS lint-protobuf
ARG PROTOC_VERSION
RUN --mount=source=.,target=/workspace,rw \
--mount=from=generated-protobuf,target=build/protobuf_${PROTOC_VERSION} \
<<EOF
if ! diff -u build/protobuf_${PROTOC_VERSION}/datapath_pb2.py src/denokv/_datapath_pb2.py ||
! diff -u build/protobuf_${PROTOC_VERSION}/datapath_pb2.pyi src/denokv/_datapath_pb2.pyi
then
printf "\nError: Generated protobuf files do not match repo files\n" >&2;
exit 1;
fi
EOF
FROM poetry AS smoketest-pkg-build
RUN --mount=source=testing/smoketest,target=.,rw \
mkdir /dist && poetry build -o /dist
FROM scratch AS smoketest-pkg
COPY --from=smoketest-pkg-build /dist/* .
FROM poetry AS denokv-pkg-build
RUN --mount=source=.,target=/workspace,rw \
mkdir /dist && poetry build -o /dist
FROM scratch AS denokv-pkg
COPY --from=denokv-pkg-build /dist/* .
FROM scratch AS denokv-bin
COPY --from=ghcr.io/denoland/denokv:latest /usr/local/bin/denokv /denokv
FROM python-base AS test-package-install
COPY --from=denokv-bin /denokv /usr/local/bin/denokv
RUN python -m venv /env
ENV PATH=/env/bin:$PATH
RUN --mount=from=smoketest-pkg,target=/pkg/smoketest \
--mount=from=denokv-pkg,target=/pkg/denokv \
--mount=type=cache,target=/root/.cache \
pip install /pkg/smoketest/*.whl /pkg/denokv/*.whl
FROM test-package-install AS test-package
RUN pip list
RUN denokv-python-smoketest
FROM scratch AS protoc-zip-arm64
ARG PROTOC_VERSION
ADD "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-aarch_64.zip" /
FROM scratch AS protoc-zip-amd64
ARG PROTOC_VERSION
ADD "https://github.com/protocolbuffers/protobuf/releases/download/v${PROTOC_VERSION}/protoc-${PROTOC_VERSION}-linux-x86_64.zip" /
FROM protoc-zip-${TARGETARCH} AS protoc-zip
FROM python-base AS protoc
RUN apt-get update && apt-get install -y --no-install-recommends unzip
RUN --mount=from=protoc-zip,source=/,dst=/protoc-zip \
unzip /protoc-zip/protoc-*.zip bin/protoc -d /usr/local
WORKDIR /build
COPY --from=denokv-repo proto/schema proto/schema
FROM protoc AS build-datapath-protobuf-python
RUN protoc --version
RUN mkdir -p out
RUN protoc --proto_path=proto/schema --python_out=out --pyi_out=out datapath.proto
FROM scratch AS datapath-protobuf-python
COPY --from=build-datapath-protobuf-python /build/out/* .