Add Docker support with build and push workflow, and configure Gunicorn for application serving
All checks were successful
Build and push Docker image / build (push) Successful in 2m14s

This commit is contained in:
Edgar P. Burkhart 2025-06-14 16:43:38 +02:00
parent 3d180d3359
commit fd09bf8aa3
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
6 changed files with 67 additions and 0 deletions

View file

@ -0,0 +1,29 @@
name: Build and push Docker image
on:
push:
tags:
- 'v*'
jobs:
build:
runs-on: ubuntu-latest
steps:
-
name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: code.edgarpierre.fr
username: ${{ vars.DOCKER_PUSH_USERNAME }}
password: ${{ secrets.DOCKER_PUSH_PASSWORD }}
-
name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
-
name: Build and push
uses: docker/build-push-action@v6
with:
push: true
tags: |
code.edgarpierre.fr/${{ github.repository }}:${{ github.ref_name }}
code.edgarpierre.fr/${{ github.repository }}:latest

17
Dockerfile Normal file
View file

@ -0,0 +1,17 @@
FROM ghcr.io/astral-sh/uv:debian-slim
ADD . /app
WORKDIR /app
RUN useradd -m -r musik && \
chown -R musik /app
USER musik
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1
ENV YOUTUBE_OAUTH_SECRETS="/config/secret.json"
RUN uv sync --locked
CMD ["/app/entrypoint.sh"]

5
entrypoint.sh Executable file
View file

@ -0,0 +1,5 @@
#!/usr/bin/env sh
cd /app
uv run manage.py collectstatic --noinput
uv run manage.py migrate --noinput
uv run gunicorn --bind :8000 --workers 2 musik.wsgi:application

View file

@ -119,6 +119,7 @@ USE_TZ = True
# https://docs.djangoproject.com/en/5.2/howto/static-files/
STATIC_URL = "static/"
STATIC_ROOT = os.getenv("MUSIK_STATIC_ROOT", "./static")
# Default primary key field type
# https://docs.djangoproject.com/en/5.2/ref/settings/#default-auto-field

View file

@ -11,6 +11,7 @@ dependencies = [
"google-auth>=2.40.3",
"google-auth-httplib2>=0.2.0",
"google-auth-oauthlib>=1.2.2",
"gunicorn>=23.0.0",
"requests>=2.32.4",
]

14
uv.lock generated
View file

@ -342,6 +342,18 @@ wheels = [
{ url = "https://files.pythonhosted.org/packages/86/f1/62a193f0227cf15a920390abe675f386dec35f7ae3ffe6da582d3ade42c7/googleapis_common_protos-1.70.0-py3-none-any.whl", hash = "sha256:b8bfcca8c25a2bb253e0e0b0adaf8c00773e5e6af6fd92397576680b807e0fd8", size = 294530, upload-time = "2025-04-14T10:17:01.271Z" },
]
[[package]]
name = "gunicorn"
version = "23.0.0"
source = { registry = "https://pypi.org/simple" }
dependencies = [
{ name = "packaging" },
]
sdist = { url = "https://files.pythonhosted.org/packages/34/72/9614c465dc206155d93eff0ca20d42e1e35afc533971379482de953521a4/gunicorn-23.0.0.tar.gz", hash = "sha256:f014447a0101dc57e294f6c18ca6b40227a4c90e9bdb586042628030cba004ec", size = 375031, upload-time = "2024-08-10T20:25:27.378Z" }
wheels = [
{ url = "https://files.pythonhosted.org/packages/cb/7d/6dac2a6e1eba33ee43f318edbed4ff29151a49b5d37f080aad1e6469bca4/gunicorn-23.0.0-py3-none-any.whl", hash = "sha256:ec400d38950de4dfd418cff8328b2c8faed0edb0d517d3394e457c317908ca4d", size = 85029, upload-time = "2024-08-10T20:25:24.996Z" },
]
[[package]]
name = "httplib2"
version = "0.22.0"
@ -420,6 +432,7 @@ dependencies = [
{ name = "google-auth" },
{ name = "google-auth-httplib2" },
{ name = "google-auth-oauthlib" },
{ name = "gunicorn" },
{ name = "requests" },
]
@ -437,6 +450,7 @@ requires-dist = [
{ name = "google-auth", specifier = ">=2.40.3" },
{ name = "google-auth-httplib2", specifier = ">=0.2.0" },
{ name = "google-auth-oauthlib", specifier = ">=1.2.2" },
{ name = "gunicorn", specifier = ">=23.0.0" },
{ name = "requests", specifier = ">=2.32.4" },
]