Add Docker support with Dockerfile and entrypoint.
Some checks failed
Docker / build (push) Failing after 25s
Some checks failed
Docker / build (push) Failing after 25s
This commit is contained in:
parent
faf880a236
commit
914d0edc6b
8 changed files with 118 additions and 2 deletions
|
|
@ -50,3 +50,6 @@ DB_ENGINE=sqlite
|
|||
#DB_PASSWORD=
|
||||
#DB_HOST=localhost
|
||||
#DB_PORT=5432
|
||||
|
||||
# SQLite settings (only used when DB_ENGINE=sqlite)
|
||||
#DB_PATH=/app/data/db.sqlite3
|
||||
|
|
|
|||
44
.forgejo/workflows/docker.yml
Normal file
44
.forgejo/workflows/docker.yml
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
name: Docker
|
||||
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- master
|
||||
tags:
|
||||
- 'v*'
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
|
||||
- name: Log in to Codeberg registry
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
uses: docker/login-action@v3
|
||||
with:
|
||||
registry: codeberg.org
|
||||
username: ${{ secrets.REGISTRY_USER }}
|
||||
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||
|
||||
- name: Extract version tag
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
id: meta
|
||||
run: echo "tag=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
|
||||
|
||||
- name: Build (verify only, no push)
|
||||
if: github.ref == 'refs/heads/master'
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
push: false
|
||||
|
||||
- name: Build and push (tagged release)
|
||||
if: startsWith(github.ref, 'refs/tags/')
|
||||
uses: docker/build-push-action@v5
|
||||
with:
|
||||
context: .
|
||||
push: true
|
||||
tags: |
|
||||
codeberg.org/${{ github.repository }}:${{ steps.meta.outputs.tag }}
|
||||
codeberg.org/${{ github.repository }}:latest
|
||||
22
Dockerfile
Normal file
22
Dockerfile
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
FROM python:3.11-slim
|
||||
|
||||
ENV PYTHONDONTWRITEBYTECODE=1
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY requirements.txt .
|
||||
RUN pip install --no-cache-dir -r requirements.txt
|
||||
|
||||
COPY . .
|
||||
|
||||
# Create volume mount points
|
||||
RUN mkdir -p /app/media /app/static /app/data
|
||||
|
||||
# Collect static files at build time (uses a dummy key, no DB needed)
|
||||
RUN SECRET_KEY=build-time-placeholder DB_ENGINE=sqlite python manage.py collectstatic --noinput
|
||||
|
||||
EXPOSE 8000
|
||||
|
||||
RUN chmod +x entrypoint.sh
|
||||
ENTRYPOINT ["./entrypoint.sh"]
|
||||
12
allauth_oauth/apps.py
Normal file
12
allauth_oauth/apps.py
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
# This file is part of photo21
|
||||
# Copyright (C) 2022 Amicale des élèves de l'ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from django.apps import AppConfig
|
||||
|
||||
|
||||
class AllauthOAuthConfig(AppConfig):
|
||||
name = "allauth_oauth"
|
||||
|
||||
def ready(self):
|
||||
import allauth_oauth.signals # noqa: F401
|
||||
29
allauth_oauth/signals.py
Normal file
29
allauth_oauth/signals.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
# This file is part of photo21
|
||||
# Copyright (C) 2022 Amicale des élèves de l'ENS Paris-Saclay
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
from allauth.socialaccount.signals import pre_social_login
|
||||
from django.dispatch import receiver
|
||||
|
||||
|
||||
@receiver(pre_social_login)
|
||||
def sync_user_fields(sender, request, sociallogin, **kwargs):
|
||||
if not sociallogin.is_existing:
|
||||
return
|
||||
|
||||
user = sociallogin.user
|
||||
data = sociallogin.account.extra_data
|
||||
changed = False
|
||||
|
||||
email = data.get("email")
|
||||
if email and user.email != email:
|
||||
user.email = email
|
||||
changed = True
|
||||
|
||||
username = data.get("username")
|
||||
if username and user.username != username:
|
||||
user.username = username
|
||||
changed = True
|
||||
|
||||
if changed:
|
||||
user.save()
|
||||
5
entrypoint.sh
Normal file
5
entrypoint.sh
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
#!/bin/sh
|
||||
set -e
|
||||
|
||||
python manage.py migrate --noinput
|
||||
exec gunicorn photo21.wsgi:application --bind 0.0.0.0:8000 --workers 3
|
||||
|
|
@ -153,7 +153,7 @@ elif _db_engine == "sqlite":
|
|||
DATABASES = {
|
||||
"default": {
|
||||
"ENGINE": "django.db.backends.sqlite3",
|
||||
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
|
||||
"NAME": config("DB_PATH", default=os.path.join(BASE_DIR, "db.sqlite3")),
|
||||
"OPTIONS": {
|
||||
"timeout": 10,
|
||||
},
|
||||
|
|
|
|||
|
|
@ -7,5 +7,6 @@ Pillow>=6.0.0
|
|||
django-debug-toolbar>=3.2.0
|
||||
python-decouple>=3.6
|
||||
whitenoise>=6.0
|
||||
psycopg2>=2.9
|
||||
psycopg2-binary>=2.9
|
||||
requests>=2.25
|
||||
gunicorn>=21.0
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue