user/tandoor-recipes: new aport

This commit is contained in:
Antoine Martin 2024-01-04 20:59:56 -05:00
parent 261bedbaac
commit ae18f93da1
8 changed files with 289 additions and 0 deletions

View file

@ -0,0 +1,134 @@
# Contributor: Antoine Martin (ayakael) <dev@ayakael.net>
# Maintainer: Antoine Martin (ayakael) <dev@ayakael.net>
pkgname=tandoor-recipes
pkgver=1.5.10
pkgrel=0
pkgdesc="Application for managing recipes, planning meals, building shopping lists, etc."
arch="noarch"
url="https://github.com/TandoorRecipes/recipes"
license="AGPL-3.0-only"
depends="
postgresql
postgresql-contrib
procps-ng
pwgen
py3-beautifulsoup4
py3-bleach
py3-boto3
py3-crispy-bootstrap4
py3-cryptography
py3-django
py3-django-allauth
py3-django-annoying
py3-django-auth-ldap
py3-django-autocomplete-light
py3-django-cleanup
py3-django-cors-headers
py3-django-crispy-forms
py3-django-debug-toolbar
py3-django-hcaptcha
py3-django-js-reverse
py3-django-oauth-toolkit
py3-django-prometheus
py3-django-rest-framework
py3-django-scopes
py3-django-storages
py3-django-tables2
py3-django-treebeard
py3-django-webpack-loader
py3-dotenv
py3-drf-writable-nested
py3-gunicorn
py3-icalendar
py3-jinja2
py3-ldap
py3-lxml
py3-markdown
py3-microdata
py3-pillow
py3-psycopg2
py3-pyppeteer
py3-pytest
py3-pytest-django
py3-pytest-factoryboy
py3-pytube
py3-recipe-scrapers
py3-requests
py3-six
py3-uritemplate
py3-validators~=0.20
py3-webdavclient3
py3-whitenoise
py3-yaml
nginx
xsel
"
makedepends="nodejs postgresql postgresql-libs py3-virtualenv nginx yarn npm"
source="
$pkgname-$pkgver.tar.gz::https://github.com/TandoorRecipes/recipes/archive/refs/tags/$pkgver.tar.gz
recipes.openrc
recipes.nginx
recipes-manage.sh
allauth-0.58-fix.patch
"
builddir="$srcdir"/recipes-$pkgver
install="$pkgname.post-install $pkgname.post-upgrade $pkgname.pre-install"
subpackages="$pkgname-openrc"
pkgusers="recipes"
pkggroups="recipes"
build() {
cd ./vue
msg "Building nodejs libraries"
yarn --cache-folder "$srcdir"/yarn-cache --ignore-engines install
yarn --cache-folder "$srcdir"/yarn-cache build
cd ../
msg "Building static files"
./manage.py collectstatic --no-input
./manage.py collectstatic_js_reverse
echo "TANDOOR_VERSION = '$pkgver'" > cookbook/version_info.py
echo "TANDOOR_REF = '$pkgver'" >> cookbook/version_info.py
echo "VERSION_INFO = [{'name': 'Tandoor ', 'version': '$pkgver', 'website': 'https://github.com/TandoorRecipes/recipes', 'commit_link': 'https://github.com/TandoorRecipes/recipes/releases/tag/$pkgver', 'ref': '$pkgver', 'branch': 'master', 'tag': '$pkgver'}]" >> cookbook/version_info.py
}
package() {
# install files
mkdir -p "$pkgdir"/usr/share/webapps/recipes
cp -r manage.py vue recipes staticfiles cookbook "$pkgdir"/usr/share/webapps/recipes
ln -s /etc/tandoor/recipes.conf "$pkgdir"/usr/share/webapps/recipes/.env
rm -rf \
"$pkgdir"/usr/share/webapps/recipes/vue/node_modules/.cache \
"$pkgdir"/usr/share/webapps/recipes/vue/node_modules/clipboardy/fallbacks
# openrc and configs
install -Dm755 "$srcdir"/recipes.openrc \
"$pkgdir"/etc/init.d/recipes
install -Dm755 "$srcdir"/recipes.nginx \
"$pkgdir"/etc/nginx/http.d/recipes.conf
install -Dm755 "$builddir"/nginx/conf.d/errorpages/http502.html \
"$pkgdir"/etc/nginx/http.d/errorpages/http502.html
install -Dm640 "$builddir"/.env.template \
"$pkgdir"/etc/tandoor/recipes.conf
chown root:www-data "$pkgdir"/etc/tandoor/recipes.conf
sed -i 's|SECRET_KEY=|SECRET_KEY=@@SECRET_KEY@@|' "$pkgdir"/etc/tandoor/recipes.conf
sed -i 's|POSTGRES_HOST.*|POSTGRES_HOST=127.0.0.1|' "$pkgdir"/etc/tandoor/recipes.conf
sed -i 's|POSTGRES_USER.*|POSTGRES_USER=recipes|' "$pkgdir"/etc/tandoor/recipes.conf
sed -i 's|POSTGRES_DB.*|POSTGRES_DB=recipes|' "$pkgdir"/etc/tandoor/recipes.conf
# Install wrapper script to /usr/bin.
install -m755 -D "$srcdir"/recipes-manage.sh \
"$pkgdir"/usr/bin/recipes-manage
# ln
ln -s /var/lib/recipes/media "$pkgdir"/usr/share/webapps/recipes/mediafiles
}
sha512sums="
ae2569bc7e81ad509bafe7c605cbc5628037f03bc9dec3280df23f21a637de0c4643332520e6486b77df9e97cb21012abac2e82e1e1781d47fffed9253133180 tandoor-recipes-1.5.10.tar.gz
6d53affec525207a86d8b26c6e5ac7a16586756520e5605f7fe1ea82212a93d051237da45893c8b4002a6663e7538d8e78ab7fc392dc420ba7e31e0cb11d3cae recipes.openrc
1ae29eb9342ad697d0e1e0cc600cd63c4ea6ce3f92b2bdc26602a95015b9ee91f1d40df65e92cad53b980fa3c15989ca9874bd0df62d6c7030ea97d396e37d2c recipes.nginx
521bc8c71bbf900bb37ef2db4d79ab16c3a068d74de57d8cfbe82feffab6041c58f94ddbb57ac1f8feb68535dd32679b79169454abfc4fa04548b025282ca507 recipes-manage.sh
a15d71798185aa4cb6da7d2f3d1610b53d6d876750d1706793c59582db1d930fd62295e02c68628b1324e379db7d6c6cd8a63fb905d2b3739aa81fc57a304368 allauth-0.58-fix.patch
"

View file

@ -0,0 +1,12 @@
diff --git a/recipes/settings.py.orig b/recipes/settings.py
index 8673962..6a6490b 100644
--- a/recipes/settings.py.orig
+++ b/recipes/settings.py
@@ -218,6 +218,7 @@ MIDDLEWARE = [
'django.middleware.locale.LocaleMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'cookbook.helper.scope_middleware.ScopeMiddleware',
+ 'allauth.account.middleware.AccountMiddleware',
]
if DEBUG_TOOLBAR:

View file

@ -0,0 +1,11 @@
#!/bin/sh
BUNDLE_DIR='/usr/share/webapps/recipes'
cd $BUNDLE_DIR
if [ "$(id -un)" != 'recipes' ]; then
exec su recipes -c '"$0" "$@"' -- ./manage.py "$@"
else
exec ./manage.py "$@"
fi

View file

@ -0,0 +1,29 @@
server {
listen 80;
server_name localhost;
client_max_body_size 128M;
# serve media files
location /static/ {
alias /usr/share/webapps/recipes/staticfiles/;
}
location /media/ {
alias /var/lib/recipes/media/;
}
location / {
proxy_set_header Host $http_host;
proxy_pass http://unix:/run/recipes/recipes.sock;
proxy_set_header X-Forwarded-Proto $scheme;
error_page 502 /errors/http502.html;
}
location /errors/ {
alias /etc/nginx/http.d/errorpages/;
internal;
}
}

View file

@ -0,0 +1,36 @@
#!/sbin/openrc-run
name="$RC_SVCNAME"
cfgfile="/etc/conf.d/$RC_SVCNAME.conf"
pidfile="/run/recipes/$RC_SVCNAME.pid"
working_directory="/usr/share/webapps/recipes"
command="/usr/bin/gunicorn"
command_args="
--error-logfile /var/log/recipes/gunicorn_err.log
--log-level debug
--capture-output
--bind unix:/run/recipes/recipes.sock
recipes.wsgi:application
"
command_user="recipes"
command_group="www-data"
start_stop_daemon_args=""
command_background="yes"
depend() {
need postgresql
need nginx
}
start_pre() {
cd "$working_directory"
checkpath --directory --owner $command_user:$command_group --mode 0775 \
/var/log/recipes \
/run/recipes \
/var/lib/recipes/media
}
stop_pre() {
ebegin "Killing child processes"
kill $(ps -o pid= --ppid $(cat $pidfile)) || true
}

View file

@ -0,0 +1,41 @@
#!/bin/sh
set -eu
config_file='/etc/tandoor/recipes.conf'
if [ $(grep '@@SECRET_KEY@@' "$config_file") ]; then
echo "* Generating random secret in $config_file" >&2
secret_key="$(pwgen -s 50 1)"
sed -i "s|@@SECRET_KEY@@|$secret_key|" "$config_file"
fi
if [ "${0##*.}" = 'post-upgrade' ]; then
cat >&2 <<-EOF
*
* To finish Recipes upgrade run:
*
* recipes-manage migrate
*
EOF
else
cat >&2 <<-EOF
*
* 1. Adjust settings in $config_file
*
* 2. Create database for Recipes:
*
* psql -c "CREATE ROLE recipes PASSWORD 'top-secret' INHERIT LOGIN;"
* psql -c "CREATE DATABASE recipes OWNER recipes ENCODING 'UTF-8';"
* psql -c "CREATE EXTENSION pg_trgm;"
*
* 3. User optimizations:
*
* psql -c "ALTER ROLE recipes SET client_encoding TO 'utf8';"
* psql -c "ALTER ROLE recipes SET default_transaction_isolation TO 'read committed';"
* psql -c "ALTER ROLE recipes SET timezone TO 'UTC';"
*
* 4. Run "recipes-manage migrate"
*
EOF
fi

View file

@ -0,0 +1 @@
tandoor-recipes.post-install

View file

@ -0,0 +1,25 @@
#!/bin/sh
recipes_dir='/var/lib/recipes'
if ! getent group recipes 1>/dev/null; then
echo '* Creating group recipes' 1>&2
addgroup -S recipes
fi
if ! id recipes 2>/dev/null 1>&2; then
echo '* Creating user recipes' 1>&2
adduser -DHS -G recipes -h "$recipes_dir" -s /bin/sh \
-g "added by apk for recipes" recipes
passwd -u recipes 1>/dev/null # unlock
fi
if ! id -Gn recipes | grep -Fq www-data; then
echo '* Adding user recipes to group www-data' 1>&2
addgroup recipes www-data
fi
exit 0