-
Notifications
You must be signed in to change notification settings - Fork 0
/
Earthfile
100 lines (88 loc) · 3.27 KB
/
Earthfile
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
VERSION 0.8
# install-base configures the base image for the project
# - creates a virtual environment for Poetry
# - installs Poetry from `poetry/requirements.txt`
install-base:
FROM DOCKERFILE --target=python .
WORKDIR /srv/workspace
ENV VENV_PATH="/opt/poetry"
ENV PATH="${VENV_PATH}/bin:$PATH"
COPY poetry/requirements.txt .
RUN python -m venv $VENV_PATH && \
${VENV_PATH}/bin/pip install \
--no-cache-dir \
--require-hashes \
--use-pep517 \
--quiet \
--requirement requirements.txt && \
rm -rf requirements.txt
# generate-requirements generates the `poetry/requirements.txt` file
# - uses pip-compile to generate a list of dependencies from `poetry/requirements.in
generate-requirements:
FROM +install-base
COPY poetry/requirements.in .
RUN pip-compile \
--allow-unsafe \
--annotate \
--generate-hashes \
--output-file requirements.txt \
--rebuild \
--resolver backtracking \
requirements.in
SAVE ARTIFACT /srv/workspace/requirements.txt AS LOCAL poetry/requirements.txt
# configure installs the library dependencies
configure:
FROM +install-base
COPY poetry.toml pyproject.toml ./
COPY mkdocs.yml ./
RUN poetry install --sync --no-root
COPY --dir src gen tests examples scripts docs .
RUN poetry install --sync
# upgrade-dependencies upgrades the library dependencies to their latest compatible version
# using `poetry-plugin-upgrade`
upgrade-dependencies:
FROM +configure
RUN poetry upgrade --latest
SAVE ARTIFACT /srv/workspace/pyproject.toml AS LOCAL pyproject.toml
# update-dependencies updates the library dependencies to their latest compatible version
# according to the constraints in `pyproject.toml`
update-dependencies:
FROM +configure
RUN poetry lock
# generate generates code from the APIs declarations
generate:
ARG APIS_REF="main"
BUILD github.com/volur-ai/apis:$APIS_REF+generate-python
# fix fixes all auto-fixable formatting and linting issues
fix:
FROM +configure
RUN poetry run ruff format src tests examples scripts && \
poetry run ruff check --fix --unsafe-fixes src tests examples scripts
SAVE ARTIFACT /srv/workspace/src AS LOCAL src
SAVE ARTIFACT /srv/workspace/tests AS LOCAL tests
SAVE ARTIFACT /srv/workspace/examples AS LOCAL examples
SAVE ARTIFACT /srv/workspace/scripts AS LOCAL scripts
# validate validates the library (project configuration, linting and static
# type checking)
validate:
FROM +configure
RUN poetry check --lock && \
poetry run ruff format --check src tests scripts && \
poetry run ruff check src tests scripts && \
poetry run mypy src tests scripts
# test runs the library unit tests
test:
FROM +configure
RUN poetry run pytest tests
SAVE ARTIFACT /srv/workspace/.coverage AS LOCAL .coverage
SAVE ARTIFACT /srv/workspace/htmlcov AS LOCAL htmlcov
# build-docs builds the documentation using mkdocs
build-docs:
FROM +configure
RUN poetry run mkdocs build
SAVE ARTIFACT /srv/workspace/site AS LOCAL site
# ci runs the CI pipeline (linting, static type checking, unit tests, documentation generation) locally
ci:
BUILD +validate
BUILD +test
BUILD +build-docs