Remove telemetry, Docker, Github-specifics, development-only tools
This commit is contained in:
parent
ba1f180c83
commit
bb6e8e516c
36 changed files with 1 additions and 1658 deletions
|
@ -1,8 +0,0 @@
|
|||
__pycache__
|
||||
*.pyc
|
||||
*.pyo
|
||||
*.pyd
|
||||
.git
|
||||
.github
|
||||
.pytest*
|
||||
.env
|
|
@ -1 +0,0 @@
|
|||
**/vendor/**
|
90
.eslintrc.js
90
.eslintrc.js
|
@ -1,90 +0,0 @@
|
|||
/* global module */
|
||||
|
||||
module.exports = {
|
||||
"env": {
|
||||
"browser": true,
|
||||
"es6": true
|
||||
},
|
||||
|
||||
"extends": "eslint:recommended",
|
||||
|
||||
"rules": {
|
||||
// Possible Errors
|
||||
"no-async-promise-executor": "error",
|
||||
"no-await-in-loop": "error",
|
||||
"no-class-assign": "error",
|
||||
"no-confusing-arrow": "error",
|
||||
"no-const-assign": "error",
|
||||
"no-dupe-class-members": "error",
|
||||
"no-duplicate-imports": "error",
|
||||
"no-template-curly-in-string": "error",
|
||||
"no-useless-computed-key": "error",
|
||||
"no-useless-constructor": "error",
|
||||
"no-useless-rename": "error",
|
||||
"require-atomic-updates": "error",
|
||||
|
||||
// Best practices
|
||||
"strict": "error",
|
||||
"no-var": "error",
|
||||
|
||||
// Stylistic Issues
|
||||
"arrow-spacing": "error",
|
||||
"capitalized-comments": [
|
||||
"warn",
|
||||
"always",
|
||||
{
|
||||
"ignoreConsecutiveComments": true
|
||||
},
|
||||
],
|
||||
"keyword-spacing": "error",
|
||||
"lines-around-comment": [
|
||||
"error",
|
||||
{
|
||||
"beforeBlockComment": true,
|
||||
"beforeLineComment": true,
|
||||
"allowBlockStart": true,
|
||||
"allowClassStart": true,
|
||||
"allowObjectStart": true,
|
||||
"allowArrayStart": true,
|
||||
},
|
||||
],
|
||||
"no-multiple-empty-lines": [
|
||||
"error",
|
||||
{
|
||||
"max": 1,
|
||||
},
|
||||
],
|
||||
"padded-blocks": [
|
||||
"error",
|
||||
"never",
|
||||
],
|
||||
"padding-line-between-statements": [
|
||||
"error",
|
||||
{
|
||||
// always before return
|
||||
"blankLine": "always",
|
||||
"prev": "*",
|
||||
"next": "return",
|
||||
},
|
||||
{
|
||||
// always before block-like expressions
|
||||
"blankLine": "always",
|
||||
"prev": "*",
|
||||
"next": "block-like",
|
||||
},
|
||||
{
|
||||
// always after variable declaration
|
||||
"blankLine": "always",
|
||||
"prev": [ "const", "let", "var" ],
|
||||
"next": "*",
|
||||
},
|
||||
{
|
||||
// not necessary between variable declaration
|
||||
"blankLine": "any",
|
||||
"prev": [ "const", "let", "var" ],
|
||||
"next": [ "const", "let", "var" ],
|
||||
},
|
||||
],
|
||||
"space-before-blocks": "error",
|
||||
}
|
||||
};
|
12
.github/FUNDING.yml
vendored
12
.github/FUNDING.yml
vendored
|
@ -1,12 +0,0 @@
|
|||
# These are supported funding model platforms
|
||||
|
||||
github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
|
||||
patreon: bookwyrm
|
||||
open_collective: bookwyrm
|
||||
ko_fi: # Replace with a single Ko-fi username
|
||||
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
|
||||
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
|
||||
liberapay: # Replace with a single Liberapay username
|
||||
issuehunt: # Replace with a single IssueHunt username
|
||||
otechie: # Replace with a single Otechie username
|
||||
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
|
43
.github/ISSUE_TEMPLATE/bug_report.md
vendored
43
.github/ISSUE_TEMPLATE/bug_report.md
vendored
|
@ -1,43 +0,0 @@
|
|||
---
|
||||
name: Bug report
|
||||
about: Create a report to help us improve
|
||||
title: ''
|
||||
labels: 'bug'
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Describe the bug**
|
||||
A clear and concise description of what the bug is.
|
||||
|
||||
**To Reproduce**
|
||||
Steps to reproduce the behavior:
|
||||
1. Go to '...'
|
||||
2. Click on '....'
|
||||
3. Scroll down to '....'
|
||||
4. See error
|
||||
|
||||
**Expected behavior**
|
||||
A clear and concise description of what you expected to happen.
|
||||
|
||||
**Screenshots**
|
||||
If applicable, add screenshots to help explain your problem.
|
||||
|
||||
**Instance**
|
||||
On which BookWyrm instance did you encounter this problem.
|
||||
|
||||
**Additional context**
|
||||
Add any other context about the problem here.
|
||||
|
||||
---
|
||||
|
||||
**Desktop (please complete the following information):**
|
||||
- OS: [e.g. iOS]
|
||||
- Browser [e.g. chrome, safari]
|
||||
- Version [e.g. 22]
|
||||
|
||||
**Smartphone (please complete the following information):**
|
||||
- Device: [e.g. iPhone6]
|
||||
- OS: [e.g. iOS8.1]
|
||||
- Browser [e.g. stock browser, safari]
|
||||
- Version [e.g. 22]
|
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
20
.github/ISSUE_TEMPLATE/feature_request.md
vendored
|
@ -1,20 +0,0 @@
|
|||
---
|
||||
name: Feature request
|
||||
about: Suggest an idea for this project
|
||||
title: ''
|
||||
labels: ''
|
||||
assignees: ''
|
||||
|
||||
---
|
||||
|
||||
**Is your feature request related to a problem? Please describe.**
|
||||
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
|
||||
|
||||
**Describe the solution you'd like**
|
||||
A clear and concise description of what you want to happen.
|
||||
|
||||
**Describe alternatives you've considered**
|
||||
A clear and concise description of any alternative solutions or features you've considered.
|
||||
|
||||
**Additional context**
|
||||
Add any other context or screenshots about the feature request here.
|
68
.github/pull_request_template.md
vendored
68
.github/pull_request_template.md
vendored
|
@ -1,68 +0,0 @@
|
|||
<!--
|
||||
Thanks for contributing! This template has some checkboxes that help keep track of what changes go into a release.
|
||||
|
||||
To check (tick) a list item, replace the space between square brackets with an x, like this:
|
||||
|
||||
- [x] I have checked the box
|
||||
|
||||
You can find more information and tips for BookWyrm contributors at https://docs.joinbookwyrm.com/contributing.html
|
||||
-->
|
||||
## Description
|
||||
<!--
|
||||
Describe what your pull request does here
|
||||
-->
|
||||
|
||||
|
||||
<!--
|
||||
For pull requests that relate or close an issue, please include them
|
||||
below. We like to follow [Github's guidance on linking issues to pull requests](https://docs.github.com/en/issues/tracking-your-work-with-issues/linking-a-pull-request-to-an-issue).
|
||||
|
||||
For example having the text: "closes #1234" would connect the current pull
|
||||
request to issue 1234. And when we merge the pull request, Github will
|
||||
automatically close the issue.
|
||||
-->
|
||||
|
||||
- Related Issue #
|
||||
- Closes #
|
||||
|
||||
## What type of Pull Request is this?
|
||||
<!-- Check all that apply -->
|
||||
|
||||
- [ ] Bug Fix
|
||||
- [ ] Enhancement
|
||||
- [ ] Plumbing / Internals / Dependencies
|
||||
- [ ] Refactor
|
||||
|
||||
## Does this PR change settings or dependencies, or break something?
|
||||
<!-- Check all that apply -->
|
||||
|
||||
- [ ] This PR changes or adds default settings, configuration, or .env values
|
||||
- [ ] This PR changes or adds dependencies
|
||||
- [ ] This PR introduces other breaking changes
|
||||
|
||||
### Details of breaking or configuration changes (if any of above checked)
|
||||
|
||||
|
||||
## Documentation
|
||||
<!--
|
||||
Documentation for users, admins, and developers is an important way to keep the BookWyrm community welcoming and make Bookwyrm easy to use.
|
||||
Our documentation is maintained in a separate repository at https://github.com/bookwyrm-social/documentation
|
||||
-->
|
||||
|
||||
<!-- Check all that apply -->
|
||||
|
||||
- [ ] New or amended documentation will be required if this PR is merged
|
||||
- [ ] I have created a matching pull request in the Documentation repository
|
||||
- [ ] I intend to create a matching pull request in the Documentation repository after this PR is merged
|
||||
|
||||
<!-- Amazing! Thanks for filling that out. Your PR will need to have passing tests and happy linters before we can merge
|
||||
You will need to check your code with `black`, `pylint`, and `mypy`, or `./bw-dev formatters`
|
||||
-->
|
||||
|
||||
### Tests
|
||||
<!-- Check one -->
|
||||
|
||||
- [ ] My changes do not need new tests
|
||||
- [ ] All tests I have added are passing
|
||||
- [ ] I have written tests but need help to make them pass
|
||||
- [ ] I have not written tests and need help to write them
|
26
.github/release.yml
vendored
26
.github/release.yml
vendored
|
@ -1,26 +0,0 @@
|
|||
changelog:
|
||||
exclude:
|
||||
labels:
|
||||
- ignore-for-release
|
||||
categories:
|
||||
- title: ‼️ Breaking Changes & New Settings ⚙️
|
||||
labels:
|
||||
- breaking-change
|
||||
- config-change
|
||||
- title: Updated Dependencies 🧸
|
||||
labels:
|
||||
- dependencies
|
||||
- title: New Features 🎉
|
||||
labels:
|
||||
- enhancement
|
||||
- title: Bug Fixes 🐛
|
||||
labels:
|
||||
- fix
|
||||
- bug
|
||||
- title: Internals/Plumbing 👩🔧
|
||||
- plumbing
|
||||
- tests
|
||||
- deployment
|
||||
- title: Other Changes
|
||||
labels:
|
||||
- "*"
|
68
.github/workflows/codeql-analysis.yml
vendored
68
.github/workflows/codeql-analysis.yml
vendored
|
@ -1,68 +0,0 @@
|
|||
# For most projects, this workflow file will not need changing; you simply need
|
||||
# to commit it to your repository.
|
||||
#
|
||||
# You may wish to alter this file to override the set of languages analyzed,
|
||||
# or to provide custom queries or build logic.
|
||||
#
|
||||
# ******** NOTE ********
|
||||
# We have attempted to detect the languages in your repository. Please check
|
||||
# the `language` matrix defined below to confirm you have the correct set of
|
||||
# supported CodeQL languages.
|
||||
# ******** NOTE ********
|
||||
|
||||
name: "CodeQL"
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
pull_request:
|
||||
# The branches below must be a subset of the branches above
|
||||
branches: [ main ]
|
||||
schedule:
|
||||
- cron: '18 6 * * 3'
|
||||
|
||||
jobs:
|
||||
analyze:
|
||||
name: Analyze
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
language: [ 'javascript', 'python' ]
|
||||
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
|
||||
# Learn more...
|
||||
# https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v3
|
||||
with:
|
||||
languages: ${{ matrix.language }}
|
||||
# If you wish to specify custom queries, you can do so here or in a config file.
|
||||
# By default, queries listed here will override any specified in a config file.
|
||||
# Prefix the list here with "+" to use these queries and those in the config file.
|
||||
# queries: ./path/to/local/query, your-org/your-repo/queries@main
|
||||
|
||||
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
|
||||
# If this step fails, then you should remove it and run the build manually (see below)
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v3
|
||||
|
||||
# ℹ️ Command-line programs to run using the OS shell.
|
||||
# 📚 https://git.io/JvXDl
|
||||
|
||||
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
|
||||
# and modify them (or add more) to build your code if your project
|
||||
# uses a compiled language
|
||||
|
||||
#- run: |
|
||||
# make bootstrap
|
||||
# make release
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v3
|
28
.github/workflows/curlylint.yaml
vendored
28
.github/workflows/curlylint.yaml
vendored
|
@ -1,28 +0,0 @@
|
|||
name: Templates validator
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install curlylint
|
||||
run: pip install curlylint
|
||||
|
||||
- name: Run linter
|
||||
run: >
|
||||
curlylint --rule 'aria_role: true' \
|
||||
--rule 'django_forms_rendering: true' \
|
||||
--rule 'html_has_lang: true' \
|
||||
--rule 'image_alt: true' \
|
||||
--rule 'meta_viewport: true' \
|
||||
--rule 'no_autofocus: true' \
|
||||
--rule 'tabindex_no_positive: true' \
|
||||
--exclude '_modal.html|create_status/layout.html|reading_modals/layout.html' \
|
||||
bookwyrm/templates
|
38
.github/workflows/lint-frontend.yaml
vendored
38
.github/workflows/lint-frontend.yaml
vendored
|
@ -1,38 +0,0 @@
|
|||
# @url https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions
|
||||
name: Lint Frontend (run `./bw-dev stylelint` to fix css errors)
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main, ci, frontend ]
|
||||
paths:
|
||||
- '.github/workflows/**'
|
||||
- 'static/**'
|
||||
- '.eslintrc'
|
||||
- '.stylelintrc.js'
|
||||
pull_request:
|
||||
branches: [ main, ci, frontend ]
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
name: Lint with stylelint and ESLint.
|
||||
runs-on: ubuntu-24.04
|
||||
|
||||
steps:
|
||||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it.
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install modules
|
||||
# run: npm install stylelint stylelint-config-recommended stylelint-config-standard stylelint-order eslint
|
||||
run: npm install eslint@^8.9.0
|
||||
|
||||
# See .stylelintignore for files that are not linted.
|
||||
# - name: Run stylelint
|
||||
# run: >
|
||||
# npx stylelint bookwyrm/static/css/*.scss bookwyrm/static/css/bookwyrm/**/*.scss \
|
||||
# --config dev-tools/.stylelintrc.js
|
||||
|
||||
# See .eslintignore for files that are not linted.
|
||||
- name: Run ESLint
|
||||
run: >
|
||||
npx eslint bookwyrm/static \
|
||||
--ext .js,.jsx,.ts,.tsx
|
23
.github/workflows/prettier.yaml
vendored
23
.github/workflows/prettier.yaml
vendored
|
@ -1,23 +0,0 @@
|
|||
# @url https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions
|
||||
name: JavaScript Prettier (run ./bw-dev prettier to fix)
|
||||
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
|
||||
jobs:
|
||||
lint:
|
||||
name: Lint with Prettier
|
||||
runs-on: ubuntu-24.04
|
||||
|
||||
steps:
|
||||
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it.
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Install modules
|
||||
run: npm install prettier@2.5.1
|
||||
|
||||
- name: Run Prettier
|
||||
run: npx prettier --check bookwyrm/static/js/*.js
|
99
.github/workflows/python.yml
vendored
99
.github/workflows/python.yml
vendored
|
@ -1,99 +0,0 @@
|
|||
name: Python
|
||||
on:
|
||||
push:
|
||||
branches: [ main ]
|
||||
pull_request:
|
||||
branches: [ main ]
|
||||
|
||||
# overrides for .env.example
|
||||
env:
|
||||
POSTGRES_HOST: 127.0.0.1
|
||||
PGPORT: 5432
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: hunter2
|
||||
POSTGRES_DB: github_actions
|
||||
SECRET_KEY: beepbeep
|
||||
EMAIL_HOST_USER: ""
|
||||
EMAIL_HOST_PASSWORD: ""
|
||||
|
||||
jobs:
|
||||
pytest:
|
||||
name: Tests (pytest)
|
||||
runs-on: ubuntu-latest
|
||||
services:
|
||||
postgres:
|
||||
image: postgres:13
|
||||
env: # does not inherit from jobs.build.env
|
||||
POSTGRES_USER: postgres
|
||||
POSTGRES_PASSWORD: hunter2
|
||||
options: >-
|
||||
--health-cmd pg_isready
|
||||
--health-interval 10s
|
||||
--health-timeout 5s
|
||||
--health-retries 5
|
||||
ports:
|
||||
- 5432:5432
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up Python 3.11
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: 3.11
|
||||
cache: pip
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r requirements.txt
|
||||
pip install pytest-github-actions-annotate-failures
|
||||
- name: Set up .env
|
||||
run: cp .env.example .env
|
||||
- name: Check migrations up-to-date
|
||||
run: python ./manage.py makemigrations --check -v 3
|
||||
- name: Run Tests
|
||||
run: pytest -n 3
|
||||
|
||||
pylint:
|
||||
name: Linting (pylint)
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up Python 3.11
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: 3.11
|
||||
cache: pip
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r requirements.txt
|
||||
- name: Analyse code with pylint
|
||||
run: pylint bookwyrm/
|
||||
|
||||
mypy:
|
||||
name: Typing (mypy)
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Set up Python 3.11
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
python-version: 3.11
|
||||
cache: pip
|
||||
- name: Install Dependencies
|
||||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install -r requirements.txt
|
||||
- name: Set up .env
|
||||
run: cp .env.example .env
|
||||
- name: Analyse code with mypy
|
||||
run: mypy bookwyrm celerywyrm
|
||||
|
||||
black:
|
||||
name: Formatting (black; run ./bw-dev black to fix)
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: actions/setup-python@v5
|
||||
- uses: psf/black@stable
|
||||
with:
|
||||
version: "22.*"
|
|
@ -1 +0,0 @@
|
|||
**/vendor/*
|
|
@ -1 +0,0 @@
|
|||
'trailingComma': 'es5'
|
12
Dockerfile
12
Dockerfile
|
@ -1,12 +0,0 @@
|
|||
FROM python:3.11
|
||||
|
||||
ENV PYTHONUNBUFFERED 1
|
||||
|
||||
RUN mkdir /app /app/static /app/images
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
RUN apt-get update && apt-get install -y gettext libgettextpo-dev tidy && apt-get clean
|
||||
|
||||
COPY requirements.txt /app/
|
||||
RUN pip install -r requirements.txt --no-cache-dir
|
|
@ -4,15 +4,12 @@ from django.dispatch import receiver
|
|||
from django.db import transaction
|
||||
from django.db.models import signals, Q
|
||||
from django.utils import timezone
|
||||
from opentelemetry import trace
|
||||
|
||||
from bookwyrm import models
|
||||
from bookwyrm.redis_store import RedisStore, r
|
||||
from bookwyrm.tasks import app, STREAMS, IMPORT_TRIGGERED
|
||||
from bookwyrm.telemetry import open_telemetry
|
||||
|
||||
|
||||
tracer = open_telemetry.tracer()
|
||||
|
||||
|
||||
class ActivityStream(RedisStore):
|
||||
|
@ -105,15 +102,8 @@ class ActivityStream(RedisStore):
|
|||
"""go from zero to a timeline"""
|
||||
self.populate_store(self.stream_id(user.id))
|
||||
|
||||
@tracer.start_as_current_span("ActivityStream._get_audience")
|
||||
def _get_audience(self, status): # pylint: disable=no-self-use
|
||||
"""given a status, what users should see it, excluding the author"""
|
||||
trace.get_current_span().set_attribute("status_type", status.status_type)
|
||||
trace.get_current_span().set_attribute("status_privacy", status.privacy)
|
||||
trace.get_current_span().set_attribute(
|
||||
"status_reply_parent_privacy",
|
||||
status.reply_parent.privacy if status.reply_parent else status.privacy,
|
||||
)
|
||||
# direct messages don't appear in feeds, direct comments/reviews/etc do
|
||||
if status.privacy == "direct" and status.status_type == "Note":
|
||||
return models.User.objects.none()
|
||||
|
@ -148,10 +138,8 @@ class ActivityStream(RedisStore):
|
|||
)
|
||||
return audience.distinct("id")
|
||||
|
||||
@tracer.start_as_current_span("ActivityStream.get_audience")
|
||||
def get_audience(self, status):
|
||||
"""given a status, what users should see it"""
|
||||
trace.get_current_span().set_attribute("stream_id", self.key)
|
||||
audience = self._get_audience(status).values_list("id", flat=True)
|
||||
status_author = models.User.objects.filter(
|
||||
is_active=True, local=True, id=status.user.id
|
||||
|
@ -179,9 +167,7 @@ class HomeStream(ActivityStream):
|
|||
|
||||
key = "home"
|
||||
|
||||
@tracer.start_as_current_span("HomeStream.get_audience")
|
||||
def get_audience(self, status):
|
||||
trace.get_current_span().set_attribute("stream_id", self.key)
|
||||
audience = super()._get_audience(status)
|
||||
# if the user is following the author
|
||||
audience = audience.filter(following=status.user).values_list("id", flat=True)
|
||||
|
|
|
@ -4,17 +4,14 @@ import logging
|
|||
from django.dispatch import receiver
|
||||
from django.db import transaction
|
||||
from django.db.models import signals, Count, Q, Case, When, IntegerField
|
||||
from opentelemetry import trace
|
||||
|
||||
from bookwyrm import models
|
||||
from bookwyrm.redis_store import RedisStore, r
|
||||
from bookwyrm.settings import INSTANCE_ACTOR_USERNAME
|
||||
from bookwyrm.tasks import app, SUGGESTED_USERS
|
||||
from bookwyrm.telemetry import open_telemetry
|
||||
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
tracer = open_telemetry.tracer()
|
||||
|
||||
|
||||
class SuggestedUsers(RedisStore):
|
||||
|
@ -61,13 +58,10 @@ class SuggestedUsers(RedisStore):
|
|||
Q(id=obj.id) | Q(followers=obj) | Q(id__in=obj.blocks.all()) | Q(blocks=obj)
|
||||
)
|
||||
|
||||
@tracer.start_as_current_span("SuggestedUsers.rerank_obj")
|
||||
def rerank_obj(self, obj, update_only=True):
|
||||
"""update all the instances of this user with new ranks"""
|
||||
trace.get_current_span().set_attribute("update_only", update_only)
|
||||
pipeline = r.pipeline()
|
||||
for store_user in self.get_users_for_object(obj):
|
||||
with tracer.start_as_current_span("SuggestedUsers.rerank_obj/user") as _:
|
||||
annotated_user = get_annotated_users(
|
||||
store_user,
|
||||
id=obj.id,
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
from opentelemetry import trace
|
||||
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import OTLPSpanExporter
|
||||
from opentelemetry.sdk.trace import TracerProvider, Tracer
|
||||
from opentelemetry.sdk.trace.export import BatchSpanProcessor, ConsoleSpanExporter
|
||||
|
||||
from bookwyrm import settings
|
||||
|
||||
trace.set_tracer_provider(TracerProvider())
|
||||
if settings.OTEL_EXPORTER_CONSOLE:
|
||||
trace.get_tracer_provider().add_span_processor(
|
||||
BatchSpanProcessor(ConsoleSpanExporter())
|
||||
)
|
||||
elif settings.OTEL_EXPORTER_OTLP_ENDPOINT:
|
||||
trace.get_tracer_provider().add_span_processor(
|
||||
BatchSpanProcessor(OTLPSpanExporter())
|
||||
)
|
||||
|
||||
|
||||
def instrumentDjango() -> None:
|
||||
from opentelemetry.instrumentation.django import DjangoInstrumentor
|
||||
|
||||
DjangoInstrumentor().instrument()
|
||||
|
||||
|
||||
def instrumentPostgres() -> None:
|
||||
from opentelemetry.instrumentation.psycopg2 import Psycopg2Instrumentor
|
||||
|
||||
Psycopg2Instrumentor().instrument()
|
||||
|
||||
|
||||
def instrumentCelery() -> None:
|
||||
from opentelemetry.instrumentation.celery import CeleryInstrumentor
|
||||
from celery.signals import worker_process_init
|
||||
|
||||
@worker_process_init.connect(weak=False)
|
||||
def init_celery_tracing(*args, **kwargs):
|
||||
CeleryInstrumentor().instrument()
|
||||
|
||||
|
||||
def tracer() -> Tracer:
|
||||
return trace.get_tracer(__name__)
|
342
bw-dev
342
bw-dev
|
@ -1,342 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# exit on errors
|
||||
set -e
|
||||
|
||||
# check if we're in DEBUG mode
|
||||
DEBUG=$(sed <.env -ne 's/^DEBUG=//p')
|
||||
|
||||
# disallow certain commands when debug is false
|
||||
function prod_error {
|
||||
if [ "$DEBUG" != "true" ]; then
|
||||
echo "This command is not safe to run in production environments"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# import our ENV variables
|
||||
# catch exits and give a friendly error message
|
||||
function showerr {
|
||||
echo "Failed to load configuration! You may need to update your .env and quote values with special characters in them."
|
||||
}
|
||||
trap showerr EXIT
|
||||
source .env
|
||||
trap - EXIT
|
||||
|
||||
if docker compose &> /dev/null ; then
|
||||
DOCKER_COMPOSE="docker compose"
|
||||
else
|
||||
DOCKER_COMPOSE="docker-compose"
|
||||
fi
|
||||
|
||||
function clean {
|
||||
$DOCKER_COMPOSE stop
|
||||
$DOCKER_COMPOSE rm -f
|
||||
}
|
||||
|
||||
function runweb {
|
||||
$DOCKER_COMPOSE run --rm web "$@"
|
||||
}
|
||||
|
||||
function execdb {
|
||||
$DOCKER_COMPOSE exec db $@
|
||||
}
|
||||
|
||||
function execweb {
|
||||
$DOCKER_COMPOSE exec web "$@"
|
||||
}
|
||||
|
||||
function initdb {
|
||||
runweb python manage.py initdb "$@"
|
||||
}
|
||||
|
||||
function migrate {
|
||||
runweb python manage.py migrate "$@"
|
||||
}
|
||||
|
||||
function admin_code {
|
||||
runweb python manage.py admin_code
|
||||
}
|
||||
|
||||
function awscommand {
|
||||
# expose env vars
|
||||
export AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID}
|
||||
export AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY}
|
||||
export AWS_DEFAULT_REGION=${AWS_S3_REGION_NAME}
|
||||
# first arg is mountpoint, second is the whole aws command
|
||||
docker run --rm -it -v $1\
|
||||
-e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_DEFAULT_REGION\
|
||||
amazon/aws-cli $2
|
||||
}
|
||||
|
||||
|
||||
|
||||
CMD=$1
|
||||
if [ -n "$CMD" ]; then
|
||||
shift
|
||||
fi
|
||||
|
||||
# show commands as they're executed
|
||||
set -x
|
||||
|
||||
case "$CMD" in
|
||||
up)
|
||||
$DOCKER_COMPOSE up --build "$@"
|
||||
;;
|
||||
down)
|
||||
$DOCKER_COMPOSE down
|
||||
;;
|
||||
service_ports_web)
|
||||
prod_error
|
||||
$DOCKER_COMPOSE run --rm --service-ports web
|
||||
;;
|
||||
initdb)
|
||||
initdb "$@"
|
||||
;;
|
||||
resetdb)
|
||||
prod_error
|
||||
$DOCKER_COMPOSE rm -svf
|
||||
docker volume rm -f bookwyrm_media_volume bookwyrm_pgdata bookwyrm_redis_activity_data bookwyrm_redis_broker_data bookwyrm_static_volume
|
||||
$DOCKER_COMPOSE build
|
||||
migrate
|
||||
migrate django_celery_beat
|
||||
initdb
|
||||
runweb python manage.py compile_themes
|
||||
runweb python manage.py collectstatic --no-input
|
||||
admin_code
|
||||
;;
|
||||
makemigrations)
|
||||
prod_error
|
||||
runweb python manage.py makemigrations "$@"
|
||||
;;
|
||||
migrate)
|
||||
migrate "$@"
|
||||
;;
|
||||
bash)
|
||||
runweb bash
|
||||
;;
|
||||
shell)
|
||||
runweb python manage.py shell
|
||||
;;
|
||||
dbshell)
|
||||
execdb psql -U ${POSTGRES_USER} ${POSTGRES_DB}
|
||||
;;
|
||||
restart_celery)
|
||||
$DOCKER_COMPOSE restart celery_worker
|
||||
;;
|
||||
pytest)
|
||||
prod_error
|
||||
runweb pytest --no-cov-on-fail "$@"
|
||||
;;
|
||||
pytest_coverage_report)
|
||||
prod_error
|
||||
runweb pytest -n 3 --cov-report term-missing "$@"
|
||||
;;
|
||||
compile_themes)
|
||||
runweb python manage.py compile_themes
|
||||
;;
|
||||
collectstatic)
|
||||
runweb python manage.py collectstatic --no-input
|
||||
;;
|
||||
makemessages)
|
||||
prod_error
|
||||
runweb django-admin makemessages --no-wrap --ignore=venv -l en_US $@
|
||||
;;
|
||||
compilemessages)
|
||||
runweb django-admin compilemessages --ignore venv $@
|
||||
;;
|
||||
update_locales)
|
||||
prod_error
|
||||
git fetch origin l10n_main:l10n_main
|
||||
git checkout l10n_main locale/ca_ES
|
||||
git checkout l10n_main locale/de_DE
|
||||
git checkout l10n_main locale/eo_UY
|
||||
git checkout l10n_main locale/es_ES
|
||||
git checkout l10n_main locale/eu_ES
|
||||
git checkout l10n_main locale/fi_FI
|
||||
git checkout l10n_main locale/fr_FR
|
||||
git checkout l10n_main locale/gl_ES
|
||||
git checkout l10n_main locale/ko_KR
|
||||
git checkout l10n_main locale/it_IT
|
||||
git checkout l10n_main locale/lt_LT
|
||||
git checkout l10n_main locale/nl_NL
|
||||
git checkout l10n_main locale/no_NO
|
||||
git checkout l10n_main locale/pl_PL
|
||||
git checkout l10n_main locale/pt_PT
|
||||
git checkout l10n_main locale/pt_BR
|
||||
git checkout l10n_main locale/ro_RO
|
||||
git checkout l10n_main locale/sv_SE
|
||||
git checkout l10n_main locale/uk_UA
|
||||
git checkout l10n_main locale/zh_Hans
|
||||
git checkout l10n_main locale/zh_Hant
|
||||
runweb django-admin makemessages --no-wrap --ignore=venv -l en_US $@
|
||||
runweb django-admin compilemessages --ignore venv
|
||||
;;
|
||||
build)
|
||||
$DOCKER_COMPOSE build
|
||||
;;
|
||||
clean)
|
||||
prod_error
|
||||
clean
|
||||
;;
|
||||
black)
|
||||
prod_error
|
||||
$DOCKER_COMPOSE run --rm dev-tools black celerywyrm bookwyrm
|
||||
;;
|
||||
pylint)
|
||||
prod_error
|
||||
# pylint depends on having the app dependencies in place, so we run it in the web container
|
||||
runweb pylint bookwyrm/
|
||||
;;
|
||||
prettier)
|
||||
prod_error
|
||||
$DOCKER_COMPOSE run --rm dev-tools prettier --write bookwyrm/static/js/*.js
|
||||
;;
|
||||
eslint)
|
||||
prod_error
|
||||
$DOCKER_COMPOSE run --rm dev-tools eslint bookwyrm/static --ext .js
|
||||
;;
|
||||
stylelint)
|
||||
prod_error
|
||||
$DOCKER_COMPOSE run --rm dev-tools stylelint --fix bookwyrm/static/css \
|
||||
--config dev-tools/.stylelintrc.js --ignore-path dev-tools/.stylelintignore
|
||||
;;
|
||||
formatters)
|
||||
prod_error
|
||||
runweb pylint bookwyrm/
|
||||
$DOCKER_COMPOSE run --rm dev-tools black celerywyrm bookwyrm
|
||||
$DOCKER_COMPOSE run --rm dev-tools prettier --write bookwyrm/static/js/*.js
|
||||
$DOCKER_COMPOSE run --rm dev-tools eslint bookwyrm/static --ext .js
|
||||
$DOCKER_COMPOSE run --rm dev-tools stylelint --fix bookwyrm/static/css \
|
||||
--config dev-tools/.stylelintrc.js --ignore-path dev-tools/.stylelintignore
|
||||
;;
|
||||
mypy)
|
||||
prod_error
|
||||
runweb mypy celerywyrm bookwyrm
|
||||
;;
|
||||
collectstatic_watch)
|
||||
prod_error
|
||||
npm run --prefix dev-tools watch:static
|
||||
;;
|
||||
update)
|
||||
git pull
|
||||
$DOCKER_COMPOSE build
|
||||
# ./update.sh
|
||||
runweb python manage.py migrate
|
||||
runweb python manage.py compile_themes
|
||||
runweb python manage.py collectstatic --no-input
|
||||
$DOCKER_COMPOSE up -d
|
||||
$DOCKER_COMPOSE restart web
|
||||
$DOCKER_COMPOSE restart celery_worker
|
||||
;;
|
||||
populate_streams)
|
||||
runweb python manage.py populate_streams "$@"
|
||||
;;
|
||||
populate_lists_streams)
|
||||
runweb python manage.py populate_lists_streams $@
|
||||
;;
|
||||
populate_suggestions)
|
||||
runweb python manage.py populate_suggestions
|
||||
;;
|
||||
generate_thumbnails)
|
||||
runweb python manage.py generateimages
|
||||
;;
|
||||
generate_preview_images)
|
||||
runweb python manage.py generate_preview_images "$@"
|
||||
;;
|
||||
remove_remote_user_preview_images)
|
||||
runweb python manage.py remove_remote_user_preview_images
|
||||
;;
|
||||
erase_deleted_user_data)
|
||||
runweb python manage.py erase_deleted_user_data "$@"
|
||||
;;
|
||||
copy_media_to_s3)
|
||||
awscommand "bookwyrm_media_volume:/images"\
|
||||
"s3 cp /images s3://${AWS_STORAGE_BUCKET_NAME}/images\
|
||||
--endpoint-url ${AWS_S3_ENDPOINT_URL}\
|
||||
--recursive --acl public-read" "$@"
|
||||
;;
|
||||
sync_media_to_s3)
|
||||
awscommand "bookwyrm_media_volume:/images"\
|
||||
"s3 sync /images s3://${AWS_STORAGE_BUCKET_NAME}/images\
|
||||
--endpoint-url ${AWS_S3_ENDPOINT_URL}\
|
||||
--acl public-read" "$@"
|
||||
;;
|
||||
set_cors_to_s3)
|
||||
set +x
|
||||
config_file=$1
|
||||
if [ -z "$config_file" ]; then
|
||||
echo "This command requires a JSON file containing a CORS configuration as an argument"
|
||||
exit 1
|
||||
fi
|
||||
set -x
|
||||
awscommand "$(pwd):/bw"\
|
||||
"s3api put-bucket-cors\
|
||||
--bucket ${AWS_STORAGE_BUCKET_NAME}\
|
||||
--endpoint-url ${AWS_S3_ENDPOINT_URL}\
|
||||
--cors-configuration file:///bw/$config_file" "$@"
|
||||
;;
|
||||
admin_code)
|
||||
admin_code
|
||||
;;
|
||||
setup)
|
||||
migrate
|
||||
migrate django_celery_beat
|
||||
initdb
|
||||
runweb python manage.py compile_themes
|
||||
runweb python manage.py collectstatic --no-input
|
||||
admin_code
|
||||
;;
|
||||
runweb)
|
||||
runweb "$@"
|
||||
;;
|
||||
remove_2fa)
|
||||
runweb python manage.py remove_2fa "$@"
|
||||
;;
|
||||
confirm_email)
|
||||
runweb python manage.py confirm_email "$@"
|
||||
;;
|
||||
*)
|
||||
set +x # No need to echo echo
|
||||
echo "Unrecognised command. Try:"
|
||||
echo " setup"
|
||||
echo " up [container]"
|
||||
echo " down"
|
||||
echo " service_ports_web"
|
||||
echo " initdb"
|
||||
echo " resetdb"
|
||||
echo " makemigrations [migration]"
|
||||
echo " migrate [migration]"
|
||||
echo " bash"
|
||||
echo " shell"
|
||||
echo " dbshell"
|
||||
echo " restart_celery"
|
||||
echo " pytest [path]"
|
||||
echo " compile_themes"
|
||||
echo " collectstatic"
|
||||
echo " makemessages"
|
||||
echo " compilemessages [locale]"
|
||||
echo " update_locales"
|
||||
echo " build"
|
||||
echo " clean"
|
||||
echo " black"
|
||||
echo " prettier"
|
||||
echo " eslint"
|
||||
echo " stylelint"
|
||||
echo " formatters"
|
||||
echo " mypy"
|
||||
echo " collectstatic_watch"
|
||||
echo " populate_streams [--stream=<stream name>]"
|
||||
echo " populate_lists_streams"
|
||||
echo " populate_suggestions"
|
||||
echo " generate_thumbnails"
|
||||
echo " generate_preview_images [--all]"
|
||||
echo " remove_remote_user_preview_images"
|
||||
echo " copy_media_to_s3"
|
||||
echo " sync_media_to_s3"
|
||||
echo " set_cors_to_s3 [cors file]"
|
||||
echo " runweb [command]"
|
||||
echo " remove_2fa"
|
||||
echo " confirm_email"
|
||||
;;
|
||||
esac
|
|
@ -7,8 +7,4 @@ class CelerywyrmConfig(AppConfig):
|
|||
verbose_name = "BookWyrm Celery"
|
||||
|
||||
def ready(self) -> None:
|
||||
if settings.OTEL_EXPORTER_OTLP_ENDPOINT or settings.OTEL_EXPORTER_CONSOLE:
|
||||
from bookwyrm.telemetry import open_telemetry
|
||||
|
||||
open_telemetry.instrumentCelery()
|
||||
open_telemetry.instrumentPostgres()
|
||||
pass
|
||||
|
|
|
@ -1,99 +0,0 @@
|
|||
# bw-dev auto-completions for fish-shell.
|
||||
# copy this to ~/.config/fish/completions/ with the name `bw-dev.fish`
|
||||
# this will only work if renamed to `bw-dev.fish`.
|
||||
|
||||
set -l commands up \
|
||||
service_ports_web \
|
||||
initdb \
|
||||
resetdb \
|
||||
makemigrations \
|
||||
migrate \
|
||||
bash \
|
||||
shell \
|
||||
dbshell \
|
||||
restart_celery \
|
||||
pytest \
|
||||
pytest_coverage_report \
|
||||
compile_themes \
|
||||
collectstatic \
|
||||
makemessages \
|
||||
compilemessages \
|
||||
update_locales \
|
||||
build \
|
||||
clean \
|
||||
black \
|
||||
prettier \
|
||||
eslint \
|
||||
stylelint \
|
||||
formatters \
|
||||
mypy \
|
||||
collectstatic_watch \
|
||||
populate_streams \
|
||||
populate_lists_streams \
|
||||
populate_suggestions \
|
||||
generate_thumbnails \
|
||||
generate_preview_images \
|
||||
remove_remote_user_preview_images \
|
||||
copy_media_to_s3 \
|
||||
set_cors_to_s3 \
|
||||
setup \
|
||||
admin_code \
|
||||
remove_2fa \
|
||||
confirm_email \
|
||||
runweb
|
||||
|
||||
function __bw_complete -a cmds cmd desc
|
||||
complete -f -c bw-dev -n "not __fish_seen_subcommand_from $cmds" -a $cmd -d $desc
|
||||
end
|
||||
|
||||
__bw_complete "$commands" "up" "bring one or all service(s) up"
|
||||
__bw_complete "$commands" "service_ports_web" "run command on the web container with its portsenabled and mapped"
|
||||
__bw_complete "$commands" "initdb" "initialize database"
|
||||
__bw_complete "$commands" "resetdb" "!! WARNING !! reset database"
|
||||
__bw_complete "$commands" "makemigrations" "create new migrations"
|
||||
__bw_complete "$commands" "migrate" "perform all migrations"
|
||||
__bw_complete "$commands" "bash" "open up bash within the web container"
|
||||
__bw_complete "$commands" "shell" "open the Python shell within the web container"
|
||||
__bw_complete "$commands" "dbshell" "open the database shell within the web container"
|
||||
__bw_complete "$commands" "restart_celery" "restart the celery container"
|
||||
__bw_complete "$commands" "pytest" "run unit tests"
|
||||
__bw_complete "$commands" "compile_themes" "compile themes css files"
|
||||
__bw_complete "$commands" "collectstatic" "copy changed static files into the installation"
|
||||
__bw_complete "$commands" "makemessages" "extract all localizable messages from the code"
|
||||
__bw_complete "$commands" "compilemessages" "compile .po localization files to .mo"
|
||||
__bw_complete "$commands" "update_locales" "run makemessages and compilemessages for the en_US and additional locales"
|
||||
__bw_complete "$commands" "build" "build the containers"
|
||||
__bw_complete "$commands" "clean" "bring the cluster down and remove all containers"
|
||||
__bw_complete "$commands" "black" "run Python code formatting tool"
|
||||
__bw_complete "$commands" "prettier" "run JavaScript code formatting tool"
|
||||
__bw_complete "$commands" "eslint" "run JavaScript linting tool"
|
||||
__bw_complete "$commands" "stylelint" "run SCSS linting tool"
|
||||
__bw_complete "$commands" "formatters" "run multiple formatter tools"
|
||||
__bw_complete "$commands" "populate_streams" "populate the main streams"
|
||||
__bw_complete "$commands" "populate_lists_streams" "populate streams for book lists"
|
||||
__bw_complete "$commands" "populate_suggestions" "populate book suggestions"
|
||||
__bw_complete "$commands" "generate_thumbnails" "generate book thumbnails"
|
||||
__bw_complete "$commands" "generate_preview_images" "generate site/book/user preview images"
|
||||
__bw_complete "$commands" "remove_remote_user_preview_images" "remove preview images for remote users"
|
||||
__bw_complete "$commands" "collectstatic_watch" "watch filesystem and copy changed static files"
|
||||
__bw_complete "$commands" "copy_media_to_s3" "run the `s3 cp` command to copy media to a bucket on S3"
|
||||
__bw_complete "$commands" "sync_media_to_s3" "run the `s3 sync` command to sync media with a bucket on S3"
|
||||
__bw_complete "$commands" "set_cors_to_s3" "push a CORS configuration defined in .json to s3"
|
||||
__bw_complete "$commands" "setup" "perform first-time setup"
|
||||
__bw_complete "$commands" "admin_code" "get the admin code"
|
||||
__bw_complete "$commands" "remove_2fa" "remove 2FA from user"
|
||||
__bw_complete "$commands" "confirm_email" "manually confirm email of user and set active"
|
||||
__bw_complete "$commands" "runweb" "run a command on the web container"
|
||||
|
||||
|
||||
function __bw_complete_subcommand -a cmd
|
||||
complete -f -c bw-dev -n "__fish_seen_subcommand_from $cmd" $argv[2..-1]
|
||||
end
|
||||
|
||||
__bw_complete_subcommand "up" -a "(docker-compose config --service)"
|
||||
__bw_complete_subcommand "pytest" -a "bookwyrm/tests/**.py"
|
||||
__bw_complete_subcommand "populate_streams" -a "--stream=" -d "pick a single stream to populate"
|
||||
__bw_complete_subcommand "populate_streams" -l stream -a "home local books"
|
||||
__bw_complete_subcommand "generate_preview_images" -a "--all"\
|
||||
-d "Generates images for ALL types: site, users and books. Can use a lot of computing power."
|
||||
__bw_complete_subcommand "set_cors_to_s3" -a "**.json"
|
|
@ -1,40 +0,0 @@
|
|||
#/usr/bin/env bash
|
||||
complete -W "up
|
||||
service_ports_web
|
||||
initdb
|
||||
resetdb
|
||||
makemigrations
|
||||
migrate
|
||||
bash
|
||||
shell
|
||||
dbshell
|
||||
restart_celery
|
||||
pytest
|
||||
pytest_coverage_report
|
||||
compile_themes
|
||||
collectstatic
|
||||
makemessages
|
||||
compilemessages
|
||||
update_locales
|
||||
build
|
||||
clean
|
||||
black
|
||||
prettier
|
||||
eslint
|
||||
stylelint
|
||||
formatters
|
||||
mypy
|
||||
collectstatic_watch
|
||||
populate_streams
|
||||
populate_lists_streams
|
||||
populate_suggestions
|
||||
generate_thumbnails
|
||||
generate_preview_images
|
||||
remove_remote_user_preview_images
|
||||
copy_media_to_s3
|
||||
set_cors_to_s3
|
||||
setup
|
||||
admin_code
|
||||
remove_2fa
|
||||
confirm_email
|
||||
runweb" -o bashdefault -o default bw-dev
|
|
@ -1,42 +0,0 @@
|
|||
#/usr/bin/env bash
|
||||
autoload bashcompinit
|
||||
bashcompinit
|
||||
complete -W "up
|
||||
service_ports_web
|
||||
initdb
|
||||
resetdb
|
||||
makemigrations
|
||||
migrate
|
||||
bash
|
||||
shell
|
||||
dbshell
|
||||
restart_celery
|
||||
pytest
|
||||
pytest_coverage_report
|
||||
compile_themes
|
||||
collectstatic
|
||||
makemessages
|
||||
compilemessages
|
||||
update_locales
|
||||
build
|
||||
clean
|
||||
black
|
||||
prettier
|
||||
eslint
|
||||
stylelint
|
||||
formatters
|
||||
mypy
|
||||
collectstatic_watch
|
||||
populate_streams
|
||||
populate_lists_streams
|
||||
populate_suggestions
|
||||
generate_thumbnails
|
||||
generate_preview_images
|
||||
remove_remote_user_preview_images
|
||||
copy_media_to_s3
|
||||
set_cors_to_s3
|
||||
setup
|
||||
admin_code
|
||||
remove_2fa
|
||||
confirm_email
|
||||
runweb" -o bashdefault -o default bw-dev
|
|
@ -1,5 +0,0 @@
|
|||
# Contrib
|
||||
|
||||
This directory contain some scripts, configuration files and other useful tools around BookWyrm.
|
||||
|
||||
These tools are not necessary for the proper functioning of BookWyrm but provide a helpful leg-up for integration with some third-party or to nicely fit BookWyrm into other environments.
|
|
@ -1,34 +0,0 @@
|
|||
[Unit]
|
||||
Description=BookWyrm scheduler
|
||||
After=network.target postgresql.service redis.service
|
||||
|
||||
[Service]
|
||||
User=bookwyrm
|
||||
Group=bookwyrm
|
||||
WorkingDirectory=/opt/bookwyrm
|
||||
ExecStart=/opt/bookwyrm/venv/bin/celery -A celerywyrm beat -l INFO --scheduler django_celery_beat.schedulers:DatabaseScheduler
|
||||
StandardOutput=journal
|
||||
StandardError=inherit
|
||||
ProtectSystem=strict
|
||||
ProtectHome=tmpfs
|
||||
InaccessiblePaths=-/media -/mnt -/srv
|
||||
PrivateTmp=yes
|
||||
TemporaryFileSystem=/var /run /opt
|
||||
PrivateUsers=true
|
||||
PrivateDevices=true
|
||||
BindReadOnlyPaths=/opt/bookwyrm
|
||||
BindPaths=/opt/bookwyrm/images /opt/bookwyrm/static /var/run/postgresql
|
||||
LockPersonality=yes
|
||||
MemoryDenyWriteExecute=true
|
||||
PrivateMounts=true
|
||||
ProtectHostname=true
|
||||
ProtectClock=true
|
||||
ProtectKernelTunables=true
|
||||
ProtectKernelModules=true
|
||||
ProtectKernelLogs=true
|
||||
ProtectControlGroups=true
|
||||
RestrictRealtime=true
|
||||
RestrictNamespaces=net
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
|
@ -1,34 +0,0 @@
|
|||
[Unit]
|
||||
Description=BookWyrm worker
|
||||
After=network.target postgresql.service redis.service
|
||||
|
||||
[Service]
|
||||
User=bookwyrm
|
||||
Group=bookwyrm
|
||||
WorkingDirectory=/opt/bookwyrm
|
||||
ExecStart=/opt/bookwyrm/venv/bin/celery -A celerywyrm worker -l info -Q high_priority,medium_priority,low_priority,streams,images,suggested_users,email,connectors,lists,inbox,imports,import_triggered,broadcast,misc
|
||||
StandardOutput=journal
|
||||
StandardError=inherit
|
||||
ProtectSystem=strict
|
||||
ProtectHome=tmpfs
|
||||
InaccessiblePaths=-/media -/mnt -/srv
|
||||
PrivateTmp=yes
|
||||
TemporaryFileSystem=/var /run /opt
|
||||
PrivateUsers=true
|
||||
PrivateDevices=true
|
||||
BindReadOnlyPaths=/opt/bookwyrm
|
||||
BindPaths=/opt/bookwyrm/images /opt/bookwyrm/static /var/run/postgresql
|
||||
LockPersonality=yes
|
||||
MemoryDenyWriteExecute=true
|
||||
PrivateMounts=true
|
||||
ProtectHostname=true
|
||||
ProtectClock=true
|
||||
ProtectKernelTunables=true
|
||||
ProtectKernelModules=true
|
||||
ProtectKernelLogs=true
|
||||
ProtectControlGroups=true
|
||||
RestrictRealtime=true
|
||||
RestrictNamespaces=net
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
|
@ -1,34 +0,0 @@
|
|||
[Unit]
|
||||
Description=BookWyrm
|
||||
After=network.target postgresql.service redis.service
|
||||
|
||||
[Service]
|
||||
User=bookwyrm
|
||||
Group=bookwyrm
|
||||
WorkingDirectory=/opt/bookwyrm
|
||||
ExecStart=/opt/bookwyrm/venv/bin/gunicorn bookwyrm.wsgi:application --bind 0.0.0.0:8000
|
||||
StandardOutput=journal
|
||||
StandardError=inherit
|
||||
ProtectSystem=strict
|
||||
ProtectHome=tmpfs
|
||||
InaccessiblePaths=-/media -/mnt -/srv
|
||||
PrivateTmp=yes
|
||||
TemporaryFileSystem=/var /run /opt
|
||||
PrivateUsers=true
|
||||
PrivateDevices=true
|
||||
BindReadOnlyPaths=/opt/bookwyrm
|
||||
BindPaths=/opt/bookwyrm/images /opt/bookwyrm/static /var/run/postgresql
|
||||
LockPersonality=yes
|
||||
MemoryDenyWriteExecute=true
|
||||
PrivateMounts=true
|
||||
ProtectHostname=true
|
||||
ProtectClock=true
|
||||
ProtectKernelTunables=true
|
||||
ProtectKernelModules=true
|
||||
ProtectKernelLogs=true
|
||||
ProtectControlGroups=true
|
||||
RestrictRealtime=true
|
||||
RestrictNamespaces=net
|
||||
|
||||
[Install]
|
||||
WantedBy=multi-user.target
|
|
@ -1,18 +0,0 @@
|
|||
FROM python:3.11-bookworm
|
||||
WORKDIR /app/dev-tools
|
||||
|
||||
ENV PATH="/app/dev-tools/node_modules/.bin:$PATH"
|
||||
ENV PYTHONUNBUFFERED=1
|
||||
ENV NPM_CONFIG_UPDATE_NOTIFIER=false
|
||||
ENV PIP_ROOT_USER_ACTION=ignore PIP_DISABLE_PIP_VERSION_CHECK=1
|
||||
|
||||
COPY nodejs.pref /etc/apt/preferences.d/
|
||||
COPY nodejs.sources /etc/apt/sources.list.d/
|
||||
COPY package.json requirements.txt .stylelintrc.js .stylelintignore /app/dev-tools/
|
||||
|
||||
RUN apt-get update && \
|
||||
apt-get install -y nodejs && \
|
||||
pip install -r requirements.txt && \
|
||||
npm install .
|
||||
|
||||
WORKDIR /app
|
|
@ -1,117 +0,0 @@
|
|||
services:
|
||||
nginx:
|
||||
image: nginx:1.25.2
|
||||
restart: unless-stopped
|
||||
ports:
|
||||
- "1333:80"
|
||||
depends_on:
|
||||
- web
|
||||
networks:
|
||||
- main
|
||||
volumes:
|
||||
- ./nginx:/etc/nginx/conf.d
|
||||
- static_volume:/app/static
|
||||
- media_volume:/app/images
|
||||
db:
|
||||
image: postgres:13
|
||||
env_file: .env
|
||||
volumes:
|
||||
- pgdata:/var/lib/postgresql/data
|
||||
networks:
|
||||
- main
|
||||
web:
|
||||
build: .
|
||||
env_file: .env
|
||||
command: python manage.py runserver 0.0.0.0:8000
|
||||
volumes:
|
||||
- .:/app
|
||||
- static_volume:/app/static
|
||||
- media_volume:/app/images
|
||||
- exports_volume:/app/exports
|
||||
depends_on:
|
||||
- db
|
||||
- celery_worker
|
||||
- redis_activity
|
||||
networks:
|
||||
- main
|
||||
ports:
|
||||
- "8000"
|
||||
redis_activity:
|
||||
image: redis:7.2.1
|
||||
command: redis-server --requirepass ${REDIS_ACTIVITY_PASSWORD} --appendonly yes --port ${REDIS_ACTIVITY_PORT}
|
||||
volumes:
|
||||
- ./redis.conf:/etc/redis/redis.conf
|
||||
- redis_activity_data:/data
|
||||
env_file: .env
|
||||
networks:
|
||||
- main
|
||||
restart: on-failure
|
||||
redis_broker:
|
||||
image: redis:7.2.1
|
||||
command: redis-server --requirepass ${REDIS_BROKER_PASSWORD} --appendonly yes --port ${REDIS_BROKER_PORT}
|
||||
volumes:
|
||||
- ./redis.conf:/etc/redis/redis.conf
|
||||
- redis_broker_data:/data
|
||||
env_file: .env
|
||||
networks:
|
||||
- main
|
||||
restart: on-failure
|
||||
celery_worker:
|
||||
env_file: .env
|
||||
build: .
|
||||
networks:
|
||||
- main
|
||||
command: celery -A celerywyrm worker -l info -Q high_priority,medium_priority,low_priority,streams,images,suggested_users,email,connectors,lists,inbox,imports,import_triggered,broadcast,misc
|
||||
volumes:
|
||||
- .:/app
|
||||
- static_volume:/app/static
|
||||
- media_volume:/app/images
|
||||
- exports_volume:/app/exports
|
||||
depends_on:
|
||||
- db
|
||||
- redis_broker
|
||||
restart: on-failure
|
||||
celery_beat:
|
||||
env_file: .env
|
||||
build: .
|
||||
networks:
|
||||
- main
|
||||
command: celery -A celerywyrm beat -l INFO --scheduler django_celery_beat.schedulers:DatabaseScheduler
|
||||
volumes:
|
||||
- .:/app
|
||||
- static_volume:/app/static
|
||||
- media_volume:/app/images
|
||||
- exports_volume:/app/exports
|
||||
depends_on:
|
||||
- celery_worker
|
||||
restart: on-failure
|
||||
flower:
|
||||
build: .
|
||||
command: celery -A celerywyrm flower --basic_auth=${FLOWER_USER}:${FLOWER_PASSWORD} --url_prefix=flower
|
||||
env_file: .env
|
||||
volumes:
|
||||
- .:/app
|
||||
- static_volume:/app/static
|
||||
networks:
|
||||
- main
|
||||
depends_on:
|
||||
- db
|
||||
- redis_broker
|
||||
restart: on-failure
|
||||
dev-tools:
|
||||
build: dev-tools
|
||||
env_file: .env
|
||||
volumes:
|
||||
- /app/dev-tools/
|
||||
- .:/app
|
||||
profiles:
|
||||
- tools
|
||||
volumes:
|
||||
pgdata:
|
||||
static_volume:
|
||||
media_volume:
|
||||
exports_volume:
|
||||
redis_broker_data:
|
||||
redis_activity_data:
|
||||
networks:
|
||||
main:
|
27
mypy.ini
27
mypy.ini
|
@ -1,27 +0,0 @@
|
|||
[mypy]
|
||||
plugins = mypy_django_plugin.main
|
||||
namespace_packages = True
|
||||
strict = True
|
||||
|
||||
[mypy.plugins.django-stubs]
|
||||
django_settings_module = "bookwyrm.settings"
|
||||
|
||||
[mypy-bookwyrm.*]
|
||||
ignore_errors = True
|
||||
implicit_reexport = True
|
||||
|
||||
[mypy-bookwyrm.connectors.*]
|
||||
ignore_errors = False
|
||||
|
||||
[mypy-bookwyrm.utils.*]
|
||||
ignore_errors = False
|
||||
|
||||
[mypy-bookwyrm.importers.*]
|
||||
ignore_errors = False
|
||||
|
||||
[mypy-bookwyrm.isbn.*]
|
||||
ignore_errors = False
|
||||
|
||||
[mypy-celerywyrm.*]
|
||||
ignore_errors = False
|
||||
|
|
@ -1,91 +0,0 @@
|
|||
include /etc/nginx/conf.d/server_config;
|
||||
|
||||
upstream web {
|
||||
server web:8000;
|
||||
}
|
||||
|
||||
server {
|
||||
access_log /var/log/nginx/access.log cache_log;
|
||||
|
||||
listen 80;
|
||||
|
||||
sendfile on;
|
||||
tcp_nopush on;
|
||||
tcp_nodelay on;
|
||||
keepalive_timeout 65;
|
||||
types_hash_max_size 2048;
|
||||
#include /etc/nginx/mime.types;
|
||||
#default_type application/octet-stream;
|
||||
|
||||
gzip on;
|
||||
gzip_disable "msie6";
|
||||
|
||||
proxy_read_timeout 1800s;
|
||||
chunked_transfer_encoding on;
|
||||
|
||||
# store responses to anonymous users for up to 1 minute
|
||||
proxy_cache bookwyrm_cache;
|
||||
proxy_cache_valid any 1m;
|
||||
add_header X-Cache-Status $upstream_cache_status;
|
||||
|
||||
# ignore the set cookie header when deciding to
|
||||
# store a response in the cache
|
||||
proxy_ignore_headers Cache-Control Set-Cookie Expires;
|
||||
|
||||
# PUT requests always bypass the cache
|
||||
# logged in sessions also do not populate the cache
|
||||
# to avoid serving personal data to anonymous users
|
||||
proxy_cache_methods GET HEAD;
|
||||
proxy_no_cache $cookie_sessionid;
|
||||
proxy_cache_bypass $cookie_sessionid;
|
||||
|
||||
# tell the web container the address of the outside client
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header Host $host;
|
||||
proxy_redirect off;
|
||||
|
||||
# rate limit the login or password reset pages
|
||||
location ~ ^/(login[^-/]|password-reset|resend-link|2fa-check) {
|
||||
limit_req zone=loginlimit;
|
||||
proxy_pass http://web;
|
||||
}
|
||||
|
||||
# do not log periodic polling requests from logged in users
|
||||
location /api/updates/ {
|
||||
access_log off;
|
||||
proxy_pass http://web;
|
||||
}
|
||||
|
||||
# forward any cache misses or bypass to the web container
|
||||
location / {
|
||||
proxy_pass http://web;
|
||||
}
|
||||
|
||||
# directly serve static files from the
|
||||
# bookwyrm filesystem using sendfile.
|
||||
# make the logs quieter by not reporting these requests
|
||||
location /static/ {
|
||||
root /app;
|
||||
try_files $uri =404;
|
||||
add_header X-Cache-Status STATIC;
|
||||
access_log off;
|
||||
}
|
||||
|
||||
# same with image files not in static folder
|
||||
location /images/ {
|
||||
location ~ \.(bmp|ico|jpg|jpeg|png|svg|tif|tiff|webp)$ {
|
||||
root /app;
|
||||
try_files $uri =404;
|
||||
add_header X-Cache-Status STATIC;
|
||||
access_log off;
|
||||
}
|
||||
# block access to any non-image files from images
|
||||
return 403;
|
||||
}
|
||||
|
||||
# monitor the celery queues with flower, no caching enabled
|
||||
location /flower/ {
|
||||
proxy_pass http://flower:8888;
|
||||
proxy_cache_bypass 1;
|
||||
}
|
||||
}
|
146
nginx/production
146
nginx/production
|
@ -1,146 +0,0 @@
|
|||
include /etc/nginx/conf.d/server_config;
|
||||
|
||||
upstream web {
|
||||
server web:8000;
|
||||
}
|
||||
|
||||
server {
|
||||
listen [::]:80;
|
||||
listen 80;
|
||||
|
||||
server_name your-domain.com www.your-domain.com;
|
||||
|
||||
location ~ /.well-known/acme-challenge {
|
||||
allow all;
|
||||
root /var/www/certbot;
|
||||
}
|
||||
|
||||
# # redirect http to https
|
||||
# return 301 https://your-domain.com$request_uri;
|
||||
}
|
||||
|
||||
|
||||
# server {
|
||||
# access_log /var/log/nginx/access.log cache_log;
|
||||
#
|
||||
# listen [::]:443 ssl http2;
|
||||
# listen 443 ssl http2;
|
||||
#
|
||||
# server_name your-domain.com;
|
||||
#
|
||||
# client_max_body_size 3M;
|
||||
#
|
||||
# if ($host != "your-domain.com") {
|
||||
# return 301 $scheme://your-domain.com$request_uri;
|
||||
# }
|
||||
#
|
||||
# # SSL code
|
||||
# ssl_certificate /etc/nginx/ssl/live/your-domain.com/fullchain.pem;
|
||||
# ssl_certificate_key /etc/nginx/ssl/live/your-domain.com/privkey.pem;
|
||||
#
|
||||
# location ~ /.well-known/acme-challenge {
|
||||
# allow all;
|
||||
# root /var/www/certbot;
|
||||
# }
|
||||
#
|
||||
# sendfile on;
|
||||
# tcp_nopush on;
|
||||
# tcp_nodelay on;
|
||||
# keepalive_timeout 65;
|
||||
# types_hash_max_size 2048;
|
||||
# #include /etc/nginx/mime.types;
|
||||
# #default_type application/octet-stream;
|
||||
#
|
||||
# gzip on;
|
||||
# gzip_disable "msie6";
|
||||
#
|
||||
# proxy_read_timeout 1800s;
|
||||
# chunked_transfer_encoding on;
|
||||
#
|
||||
# # store responses to anonymous users for up to 1 minute
|
||||
# proxy_cache bookwyrm_cache;
|
||||
# proxy_cache_valid any 1m;
|
||||
# add_header X-Cache-Status $upstream_cache_status;
|
||||
#
|
||||
# # ignore the set cookie header when deciding to
|
||||
# # store a response in the cache
|
||||
# proxy_ignore_headers Cache-Control Set-Cookie Expires;
|
||||
#
|
||||
# # PUT requests always bypass the cache
|
||||
# # logged in sessions also do not populate the cache
|
||||
# # to avoid serving personal data to anonymous users
|
||||
# proxy_cache_methods GET HEAD;
|
||||
# proxy_no_cache $cookie_sessionid;
|
||||
# proxy_cache_bypass $cookie_sessionid;
|
||||
#
|
||||
# # tell the web container the address of the outside client
|
||||
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
# proxy_set_header Host $host;
|
||||
# proxy_redirect off;
|
||||
#
|
||||
# location ~ ^/(login[^-/]|password-reset|resend-link|2fa-check) {
|
||||
# limit_req zone=loginlimit;
|
||||
# proxy_pass http://web;
|
||||
# }
|
||||
#
|
||||
# # do not log periodic polling requests from logged in users
|
||||
# location /api/updates/ {
|
||||
# access_log off;
|
||||
# proxy_pass http://web;
|
||||
# }
|
||||
#
|
||||
# location / {
|
||||
# proxy_pass http://web;
|
||||
# }
|
||||
#
|
||||
# # directly serve static files from the
|
||||
# # bookwyrm filesystem using sendfile.
|
||||
# # make the logs quieter by not reporting these requests
|
||||
# location /static/ {
|
||||
# root /app;
|
||||
# try_files $uri =404;
|
||||
# add_header X-Cache-Status STATIC;
|
||||
# access_log off;
|
||||
# }
|
||||
#
|
||||
# # same with image files not in static folder
|
||||
# location /images/ {
|
||||
# location ~ \.(bmp|ico|jpg|jpeg|png|svg|tif|tiff|webp)$ {
|
||||
# root /app;
|
||||
# try_files $uri =404;
|
||||
# add_header X-Cache-Status STATIC;
|
||||
# access_log off;
|
||||
# }
|
||||
# # block access to any non-image files from images
|
||||
# return 403;
|
||||
# }
|
||||
#
|
||||
# # monitor the celery queues with flower, no caching enabled
|
||||
# location /flower/ {
|
||||
# proxy_pass http://flower:8888;
|
||||
# proxy_cache_bypass 1;
|
||||
# }
|
||||
# }
|
||||
|
||||
# Reverse-Proxy server
|
||||
# server {
|
||||
# listen [::]:8001;
|
||||
# listen 8001;
|
||||
|
||||
# server_name your-domain.com www.your-domain.com;
|
||||
|
||||
# location / {
|
||||
# proxy_pass http://web;
|
||||
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
# proxy_set_header Host $host;
|
||||
# proxy_redirect off;
|
||||
# }
|
||||
|
||||
# location /images/ {
|
||||
# alias /app/images/;
|
||||
# }
|
||||
|
||||
# location /static/ {
|
||||
# alias /app/static/;
|
||||
# }
|
||||
# }
|
|
@ -1,22 +0,0 @@
|
|||
client_max_body_size 10m;
|
||||
limit_req_zone $binary_remote_addr zone=loginlimit:10m rate=1r/s;
|
||||
|
||||
# include the cache status in the log message
|
||||
log_format cache_log '$upstream_cache_status - '
|
||||
'$remote_addr [$time_local] '
|
||||
'"$request" $status $body_bytes_sent '
|
||||
'"$http_referer" "$http_user_agent" '
|
||||
'$upstream_response_time $request_time';
|
||||
|
||||
# Create a cache for responses from the web app
|
||||
proxy_cache_path
|
||||
/var/cache/nginx/bookwyrm_cache
|
||||
keys_zone=bookwyrm_cache:20m
|
||||
loader_threshold=400
|
||||
loader_files=400
|
||||
max_size=400m;
|
||||
|
||||
# use the accept header as part of the cache key
|
||||
# since activitypub endpoints have both HTML and JSON
|
||||
# on the same URI.
|
||||
proxy_cache_key $scheme$proxy_host$uri$is_args$args$http_accept;
|
|
@ -1,2 +0,0 @@
|
|||
[tool.black]
|
||||
required-version = "22"
|
|
@ -1 +0,0 @@
|
|||
./bw-dev migrate django_celery_beat
|
Loading…
Add table
Reference in a new issue