feat: Update Dockerfile to use new UV system
Also fixes error in spotify refreshing
This commit is contained in:
19
.dockerignore
Normal file
19
.dockerignore
Normal 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
|
||||
24
Dockerfile
24
Dockerfile
@@ -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
|
||||
|
||||
COPY requirements.txt /app
|
||||
RUN --mount=type=cache,target=/root/.cache/pip \
|
||||
python3 -m pip install -r requirements.txt
|
||||
# Install dependencies
|
||||
RUN --mount=type=cache,target=/root/.cache/uv \
|
||||
--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
|
||||
# VOLUME /data
|
||||
|
||||
ENTRYPOINT ["python3"]
|
||||
ENTRYPOINT ["uv", "run"]
|
||||
CMD ["main.py"]
|
||||
|
||||
FROM builder AS dev-envs
|
||||
|
||||
@@ -25,6 +25,10 @@ def refresh_access_token():
|
||||
"""Refresh Spotify access token when expired."""
|
||||
global ACCESS_TOKEN, TOKEN_EXPIRES
|
||||
|
||||
# If no refresh token, cannot proceed
|
||||
if not REFRESH_TOKEN:
|
||||
return None
|
||||
|
||||
# If still valid, reuse it
|
||||
if ACCESS_TOKEN and time.time() < TOKEN_EXPIRES - 60:
|
||||
return ACCESS_TOKEN
|
||||
@@ -100,7 +104,7 @@ def get_spotify_track():
|
||||
"""Internal function to get current playing track without HTTP context."""
|
||||
token = refresh_access_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}"}
|
||||
response = requests.get(SPOTIFY_CURRENTLY_PLAYING_URL, headers=headers)
|
||||
|
||||
Reference in New Issue
Block a user