Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Docker build and wheel dist build fixes #223

Merged
merged 5 commits into from
Apr 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ venv/
.git/
test_*.py
.github/
Dockerfile
*.Dockerfile
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ __pycache__/
.idea/
.pytest_cache/
.env*
dist/
!.env-template
rdf/
7 changes: 4 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ WORKDIR /app
COPY . .

RUN poetry build
RUN python -m venv --system-site-packages /opt/venv
RUN pip install --no-cache-dir dist/*.whl
RUN python3 -m venv --system-site-packages ${VIRTUAL_ENV}
RUN ${VIRTUAL_ENV}/bin/pip3 install --no-cache-dir dist/*.whl

#
# Final
Expand All @@ -50,6 +50,7 @@ RUN apk update && \
bash

WORKDIR /app
COPY . .
# prez module is already built as a package and installed in $VIRTUAL_ENV as a library
COPY main.py pyproject.toml ./

ENTRYPOINT uvicorn prez.app:app --host=${HOST:-0.0.0.0} --port=${PORT:-8000} --proxy-headers
21 changes: 18 additions & 3 deletions prez/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,24 @@ def get_version(cls, values):
values["prez_version"] = version

if version is None or version == "":
values["prez_version"] = toml.load(
Path(Path(__file__).parent.parent) / "pyproject.toml"
)["tool"]["poetry"]["version"]
possible_locations = (
# dir above /prez, this is present in dev environments
# this is also used by derived projects to override the app version
Path(__file__).parent.parent,
# _inside_ /prez module, this is present in wheel builds
Path(__file__).parent,
)
p: Path
for p in possible_locations:
if (p / "pyproject.toml").exists():
values["prez_version"] = toml.load(p / "pyproject.toml")["tool"][
"poetry"
]["version"]
break
else:
raise RuntimeError(
"PREZ_VERSION not set, and cannot find a pyproject.toml to extract the version."
)

return values

Expand Down
14 changes: 14 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,20 @@ name = "prez"
version = "0.1.0.dev0"
description = "A python application for displaying linked data on the web"
authors = ["Jamie Feiss <jamie.feiss@gmail.com>", "Nicholas Car <nick@kurrawong.net>", "David Habgood <dcchabgood@gmail.com>"]
packages = [
{ include = "prez" },
{ include = "pyproject.toml", format = "wheel", to="prez" },
]
include = [
{ path = "./*.md", format = "sdist" },
{ path = "LICENSE", format = "sdist" },
{ path = "demo", format = "sdist" },
{ path = "dev", format = "sdist" },
{ path = "tests", format = "sdist" },
{ path = "poetry.lock", format = "sdist" },
{ path = "./*.whl", format = "sdist" },
{ path = "*.toml", format = "sdist" }
]

[tool.poetry.dependencies]
python = "^3.11"
Expand Down
Loading