feat: Update Dockerfile to use new UV system
All checks were successful
Check Code Quality / RuffCheck (push) Successful in 2m44s
Build Docker / BuildImage (push) Successful in 3m15s

Also fixes error in spotify refreshing
This commit is contained in:
2025-11-01 12:17:25 +11:00
parent 1888160fa5
commit b8f3039629
3 changed files with 39 additions and 10 deletions

19
.dockerignore Normal file
View File

@@ -0,0 +1,19 @@
__pycache__/
.env
.vs/
.venv/
*.tmp
testing/
tests/
.vscode/
.ruff_check/
.gitea/
# Random files
README.md
LICENSE.txt
NathanWoodburn.bsdesign
Dockerfile

View File

@@ -1,18 +1,24 @@
FROM --platform=$BUILDPLATFORM python:3.13-alpine AS builder FROM --platform=$BUILDPLATFORM python:3.13-alpine
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
RUN apk add curl # Set working directory
WORKDIR /app WORKDIR /app
COPY requirements.txt /app # Install dependencies
RUN --mount=type=cache,target=/root/.cache/pip \ RUN --mount=type=cache,target=/root/.cache/uv \
python3 -m pip install -r requirements.txt --mount=type=bind,source=uv.lock,target=uv.lock \
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \
uv sync --locked --no-install-project
COPY . /app # Copy the project into the image
ADD . /app
# Sync the project
RUN --mount=type=cache,target=/root/.cache/uv \
uv sync --locked
# Add mount point for data volume # Add mount point for data volume
# VOLUME /data # VOLUME /data
ENTRYPOINT ["python3"] ENTRYPOINT ["uv", "run"]
CMD ["main.py"] CMD ["main.py"]
FROM builder AS dev-envs

View File

@@ -25,6 +25,10 @@ def refresh_access_token():
"""Refresh Spotify access token when expired.""" """Refresh Spotify access token when expired."""
global ACCESS_TOKEN, TOKEN_EXPIRES global ACCESS_TOKEN, TOKEN_EXPIRES
# If no refresh token, cannot proceed
if not REFRESH_TOKEN:
return None
# If still valid, reuse it # If still valid, reuse it
if ACCESS_TOKEN and time.time() < TOKEN_EXPIRES - 60: if ACCESS_TOKEN and time.time() < TOKEN_EXPIRES - 60:
return ACCESS_TOKEN return ACCESS_TOKEN
@@ -100,7 +104,7 @@ def get_spotify_track():
"""Internal function to get current playing track without HTTP context.""" """Internal function to get current playing track without HTTP context."""
token = refresh_access_token() token = refresh_access_token()
if not token: if not token:
return json_response(request, {"error": "Failed to refresh access token"}, 500) return {"error": "Failed to refresh access token"}
headers = {"Authorization": f"Bearer {token}"} headers = {"Authorization": f"Bearer {token}"}
response = requests.get(SPOTIFY_CURRENTLY_PLAYING_URL, headers=headers) response = requests.get(SPOTIFY_CURRENTLY_PLAYING_URL, headers=headers)