Skip to content

Commit cb30c12

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents 419336c + ff55ec3 commit cb30c12

File tree

6 files changed

+21
-17
lines changed

6 files changed

+21
-17
lines changed

docker-compose.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,27 @@ version: "3.7"
22

33
services:
44
api:
5-
image: python:3.9.1-buster
6-
build: mystbin/rest
5+
build: mystbin/backend
76
ports:
87
- 127.0.0.1:5557:9000/tcp
98
volumes:
109
- ./mystbin/database/schema.sql:/etc/schema.sql:ro
1110
- ./config.json:/usr/src/app/config.json:ro
12-
container_name: "staging-api"
11+
container_name: "mystbin-api"
1312
networks:
1413
main:
1514
ipv4_address: 172.25.0.11
1615
depends_on:
1716
- database
1817

1918
database:
20-
image: postgres:13-alpine
19+
image: postgres:14-alpine
2120
ports:
2221
- 127.0.0.1:5558:5432
23-
container_name: "staging-database"
22+
container_name: "mystbin-database"
2423
volumes:
2524
- postgresdata:/var/lib/postgresql/data/pgdata
25+
- ./mystbin/database/schema.sql:/docker-entrypoint-initdb.d/schema.sql:ro
2626
environment:
2727
POSTGRES_DB: mystbin
2828
POSTGRES_PASSWORD: "${POSTGRES_PASSWORD}"
@@ -40,7 +40,7 @@ services:
4040
- ./config.json:/app/config.json:ro
4141
ports:
4242
- 127.0.0.1:5559:3000
43-
container_name: "staging-frontend"
43+
container_name: "mystbin-frontend"
4444
build: ./mystbin/frontend
4545
depends_on:
4646
- api

mystbin/backend/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
FROM python:3.9.1-buster
1+
FROM python:3.9-slim
22

33
WORKDIR /usr/src/app
44

55
COPY . ./
66
RUN pip install --no-cache-dir -U -r requirements.txt
77
ENV ISDOCKER=true
88

9-
CMD ["python", "main.py"]
9+
CMD ["python", "-m", "uvicorn", "app:app", "--host", "0.0.0.0", "--port", "9000"]

mystbin/backend/main.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
from __future__ import annotations
2+
13
import argparse
24
import json
35
import os
46
import pathlib
57
import sys
68
from typing import cast
79

8-
910
import uvicorn
1011
from uvicorn.supervisors import Multiprocess
1112

@@ -26,6 +27,7 @@ def get_config() -> dict[str, dict[str, int | str]]:
2627

2728
return data
2829

30+
2931
if __name__ == "__main__":
3032
cfg = get_config()
3133
port = cast(int, cfg["site"]["backend_port"])
@@ -35,7 +37,7 @@ def get_config() -> dict[str, dict[str, int | str]]:
3537
parser.add_argument("--workers", "-w", nargs=1, default=os.cpu_count() or 1)
3638

3739
ns = parser.parse_args(sys.argv[1:])
38-
40+
3941
use_workers: bool = not ns.no_workers
4042
use_cli: bool = not ns.no_cli
4143
worker_count: int = ns.workers

mystbin/backend/requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ sentry-sdk==1.5.3
1010
starlette-prometheus==0.9.0
1111
typing-extensions==4.0.1
1212
ujson==5.1.0
13-
uvicorn[standard]==0.17.0
13+
uvicorn[standard]==0.18.0
1414
yarl
1515
aioconsole
1616
tabulate
17-
aioredis>2<3
17+
aioredis>2<3

mystbin/backend/routers/admin.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
import datetime
2222
import pathlib
2323
import subprocess
24-
from hmac import HMAC, compare_digest
2524
from hashlib import sha256
25+
from hmac import HMAC, compare_digest
2626
from typing import Dict, Optional, Union
2727

2828
import psutil
@@ -257,14 +257,14 @@ async def release_hook(request: MystbinRequest):
257257
with open(config) as f:
258258
config = ujson.load(f)
259259

260-
SECRET = config['github_secret'].encode()
260+
SECRET = config["github_secret"].encode()
261261

262-
received_sign = request.headers.get('X-Hub-Signature-256').split('sha256=')[-1].strip()
262+
received_sign = request.headers.get("X-Hub-Signature-256").split("sha256=")[-1].strip()
263263
expected_sign = HMAC(key=SECRET, msg=await request.body(), digestmod=sha256).hexdigest()
264264
if not compare_digest(received_sign, expected_sign):
265265
return UJSONResponse({"error": "Unauthorized"}, status_code=401)
266266

267-
command = 'cd /root/MystBin/; git pull;'
267+
command = "cd /root/MystBin/; git pull;"
268268
subprocess.run(command, stdout=subprocess.PIPE, shell=True)
269269

270270
return Response(status_code=200)

mystbin/backend/utils/db.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
You should have received a copy of the GNU General Public License
1717
along with MystBin. If not, see <https://www.gnu.org/licenses/>.
1818
"""
19+
from __future__ import annotations
20+
1921
import asyncio
2022
import datetime
2123
import difflib
@@ -269,7 +271,7 @@ async def put_paste(
269271
resp["id"],
270272
page.content,
271273
page.filename,
272-
page.content.count("\n") + 1, # add an extra for line 1
274+
page.content.count("\n") + 1, # add an extra for line 1
273275
)
274276
)
275277

0 commit comments

Comments
 (0)