This is an automated email from the ASF dual-hosted git repository.
sbp pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tooling-atr-experiments.git
The following commit(s) were added to refs/heads/main by this push:
new a949a7b Use dunamai inside containers to discover the version
a949a7b is described below
commit a949a7b094120da0ab8bef9c0c4435ded0c90bc4
Author: Sean B. Palmer <[email protected]>
AuthorDate: Tue Mar 4 21:19:18 2025 +0200
Use dunamai inside containers to discover the version
---
.dockerignore | 1 -
Dockerfile.alpine | 20 ++++++++------------
Dockerfile.ubuntu | 21 +++++++++------------
atr/server.py | 6 +++---
atr/version.py | 16 +++++++++++-----
pyproject.toml | 2 +-
6 files changed, 32 insertions(+), 34 deletions(-)
diff --git a/.dockerignore b/.dockerignore
index a6a542e..3cb4c14 100644
--- a/.dockerignore
+++ b/.dockerignore
@@ -5,7 +5,6 @@
.Python
.coverage
.dmypy.json
-.git
.gitignore
.hypothesis/
.mypy_cache/
diff --git a/Dockerfile.alpine b/Dockerfile.alpine
index 052b5fc..88b70d2 100644
--- a/Dockerfile.alpine
+++ b/Dockerfile.alpine
@@ -4,10 +4,6 @@ ARG BIND=127.0.0.1:8080
ENV BIND=${BIND}
ARG SCRIPTS=scripts/poetry
ENV SCRIPTS=${SCRIPTS}
-ARG VERSION=unknown
-ENV VERSION=${VERSION}
-ARG COMMIT=unknown
-ENV COMMIT=${COMMIT}
# gcompat is required for ruff to work
# # go is required for syft
@@ -32,18 +28,18 @@ ENV PYTHONUNBUFFERED=1
RUN pip3 install setuptools wheel pip-tools poetry
WORKDIR /opt/atr
COPY . /opt/atr
-RUN mkdir -p /tmp/apache-rat && \
- cd /tmp/apache-rat && \
- curl -L
https://dlcdn.apache.org/creadur/apache-rat-0.16.1/apache-rat-0.16.1-bin.tar.gz
-o apache-rat.tar.gz && \
- tar -xzf apache-rat.tar.gz && \
- find apache-rat-0.16.1 -type f -name "*.jar" -exec cp {} . \; && \
- # Rename to match expected filename if needed
- [ -f apache-rat-0.16.1.jar ] || mv $(find . -maxdepth 1 -type f -name
"apache-rat*.jar" | head -1) apache-rat-0.16.1.jar
+RUN mkdir -p /tmp/apache-rat
+WORKDIR /tmp/apache-rat
+RUN curl -L
https://dlcdn.apache.org/creadur/apache-rat-0.16.1/apache-rat-0.16.1-bin.tar.gz
-o apache-rat.tar.gz
+RUN tar -xzf apache-rat.tar.gz
+RUN find apache-rat-0.16.1 -type f -name "*.jar" -exec cp {} . \;
+# Rename to match expected filename if needed
+RUN [ -f apache-rat-0.16.1.jar ] || mv $(find . -maxdepth 1 -type f -name
"apache-rat*.jar" | head -1) apache-rat-0.16.1.jar
RUN java -version
+WORKDIR /opt/atr
# TODO: We should pin the syft version
# RUN GOPATH=/usr/local go install github.com/anchore/syft/cmd/syft@latest
RUN curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh
| sh -s -- -b /usr/local/bin
-RUN sed -i "s%ATR-VERSION%${VERSION}%" atr/templates/includes/footer.html
RUN rm -rf .venv-*
RUN make sync PYTHON="$(which python3)"
EXPOSE 8080
diff --git a/Dockerfile.ubuntu b/Dockerfile.ubuntu
index c3ecd7b..3c923d9 100644
--- a/Dockerfile.ubuntu
+++ b/Dockerfile.ubuntu
@@ -5,10 +5,6 @@ ARG BIND=127.0.0.1:8080
ENV BIND=${BIND}
ARG SCRIPTS=scripts/poetry
ENV SCRIPTS=${SCRIPTS}
-ARG VERSION=unknown
-ENV VERSION=${VERSION}
-ARG COMMIT=unknown
-ENV COMMIT=${COMMIT}
RUN apt-get update && apt-get install -y \
curl \
@@ -29,19 +25,20 @@ ENV PYTHONUNBUFFERED=1
RUN rm -rf /usr/local && python3.13 -m venv /usr/local
RUN pip3 install setuptools wheel pip-tools poetry uv
WORKDIR /opt/atr
-RUN mkdir -p /tmp/apache-rat && \
- cd /tmp/apache-rat && \
- curl -L
https://dlcdn.apache.org/creadur/apache-rat-0.16.1/apache-rat-0.16.1-bin.tar.gz
-o apache-rat.tar.gz && \
- tar -xzf apache-rat.tar.gz && \
- find apache-rat-0.16.1 -type f -name "*.jar" -exec cp {} . \; && \
- # Rename to match expected filename if needed
- [ -f apache-rat-0.16.1.jar ] || mv $(find . -maxdepth 1 -type f -name
"apache-rat*.jar" | head -1) apache-rat-0.16.1.jar
+COPY . /opt/atr
+RUN mkdir -p /tmp/apache-rat
+WORKDIR /tmp/apache-rat
+RUN curl -L
https://dlcdn.apache.org/creadur/apache-rat-0.16.1/apache-rat-0.16.1-bin.tar.gz
-o apache-rat.tar.gz
+RUN tar -xzf apache-rat.tar.gz
+RUN find apache-rat-0.16.1 -type f -name "*.jar" -exec cp {} . \;
+# Rename to match expected filename if needed
+RUN [ -f apache-rat-0.16.1.jar ] || mv $(find . -maxdepth 1 -type f -name
"apache-rat*.jar" | head -1) apache-rat-0.16.1.jar
RUN java -version
+WORKDIR /opt/atr
# TODO: We should pin the syft version
# RUN GOPATH=/usr/local go install github.com/anchore/syft/cmd/syft@latest
RUN curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh
| sh -s -- -b /usr/local/bin
COPY . /opt/atr
-RUN sed -i "s%ATR-VERSION%${VERSION}%" atr/templates/includes/footer.html
RUN rm -rf .venv-*
RUN make sync PYTHON="$(find /usr/bin -name python3.13 | head -n 1)"
EXPOSE 8080
diff --git a/atr/server.py b/atr/server.py
index db256b2..1d47f72 100644
--- a/atr/server.py
+++ b/atr/server.py
@@ -121,13 +121,13 @@ def app_setup_context(app: QuartApp) -> None:
@app.context_processor
async def app_wide() -> dict[str, Any]:
from atr.util import is_admin
- from atr.version import __commit__, __version__
+ from atr.version import commit, version
return {
"current_user": await asfquart.session.read(),
"is_admin": is_admin,
- "commit": __commit__,
- "version": __version__,
+ "commit": commit,
+ "version": version,
}
diff --git a/atr/version.py b/atr/version.py
index c879c90..b338159 100644
--- a/atr/version.py
+++ b/atr/version.py
@@ -18,7 +18,7 @@
import os
-def _get_development_version() -> tuple[str, str] | None:
+def get_development_version() -> tuple[str, str] | None:
"""Returns the version when within a development environment."""
try:
@@ -29,7 +29,10 @@ def _get_development_version() -> tuple[str, str] | None:
return None
try:
- version = Version.from_git()
+ from pathlib import Path
+
+ # We start in state/, so we need to go up one level
+ version = Version.from_git(path=Path(".."))
if version.distance > 0:
return version.serialize(format="v{base}+{distance}.{commit}",
bump=True), version.serialize(
format="{commit}"
@@ -41,12 +44,15 @@ def _get_development_version() -> tuple[str, str] | None:
return None
-def _get_version_from_env() -> tuple[str, str | None]:
+def get_version_from_env() -> tuple[str, str | None]:
"""Returns the version from an environment variable."""
- return os.environ.get("VERSION", "undefined"), os.environ.get("COMMIT")
+ # Use the commit where dunamai was added by default
+ # TODO: Use a better default value
+ return os.environ.get("VERSION", "undefined"), os.environ.get("COMMIT",
"4e5bff1")
# Try to determine the version from a development environment first.
# If this fails, try to get it from environment variables that are set when
building a docker image.
-__version__, __commit__ = _get_development_version() or _get_version_from_env()
+# We don't use __version__ and __commit__ as these are not reserved words in
Python
+version, commit = get_development_version() or get_version_from_env()
diff --git a/pyproject.toml b/pyproject.toml
index 83825c1..d5218b0 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -15,6 +15,7 @@ dependencies = [
"asfquart", # TODO: convert asfquart from a source dependency to pypi or git
dependency
"blockbuster>=1.5.23,<2.0.0",
"cryptography~=44.0",
+ "dunamai>=1.23.0",
"greenlet>=3.1.1,<4.0.0",
"httpx~=0.27",
"hypercorn~=0.17",
@@ -32,7 +33,6 @@ dev = [
"pyright>=1.1.393",
"ruff>=0.9.4",
"types-aiofiles>=24.1.0.20241221,<25.0.0.0",
- "dunamai>=1.23.0"
]
test = [
"pytest>=8.0",
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]