Skip to content

Commit 8a5521e

Browse files
authored
Merge pull request #102 from SynoCommunity/diaoul/refactor
ref!: various upgrades and fixes
2 parents b3d6268 + c7e67e9 commit 8a5521e

29 files changed

+1886
-2047
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[flake8]
22
max-line-length = 88
33
extend-ignore = E203
4-
per-file-ignores = __init__.py:F401
4+
per-file-ignores = __init__.py:F401 spkrepo/app.py:F841
55
exclude =
66
docs/*
77
migrations/*

.github/workflows/build.yml

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,34 +9,32 @@ jobs:
99
pre-commit:
1010
runs-on: ubuntu-latest
1111
steps:
12-
- uses: actions/checkout@v2
12+
- uses: actions/checkout@v3
13+
- uses: actions/setup-python@v4
1314
with:
14-
fetch-depth: 1
15-
- uses: actions/setup-python@v2
16-
with:
17-
python-version: 3.8
18-
- uses: pre-commit/action@v2.0.0
15+
python-version: 3.11
16+
- uses: pre-commit/action@v3.0.0
1917

2018
test:
2119
runs-on: ubuntu-latest
2220
steps:
23-
- uses: actions/checkout@v2
24-
- uses: actions/setup-python@v2
21+
- uses: actions/checkout@v3
22+
- uses: actions/setup-python@v4
2523
with:
26-
python-version: 3.9
27-
- uses: snok/install-poetry@v1.2.0
24+
python-version: 3.11
25+
- uses: snok/install-poetry@v1
2826
with:
2927
virtualenvs-in-project: true
3028
- name: Load cached venv
3129
id: cached-poetry-dependencies
32-
uses: actions/cache@v2
30+
uses: actions/cache@v3
3331
with:
3432
path: .venv
35-
key: venv-${{ runner.os }}-${{ hashFiles('pyproject.toml') }}
33+
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/pyproject.toml') }}
3634
- name: Install dependencies
3735
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
3836
run: poetry install --no-interaction --no-root
39-
- name: Install application
37+
- name: Install project
4038
run: poetry install --no-interaction
4139
- name: Run tests
4240
run: poetry run pytest -v

.github/workflows/publish.yml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,23 @@ jobs:
88
pypi:
99
runs-on: ubuntu-latest
1010
steps:
11-
- uses: actions/checkout@v2
12-
- uses: actions/setup-python@v2
11+
- uses: actions/checkout@v3
12+
- uses: actions/setup-python@v4
1313
with:
14-
python-version: 3.9
15-
- uses: snok/install-poetry@v1.2.0
14+
python-version: 3.11
15+
- uses: snok/install-poetry@v1
1616
with:
1717
virtualenvs-in-project: true
1818
- name: Load cached venv
1919
id: cached-poetry-dependencies
20-
uses: actions/cache@v2
20+
uses: actions/cache@v3
2121
with:
2222
path: .venv
23-
key: venv-${{ runner.os }}-${{ hashFiles('pyproject.toml') }}
23+
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/pyproject.toml') }}
2424
- name: Install dependencies
2525
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
2626
run: poetry install --no-interaction --no-root
27-
- name: Install library
27+
- name: Install project
2828
run: poetry install --no-interaction
2929
- name: Publish
3030
env:
@@ -36,20 +36,20 @@ jobs:
3636
contents: read
3737
packages: write
3838
steps:
39-
- uses: actions/checkout@v2
39+
- uses: actions/checkout@v3
40+
- name: Extract metadata (tags, labels) for Docker
41+
id: meta
42+
uses: docker/metadata-action@v4
43+
with:
44+
images: ghcr.io/${{ github.repository }}
4045
- name: Log in to the Container registry
41-
uses: docker/login-action@v1
46+
uses: docker/login-action@v2
4247
with:
4348
registry: ghcr.io
4449
username: ${{ github.actor }}
4550
password: ${{ secrets.GITHUB_TOKEN }}
46-
- name: Extract metadata (tags, labels) for Docker
47-
id: meta
48-
uses: docker/metadata-action@v3
49-
with:
50-
images: ghcr.io/${{ github.repository }}
5151
- name: Build and push Docker image
52-
uses: docker/build-push-action@v2
52+
uses: docker/build-push-action@v4
5353
with:
5454
context: .
5555
push: true

.pre-commit-config.yaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
1+
---
2+
default_language_version:
3+
python: python3.11
14
repos:
25
- repo: https://github.com/python-poetry/poetry
3-
rev: master
6+
rev: 1.4.2
47
hooks:
58
- id: poetry-export
69
- repo: https://github.com/psf/black
7-
rev: 22.1.0
10+
rev: 23.3.0
811
hooks:
912
- id: black
10-
- repo: https://gitlab.com/PyCQA/flake8
11-
rev: 3.9.2
13+
- repo: https://github.com/PyCQA/flake8
14+
rev: 6.0.0
1215
hooks:
1316
- id: flake8
1417
- repo: https://github.com/PyCQA/isort
15-
rev: 5.10.1
18+
rev: 5.12.0
1619
hooks:
1720
- id: isort
1821
- repo: https://github.com/pre-commit/pre-commit-hooks
19-
rev: v4.1.0
22+
rev: v4.4.0
2023
hooks:
2124
- id: trailing-whitespace
2225
- id: end-of-file-fixer

.python-version

Lines changed: 0 additions & 1 deletion
This file was deleted.

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.9.7-buster
1+
FROM python:3.11
22

33
WORKDIR /usr/src/app
44

@@ -14,7 +14,7 @@ RUN pip install --no-cache-dir -r requirements.txt
1414

1515
COPY spkrepo ./spkrepo
1616
COPY migrations ./migrations
17-
COPY manage.py wsgi.py ./
17+
COPY wsgi.py ./
1818

1919
HEALTHCHECK --interval=1m --timeout=5s \
2020
CMD curl -f http://localhost:8000/ || exit 1

README.md

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,41 @@ Synology Package Repository
44
![Build](https://img.shields.io/github/actions/workflow/status/SynoCommunity/spkrepo/build.yml?branch=main&style=for-the-badge)
55
[![Discord](https://img.shields.io/discord/732558169863225384?color=7289DA&label=Discord&logo=Discord&logoColor=white&style=for-the-badge)](https://discord.gg/nnN9fgE7EF)
66

7-
## Development
87

8+
## Development
99
### Requirements
10-
* ImageMagic: `apt install imagemagic -y`
11-
* Python 3.10: `pyenv install 3.10 && poetry env use 3.10`
12-
* Recommended: `pyenv` and `pipx`: `apt install pyenv python-pipx -y`
10+
1. Install docker and docker-compose
11+
2. Install python and poetry
12+
3. Optionally install direnv and a working poetry layout as described [here](https://github.com/direnv/direnv/issues/592#issuecomment-856227234) in your `~/.config/direnv/direnvrc`
1313

1414
### Installation
15-
1. Install dependencies with `poetry install`
16-
2. Run the next commands in the virtual environment `poetry shell`
17-
3. Create the tables with `python manage.py create`
18-
4. Populate the database with some fake packages with `python manage.py populate`
19-
5. Add an user with `python manage.py user create -u Admin -e admin@admin.adm -p adminadmin`
20-
6. Grant the created user with Administrator permissions `python manage.py roles add admin@admin.adm admin`
21-
7. Grant the created user with Package Administrator permissions `python manage.py roles add admin@admin.adm package_admin`
22-
8. Grant the created user with Developer permissions `python manage.py roles add admin@admin.adm developer`
23-
24-
To reset the environment, clean up with `python manage.py clean`.
15+
1. Run postgres, e.g. using docker with `docker compose up db`
16+
2. Install dependencies with `poetry install`
17+
3. Run the next commands in the virtual environment `poetry shell`
18+
4. Create the tables with `flask db upgrade`
19+
5. Populate the database with some fake packages with `flask spkrepo populate_db`
20+
6. Add a user with `flask spkrepo create_user -u admin -e admin@synocommunity.com -p adminadmin`
21+
7. Grant the created user with Administrator permissions `flask roles add admin@synocommunity.com admin`
22+
8. Grant the created user with Package Administrator permissions `flask roles add admin@synocommunity.com package_admin`
23+
9. Grant the created user with Developer permissions `flask roles add admin@synocommunity.com developer`
24+
25+
To clean data created by fake packages, run `flask spkrepo depopulate_db`
2526

2627
### Run
27-
1. Start the development server with `python manage.py run`
28-
2. Website is available at http://localhost:5000
29-
3. Admin interface is available at http://localhost:5000/admin
30-
4. NAS interface is available at http://localhost:5000/nas
31-
5. API is available at http://localhost:5000/api
32-
6. Run the test suite with `poetry run pytest -v`
28+
1. Start postgres with `docker compose up db`
29+
2. Start the development server with `flask run`
30+
3. Website is available at http://localhost:5000
31+
4. Admin interface is available at http://localhost:5000/admin
32+
5. NAS interface is available at http://localhost:5000/nas
33+
6. API is available at http://localhost:5000/api
34+
7. Run the test suite with `pytest -v`
3335

3436
## Docker Compose Run
35-
It is also possible to start a development environment with postgres database
36-
using docker compose:
37-
1. Build and run `docker-compose up --build`
38-
2. On first run you can apply database migrations with `docker exec spkrepo_spkrepo_1 python manage.py db upgrade`.
39-
Also run any other command that you need (populate the databse, create user) as mentioned above but by prefixing
40-
with `docker exec {container_id} [...]`.
41-
3. Browse to http://localhost:5000
42-
4. To tear down the environment, run `docker-compose down --remove`
37+
- If you also want to run the app in docker you can with `docker compose up app`
38+
- You can run both postgres and the app with `docker compose up`
4339

44-
## Deployment
4540

41+
## Deployment
4642
### Configuration
4743
Create a config file `./config.py` to disable debug logs, connect to a database, set a secure key and optionally set a cache:
4844

@@ -55,7 +51,7 @@ SECRET_KEY = "Please-change-me-to-some-random-string"
5551
SQLALCHEMY_ECHO = False
5652
SQLALCHEMY_DATABASE_URI = "postgresql://user:pass@localhost/dbname"
5753
# https://pythonhosted.org/Flask-Caching/#configuring-flask-caching
58-
CACHE_TYPE= "simple"
54+
CACHE_TYPE= "SimpleCache"
5955
# For signing packages
6056
GNUPG_PATH= "/usr/local/bin/gpg"
6157
```

docker-compose.yaml

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
1-
version: "3.9"
1+
---
2+
version: '3.8'
3+
24
services:
35
db:
4-
image: postgres:13
6+
image: postgres:15
57
environment:
68
POSTGRES_DB: spkrepo
79
POSTGRES_USER: spkrepo
810
POSTGRES_PASSWORD: spkrepo
9-
spkrepo:
10-
build: .
11-
command: python manage.py runserver -h 0.0.0.0
12-
ports:
13-
- "5000:5000"
14-
environment:
15-
SPKREPO_SQLALCHEMY_DATABASE_URI: postgresql://spkrepo:spkrepo@db/spkrepo
16-
volumes:
17-
- .:/usr/src/app/
18-
depends_on:
19-
- db
11+
ports:
12+
- 5432:5432
13+
app:
14+
build: .
15+
image: ghcr.io/synocommunity/spkrepo:v0.2.4
16+
command: flask run -h 0.0.0.0
17+
ports:
18+
- 5000:5000
19+
environment:
20+
SPKREPO_SQLALCHEMY_DATABASE_URI: postgresql://spkrepo:spkrepo@db/spkrepo
21+
volumes:
22+
- .:/usr/src/app/
23+
depends_on:
24+
- db
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"""Add fs_uniquifier
2+
3+
Revision ID: 76d559b4e873
4+
Revises: d429595e8362
5+
Create Date: 2022-10-24 09:31:01.814928
6+
7+
"""
8+
revision = "76d559b4e873"
9+
down_revision = "d429595e8362"
10+
11+
import sqlalchemy as sa
12+
from alembic import op
13+
14+
15+
def upgrade():
16+
# ### commands auto generated by Alembic - please adjust! ###
17+
op.add_column(
18+
"user", sa.Column("fs_uniquifier", sa.String(length=255), nullable=False)
19+
)
20+
op.create_unique_constraint(None, "user", ["fs_uniquifier"])
21+
# ### end Alembic commands ###
22+
23+
24+
def downgrade():
25+
# ### commands auto generated by Alembic - please adjust! ###
26+
op.drop_constraint(None, "user", type_="unique")
27+
op.drop_column("user", "fs_uniquifier")
28+
# ### end Alembic commands ###

migrations/versions/d429595e8362_update_build_path_length.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,13 @@
55
Create Date: 2022-10-22 21:31:03.050850
66
77
"""
8-
revision = 'd429595e8362'
9-
down_revision = 'dc7687894ba7'
8+
revision = "d429595e8362"
9+
down_revision = "dc7687894ba7"
1010

1111
import sqlalchemy as sa
1212
from alembic import op
1313

1414

15-
16-
1715
def upgrade():
1816
op.alter_column(
1917
"build",

0 commit comments

Comments
 (0)