Skip to content

Commit

Permalink
merge: main -> boilerplate
Browse files Browse the repository at this point in the history
sync

fix(ci): pnpm, action!

feat: opensearch and optimization for using production config
and fuck you, elasticsearch

fix(ci): only build check on boilerplate branch

chore: reconfig opensearch index config bc tenant issue

fix(cfg): config fixes

fix(cfg): idiot's config construction

fix(cfg): typo in env variable XD

fix(cfg): url parse stuff left a slash

fix(cfg): prod reconfig according rest deployment?!

fix(cfg): debug in prod confirmed??!!?

fix(cfg): env forced?? note to myself pls squash this

refactor(script): debug in production friendly scripts setup

fix(scripts): make manage.py script executable

sorry was making it on windows

fix(scripts): more executables

same like above

fix(cfg): env stuff fix

fix(scripts): add shebang

chore: create table, just in case backup

fix(search): improve search by adding seo_titles

why dont they add it already, it built in and suppose to help search?

cleanup(models): cleanup unused pyfiles?
should be alr, it boot, check 0 fail, whatever
  • Loading branch information
hUwUtao committed May 26, 2024
1 parent e83e379 commit 4e04411
Show file tree
Hide file tree
Showing 20 changed files with 81 additions and 113 deletions.
8 changes: 7 additions & 1 deletion .github/workflows/client.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
push:
branches:
- main
- boilerplate

jobs:
build-and-publish:
Expand All @@ -17,6 +18,10 @@ jobs:
with:
node-version: '18'

- uses: pnpm/action-setup@v4
with:
version: 9

- name: Install dependencies
run: pnpm install

Expand All @@ -33,6 +38,7 @@ jobs:
echo "registry=https://npm.pkg.github.com/" >> .npmrc
- name: Publish to GitHub Packages
run: pnpm publish --access public
if: github.ref == 'refs/heads/boilerplate'
run: pnpm publish --access public --no-git-checks
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,5 @@ pip-selfcheck.json
# End of https://www.toptal.com/developers/gitignore/api/python,virtualenv,node
/media/
/static/
.coverage
.coverage
!scripts
3 changes: 0 additions & 3 deletions blog/admin.py

This file was deleted.

1 change: 1 addition & 0 deletions blog/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class BlogPage(Page):
search_fields = Page.search_fields + [
index.SearchField('intro'),
index.SearchField('body'),
index.SearchField('seo_title')
]

content_panels = Page.content_panels + [
Expand Down
9 changes: 7 additions & 2 deletions fuhoblog/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,14 @@

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
import os
import dotenv

dotenv.load_dotenv()

PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
BASE_DIR = os.path.dirname(PROJECT_DIR)

SECRET_KEY = os.environ['SECRET_KEY'] or ''

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/
Expand All @@ -26,7 +30,7 @@
INSTALLED_APPS = [
# MVC stuff
'blog',
'search',
# 'search',
'gallery',
# Stuff
# 'wagtail.contrib.modeladmin',
Expand All @@ -37,6 +41,7 @@
'wagtail_localize',
'wagtail_localize.locales',
# API engine
'rest_framework',
'wagtail.api.v2',
# Whatever
'wagtail.contrib.forms',
Expand Down Expand Up @@ -186,4 +191,4 @@

# Base URL to use when referring to full URLs within the Wagtail admin backend -
# e.g. in notification emails. Don't include '/admin' or a trailing slash
WAGTAILADMIN_BASE_URL = 'http://example.com'
WAGTAILADMIN_BASE_URL = 'http://example.com'
2 changes: 1 addition & 1 deletion fuhoblog/settings/dev.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'

INSTALLED_APPS += ['rest_framework']
INSTALLED_APPS += []

try:
from .local import *
Expand Down
60 changes: 45 additions & 15 deletions fuhoblog/settings/production.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,56 @@
from .base import *

DEBUG = False
import os
from urllib.parse import urlparse

ENV_KEYS = ['DB_NAME', 'DB_HOST', 'DB_PORT', 'DB_PASS', 'DB_USER']
ENV_VARS = list(map(os.environ.get, ENV_KEYS))
os.environ.setdefault('DJANGO_DEBUG', 'False')

DEBUG = False or (os.environ['DJANGO_DEBUG'] == 'True')

if SECRET_KEY == '':
print('no SECRET_KEY env')
exit(1)

DATABASES = DATABASES
WAGTAILSEARCH_BACKENDS = WAGTAILSEARCH_BACKENDS

if os.environ.get('DATABASE') is not None:
try:
DATABASE_ENVIRON = urlparse(os.environ['DATABASE'])
if DATABASE_ENVIRON.scheme == 'mysql':
DATABASES |= {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': DATABASE_ENVIRON.path.replace('/', '') or 'wagtail',
'USER': DATABASE_ENVIRON.username or 'root',
'PASSWORD': DATABASE_ENVIRON.password or '',
'HOST': DATABASE_ENVIRON.hostname or 'localhost',
'PORT': int(DATABASE_ENVIRON.port) or 3306,
},
}
else:
print('DATABASE environment unknown scheme', DATABASE_ENVIRON.scheme)
except ValueError:
print('DATABASE environment variable invalid')
else:
print('Did not tried using DATABASE despite tried to load PRODUCTION config')

if all(
not k.startswith('DB_') or ENV_VARS[i] is not None for i, k in enumerate(ENV_KEYS)
):
print('Using MYSQL instead')
DATABASES = {

if os.environ['OPENSEARCH_HOST'] is not None:
WAGTAILSEARCH_BACKENDS = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': ENV_VARS[0],
'USER': ENV_VARS[4],
'PASSWORD': ENV_VARS[3],
'HOST': ENV_VARS[1],
'PORT': ENV_VARS[2],
},
'BACKEND': 'wagtail.search.backends.elasticsearch7',
'URLS': [os.environ['OPENSEARCH_HOST']],
'INDEX': 'fuhoblog',
'TIMEOUT': 5,
'OPTIONS': {},
'INDEX_SETTINGS': {},
}
}
else:
print('Did not tried using OPENSEARCH despite tried to load PRODUCTION config')

ALLOWED_HOSTS = ['*']

try:
from .local import *
Expand Down
3 changes: 0 additions & 3 deletions fuhoblog/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@
from .api import api_router


from search import views as search_views

urlpatterns = [
path('django-admin/', admin.site.urls),
path('admin/', include(wagtailadmin_urls)),
path('documents/', include(wagtaildocs_urls)),
path('search/', search_views.search, name='search'),
path('api/v2/', api_router.urls),
re_path(r'^', include(wagtail_urls)),
]
Expand Down
3 changes: 0 additions & 3 deletions gallery/admin.py

This file was deleted.

1 change: 1 addition & 0 deletions gallery/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Picture(Page):

search_fields = Page.search_fields + [
index.SearchField('cap'),
index.SearchField('seo_title'),
]

content_panels = Page.content_panels + [
Expand Down
3 changes: 0 additions & 3 deletions gallery/views.py

This file was deleted.

8 changes: 7 additions & 1 deletion manage.py
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,13 @@
import sys

if __name__ == '__main__':
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'fuhoblog.settings.dev')
os.environ.setdefault('DJANGO_FORCEPROD', 'False')
os.environ.setdefault(
'DJANGO_SETTINGS_MODULE',
'fuhoblog.settings.dev'
if os.environ['DJANGO_FORCEPROD'] == 'False'
else 'fuhoblog.settings.production',
)

from django.core.management import execute_from_command_line

Expand Down
6 changes: 4 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
Django>=4.2,<4.3
wagtail>=6,<7
# wagtail>=5.0,<5.1
gunicorn==22
elasticsearch==7.13.4
wagtail-localize==1.9
wagtail_modeladmin==2.0
wagtail_modeladmin==2.0
python-dotenv
mysqlclient
2 changes: 2 additions & 0 deletions run.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/sh
source scripts/prod.env
rm -rv static
python manage.py collectstatic
python manage.py migrate --noinput
Expand Down
2 changes: 2 additions & 0 deletions scripts/ctable.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DROP DATABASE wagtail;
CREATE DATABASE wagtail CHARACTER SET utf8mb4;
0 install.sh → scripts/install.sh
100644 → 100755
File renamed without changes.
2 changes: 2 additions & 0 deletions scripts/prod.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export DJANGO_SETTINGS_MODULE=fuhoblog.settings.production
export DJANGO_FORCEPROD="True"
Empty file removed search/__init__.py
Empty file.
38 changes: 0 additions & 38 deletions search/templates/search/search.html

This file was deleted.

40 changes: 0 additions & 40 deletions search/views.py

This file was deleted.

0 comments on commit 4e04411

Please sign in to comment.