Add Docker support with Dockerfile and entrypoint
All checks were successful
Docker / build (push) Successful in 28s
All checks were successful
Docker / build (push) Successful in 28s
This commit is contained in:
parent
faf880a236
commit
4bc1afa0cb
8 changed files with 118 additions and 2 deletions
|
|
@ -50,3 +50,6 @@ DB_ENGINE=sqlite
|
||||||
#DB_PASSWORD=
|
#DB_PASSWORD=
|
||||||
#DB_HOST=localhost
|
#DB_HOST=localhost
|
||||||
#DB_PORT=5432
|
#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: Set image tag
|
||||||
|
id: meta
|
||||||
|
run: |
|
||||||
|
if [[ "${GITHUB_REF}" == refs/tags/* ]]; then
|
||||||
|
echo "TAG=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "TAG=latest" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
|
||||||
|
- name: Login to Forgejo registry
|
||||||
|
uses: docker/login-action@v3
|
||||||
|
with:
|
||||||
|
registry: git.sinfonie.org
|
||||||
|
username: ${{ secrets.REGISTRY_USER }}
|
||||||
|
password: ${{ secrets.REGISTRY_TOKEN }}
|
||||||
|
|
||||||
|
- name: Build image
|
||||||
|
run: |
|
||||||
|
docker build -t git.sinfonie.org/sinfonie/photo26:${{ steps.meta.outputs.TAG }} .
|
||||||
|
|
||||||
|
- name: Push image
|
||||||
|
run: |
|
||||||
|
docker push git.sinfonie.org/sinfonie/photo26:${{ steps.meta.outputs.TAG }}
|
||||||
|
|
||||||
|
- name: Tag latest (for master)
|
||||||
|
if: github.ref == 'refs/heads/master'
|
||||||
|
run: |
|
||||||
|
docker tag git.sinfonie.org/sinfonie/photo26:${{ steps.meta.outputs.TAG }} git.sinfonie.org/sinfonie/photo26:latest
|
||||||
|
docker push git.sinfonie.org/sinfonie/photo26: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 = {
|
DATABASES = {
|
||||||
"default": {
|
"default": {
|
||||||
"ENGINE": "django.db.backends.sqlite3",
|
"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": {
|
"OPTIONS": {
|
||||||
"timeout": 10,
|
"timeout": 10,
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -7,5 +7,6 @@ Pillow>=6.0.0
|
||||||
django-debug-toolbar>=3.2.0
|
django-debug-toolbar>=3.2.0
|
||||||
python-decouple>=3.6
|
python-decouple>=3.6
|
||||||
whitenoise>=6.0
|
whitenoise>=6.0
|
||||||
psycopg2>=2.9
|
psycopg2-binary>=2.9
|
||||||
requests>=2.25
|
requests>=2.25
|
||||||
|
gunicorn>=21.0
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue