Skip to content

Commit 9892bf7

Browse files
authored
Merge branch 'production' into main
2 parents cb5603d + 6cea7c0 commit 9892bf7

File tree

14 files changed

+716
-25
lines changed

14 files changed

+716
-25
lines changed

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.7.3
1+
0.7.4

bookwyrm/settings.py

+6
Original file line numberDiff line numberDiff line change
@@ -293,9 +293,15 @@
293293
AUTH_PASSWORD_VALIDATORS = [
294294
{
295295
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
296+
'OPTIONS': {
297+
'max_similarity': .9,
298+
}
296299
},
297300
{
298301
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
302+
'OPTIONS': {
303+
'min_length': 16,
304+
}
299305
},
300306
{
301307
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",

bookwyrm/views/landing/password.py

+1
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ def post(self, request, code):
7575
return TemplateResponse(request, "landing/password_reset.html", data)
7676

7777
new_password = form.cleaned_data["password"]
78+
# deepcode ignore DjangoUnvalidatedPassword: cleaned_data validates the password; would be nice to move validation here eventually
7879
user.set_password(new_password)
7980
user.save(broadcast=False, update_fields=["password"])
8081
login(request, user)

bookwyrm/views/preferences/change_password.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ def post(self, request):
3030
data = {"form": form}
3131
return TemplateResponse(request, "preferences/change_password.html", data)
3232

33-
new_password = form.cleaned_data["password"]
33+
new_password = form.cleaned_data["password"]
34+
# deepcode ignore DjangoUnvalidatedPassword: cleaned_data includes password validation; would be nice to move it here eventually
3435
request.user.set_password(new_password)
3536
request.user.save(broadcast=False, update_fields=["password"])
3637

contrib/systemd/bookwyrm.service

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ After=network.target postgresql.service redis.service
66
User=bookwyrm
77
Group=bookwyrm
88
WorkingDirectory=/opt/bookwyrm
9-
ExecStart=/opt/bookwyrm/venv/bin/gunicorn bookwyrm.wsgi:application --bind 0.0.0.0:8000
9+
ExecStart=/opt/bookwyrm/venv/bin/gunicorn bookwyrm.wsgi:application --threads=8 --bind 0.0.0.0:8000
1010
StandardOutput=journal
1111
StandardError=inherit
1212
ProtectSystem=strict

docker-compose.yml

+35-3
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,54 @@
1+
version: '3'
2+
3+
x-logging:
4+
&default-logging
5+
driver: "json-file"
6+
options:
7+
max-size: "150m"
8+
max-file: "2"
9+
110
services:
211
nginx:
312
image: nginx:1.25.2
13+
logging: *default-logging
414
restart: unless-stopped
515
ports:
6-
- "1333:80"
16+
- "80:80"
17+
- "443:443"
718
depends_on:
819
- web
920
networks:
1021
- main
1122
volumes:
1223
- ./nginx:/etc/nginx/conf.d
24+
- ./certbot/conf:/etc/nginx/ssl
25+
- ./certbot/data:/var/www/certbot
1326
- static_volume:/app/static
1427
- media_volume:/app/images
28+
certbot:
29+
image: certbot/certbot:latest
30+
command: certonly --webroot --webroot-path=/var/www/certbot --email ${EMAIL} --agree-tos --no-eff-email -d ${DOMAIN} -d www.${DOMAIN}
31+
#command: renew --webroot --webroot-path /var/www/certbot
32+
logging: *default-logging
33+
volumes:
34+
- ./certbot/conf:/etc/letsencrypt
35+
- ./certbot/logs:/var/log/letsencrypt
36+
- ./certbot/data:/var/www/certbot
1537
db:
16-
image: postgres:13
38+
build: postgres-docker
1739
env_file: .env
40+
entrypoint: /bookwyrm-entrypoint.sh
41+
command: cron postgres
1842
volumes:
1943
- pgdata:/var/lib/postgresql/data
44+
- backups:/backups
2045
networks:
2146
- main
2247
web:
2348
build: .
2449
env_file: .env
25-
command: python manage.py runserver 0.0.0.0:8000
50+
command: gunicorn bookwyrm.wsgi:application --threads=8 --bind 0.0.0.0:8000
51+
logging: *default-logging
2652
volumes:
2753
- .:/app
2854
- static_volume:/app/static
@@ -39,6 +65,7 @@ services:
3965
redis_activity:
4066
image: redis:7.2.1
4167
command: redis-server --requirepass ${REDIS_ACTIVITY_PASSWORD} --appendonly yes --port ${REDIS_ACTIVITY_PORT}
68+
logging: *default-logging
4269
volumes:
4370
- ./redis.conf:/etc/redis/redis.conf
4471
- redis_activity_data:/data
@@ -49,6 +76,7 @@ services:
4976
redis_broker:
5077
image: redis:7.2.1
5178
command: redis-server --requirepass ${REDIS_BROKER_PASSWORD} --appendonly yes --port ${REDIS_BROKER_PORT}
79+
logging: *default-logging
5280
volumes:
5381
- ./redis.conf:/etc/redis/redis.conf
5482
- redis_broker_data:/data
@@ -62,6 +90,7 @@ services:
6290
networks:
6391
- main
6492
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
93+
logging: *default-logging
6594
volumes:
6695
- .:/app
6796
- static_volume:/app/static
@@ -77,6 +106,7 @@ services:
77106
networks:
78107
- main
79108
command: celery -A celerywyrm beat -l INFO --scheduler django_celery_beat.schedulers:DatabaseScheduler
109+
logging: *default-logging
80110
volumes:
81111
- .:/app
82112
- static_volume:/app/static
@@ -88,6 +118,7 @@ services:
88118
flower:
89119
build: .
90120
command: celery -A celerywyrm flower --basic_auth=${FLOWER_USER}:${FLOWER_PASSWORD} --url_prefix=flower
121+
logging: *default-logging
91122
env_file: .env
92123
volumes:
93124
- .:/app
@@ -108,6 +139,7 @@ services:
108139
- tools
109140
volumes:
110141
pgdata:
142+
backups:
111143
static_volume:
112144
media_volume:
113145
exports_volume:

postgres-docker/Dockerfile

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
FROM postgres:13.0
2+
3+
# crontab
4+
RUN mkdir /backups
5+
COPY ./backup.sh /usr/local/bin/bookwyrm-backup.sh
6+
COPY ./weed.sh /usr/local/bin/bookwyrm-weed.sh
7+
COPY ./cronfile /etc/cron.d/cronfile
8+
RUN apt-get update && apt-get -y --no-install-recommends install cron
9+
RUN chmod 0644 /etc/cron.d/cronfile
10+
RUN crontab /etc/cron.d/cronfile
11+
RUN touch /var/log/cron.log
12+
13+
# The postgres image's entrypoint expects the docker command to only contain flags to
14+
# pass postgres. It runs the entrypoint twice, the second times as the postgres user.
15+
# We need to start the cron service the first time it runs, when it's still being run
16+
# as the root user. We're going to add a check that looks at the first argument and
17+
# if it's 'cron', starts the service and then removes that argument.
18+
RUN awk '$0 ~ /^\t_main "\$@"$/ { print "\tif [[ $1 == cron ]]; then\n\t\techo \"POSTGRES_DB=${POSTGRES_DB}\" > /backups/.env\n\t\techo \"POSTGRES_USER=${POSTGRES_USER}\" >> /backups/.env\n\t\tservice cron start\n\t\tshift\n\tfi" }{ print }' docker-entrypoint.sh > bookwyrm-entrypoint.sh
19+
RUN chown postgres /bookwyrm-entrypoint.sh
20+
RUN chmod u=rwx,go=r /bookwyrm-entrypoint.sh

postgres-docker/backup.sh

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
source /backups/.env
3+
4+
if [ -z "$POSTGRES_DB" ]; then
5+
echo "Database not specified, defaulting to bookwyrm"
6+
fi
7+
if [ -z "$POSTGRES_USER" ]; then
8+
echo "Database user not specified, defaulting to bookwyrm"
9+
fi
10+
BACKUP_DB=${POSTGRES_DB:-bookwyrm}
11+
BACKUP_USER=${POSTGRES_USER:-bookwyrm}
12+
filename=backup_${BACKUP_DB}_$(date +%F)
13+
pg_dump -U $BACKUP_USER $BACKUP_DB > /backups/$filename.sql

postgres-docker/cronfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
0 0 * * * /usr/local/bin/bookwyrm-backup.sh
2+
# If uncommented, this script will weed the backups directory. It will keep the 14
3+
# most-recent backups, then one backup/week for the next four backups, then one
4+
# backup/month after that.
5+
# 0 5 * * * /usr/local/bin/bookwyrm-weed.sh -d 14 -w 4 -m -1 /backups

postgres-docker/tests/Dockerfile

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
FROM postgres:latest
2+
3+
RUN apt update && apt install -y shellcheck
4+
5+
COPY ./tests/testing-entrypoint.sh /testing-entrypoint.sh
6+
RUN chmod u+rx,go=r /testing-entrypoint.sh
7+
COPY ./weed.sh /weed.sh
8+
RUN chmod u+rx,go=r /weed.sh
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: "3"
2+
3+
services:
4+
weeding:
5+
build:
6+
# We need to build from the parent directory so we can access weed.sh
7+
context: ..
8+
dockerfile: ./tests/Dockerfile
9+
entrypoint: /testing-entrypoint.sh

0 commit comments

Comments
 (0)