Updated commit and build date capturing
It's now written to a build.txt file instead of using environment variables internally. Standalone installs now has this properly as well.
This commit is contained in:
5
.github/workflows/ci.yml
vendored
5
.github/workflows/ci.yml
vendored
@@ -83,6 +83,11 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
chmod +x scripts/*.sh
|
chmod +x scripts/*.sh
|
||||||
|
|
||||||
|
- name: Write build info
|
||||||
|
run: |
|
||||||
|
echo "GIT_COMMIT=$(git rev-parse --short HEAD)" > build.txt
|
||||||
|
echo "BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ")" >> build.txt
|
||||||
|
|
||||||
- name: Upload client Spoolman artifact
|
- name: Upload client Spoolman artifact
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -59,6 +59,10 @@ ARG BUILD_DATE=unknown
|
|||||||
ENV GIT_COMMIT=${GIT_COMMIT}
|
ENV GIT_COMMIT=${GIT_COMMIT}
|
||||||
ENV BUILD_DATE=${BUILD_DATE}
|
ENV BUILD_DATE=${BUILD_DATE}
|
||||||
|
|
||||||
|
# Write GIT_COMMIT and BUILD_DATE to a build.txt file
|
||||||
|
RUN echo "GIT_COMMIT=${GIT_COMMIT}" > build.txt \
|
||||||
|
&& echo "BUILD_DATE=${BUILD_DATE}" >> build.txt
|
||||||
|
|
||||||
# Run command
|
# Run command
|
||||||
EXPOSE 8000
|
EXPOSE 8000
|
||||||
ENTRYPOINT ["/home/app/spoolman/entrypoint.sh"]
|
ENTRYPOINT ["/home/app/spoolman/entrypoint.sh"]
|
||||||
|
|||||||
@@ -286,10 +286,16 @@ def get_commit_hash() -> Optional[str]:
|
|||||||
Returns:
|
Returns:
|
||||||
Optional[str]: The commit hash.
|
Optional[str]: The commit hash.
|
||||||
"""
|
"""
|
||||||
commit_hash = os.getenv("GIT_COMMIT", "unknown")
|
# Read commit has from build.txt
|
||||||
if commit_hash == "unknown":
|
# commit is written as GIT_COMMIT=<hash> in build.txt
|
||||||
|
build_file = Path("build.txt")
|
||||||
|
if not build_file.exists():
|
||||||
|
return None
|
||||||
|
with build_file.open(encoding="utf-8") as f:
|
||||||
|
for line in f:
|
||||||
|
if line.startswith("GIT_COMMIT="):
|
||||||
|
return line.split("=")[1].strip()
|
||||||
return None
|
return None
|
||||||
return commit_hash
|
|
||||||
|
|
||||||
|
|
||||||
def get_build_date() -> Optional[datetime]:
|
def get_build_date() -> Optional[datetime]:
|
||||||
@@ -298,10 +304,16 @@ def get_build_date() -> Optional[datetime]:
|
|||||||
Returns:
|
Returns:
|
||||||
Optional[datetime.datetime]: The build date.
|
Optional[datetime.datetime]: The build date.
|
||||||
"""
|
"""
|
||||||
build_date = os.getenv("BUILD_DATE", "unknown")
|
# Read build date has from build.txt
|
||||||
if build_date == "unknown":
|
# build date is written as BUILD_DATE=<hash> in build.txt
|
||||||
|
build_file = Path("build.txt")
|
||||||
|
if not build_file.exists():
|
||||||
|
return None
|
||||||
|
with build_file.open(encoding="utf-8") as f:
|
||||||
|
for line in f:
|
||||||
|
if line.startswith("BUILD_DATE="):
|
||||||
|
return datetime.fromisoformat(line.split("=")[1].strip())
|
||||||
return None
|
return None
|
||||||
return datetime.fromisoformat(build_date)
|
|
||||||
|
|
||||||
|
|
||||||
def can_write_to_data_dir() -> bool:
|
def can_write_to_data_dir() -> bool:
|
||||||
|
|||||||
Reference in New Issue
Block a user