-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #102 from SynoCommunity/diaoul/refactor
ref!: various upgrades and fixes
- Loading branch information
Showing
29 changed files
with
1,886 additions
and
2,047 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
[flake8] | ||
max-line-length = 88 | ||
extend-ignore = E203 | ||
per-file-ignores = __init__.py:F401 | ||
per-file-ignores = __init__.py:F401 spkrepo/app.py:F841 | ||
exclude = | ||
docs/* | ||
migrations/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,34 +9,32 @@ jobs: | |
pre-commit: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
fetch-depth: 1 | ||
- uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.8 | ||
- uses: pre-commit/[email protected] | ||
python-version: 3.11 | ||
- uses: pre-commit/[email protected] | ||
|
||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v2 | ||
- uses: actions/checkout@v3 | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: 3.9 | ||
- uses: snok/install-poetry@v1.2.0 | ||
python-version: 3.11 | ||
- uses: snok/install-poetry@v1 | ||
with: | ||
virtualenvs-in-project: true | ||
- name: Load cached venv | ||
id: cached-poetry-dependencies | ||
uses: actions/cache@v2 | ||
uses: actions/cache@v3 | ||
with: | ||
path: .venv | ||
key: venv-${{ runner.os }}-${{ hashFiles('pyproject.toml') }} | ||
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/pyproject.toml') }} | ||
- name: Install dependencies | ||
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true' | ||
run: poetry install --no-interaction --no-root | ||
- name: Install application | ||
- name: Install project | ||
run: poetry install --no-interaction | ||
- name: Run tests | ||
run: poetry run pytest -v |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,45 +4,41 @@ Synology Package Repository | |
![Build](https://img.shields.io/github/actions/workflow/status/SynoCommunity/spkrepo/build.yml?branch=main&style=for-the-badge) | ||
[![Discord](https://img.shields.io/discord/732558169863225384?color=7289DA&label=Discord&logo=Discord&logoColor=white&style=for-the-badge)](https://discord.gg/nnN9fgE7EF) | ||
|
||
## Development | ||
|
||
## Development | ||
### Requirements | ||
* ImageMagic: `apt install imagemagic -y` | ||
* Python 3.10: `pyenv install 3.10 && poetry env use 3.10` | ||
* Recommended: `pyenv` and `pipx`: `apt install pyenv python-pipx -y` | ||
1. Install docker and docker-compose | ||
2. Install python and poetry | ||
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` | ||
|
||
### Installation | ||
1. Install dependencies with `poetry install` | ||
2. Run the next commands in the virtual environment `poetry shell` | ||
3. Create the tables with `python manage.py create` | ||
4. Populate the database with some fake packages with `python manage.py populate` | ||
5. Add an user with `python manage.py user create -u Admin -e [email protected] -p adminadmin` | ||
6. Grant the created user with Administrator permissions `python manage.py roles add [email protected] admin` | ||
7. Grant the created user with Package Administrator permissions `python manage.py roles add [email protected] package_admin` | ||
8. Grant the created user with Developer permissions `python manage.py roles add [email protected] developer` | ||
|
||
To reset the environment, clean up with `python manage.py clean`. | ||
1. Run postgres, e.g. using docker with `docker compose up db` | ||
2. Install dependencies with `poetry install` | ||
3. Run the next commands in the virtual environment `poetry shell` | ||
4. Create the tables with `flask db upgrade` | ||
5. Populate the database with some fake packages with `flask spkrepo populate_db` | ||
6. Add a user with `flask spkrepo create_user -u admin -e [email protected] -p adminadmin` | ||
7. Grant the created user with Administrator permissions `flask roles add [email protected] admin` | ||
8. Grant the created user with Package Administrator permissions `flask roles add [email protected] package_admin` | ||
9. Grant the created user with Developer permissions `flask roles add [email protected] developer` | ||
|
||
To clean data created by fake packages, run `flask spkrepo depopulate_db` | ||
|
||
### Run | ||
1. Start the development server with `python manage.py run` | ||
2. Website is available at http://localhost:5000 | ||
3. Admin interface is available at http://localhost:5000/admin | ||
4. NAS interface is available at http://localhost:5000/nas | ||
5. API is available at http://localhost:5000/api | ||
6. Run the test suite with `poetry run pytest -v` | ||
1. Start postgres with `docker compose up db` | ||
2. Start the development server with `flask run` | ||
3. Website is available at http://localhost:5000 | ||
4. Admin interface is available at http://localhost:5000/admin | ||
5. NAS interface is available at http://localhost:5000/nas | ||
6. API is available at http://localhost:5000/api | ||
7. Run the test suite with `pytest -v` | ||
|
||
## Docker Compose Run | ||
It is also possible to start a development environment with postgres database | ||
using docker compose: | ||
1. Build and run `docker-compose up --build` | ||
2. On first run you can apply database migrations with `docker exec spkrepo_spkrepo_1 python manage.py db upgrade`. | ||
Also run any other command that you need (populate the databse, create user) as mentioned above but by prefixing | ||
with `docker exec {container_id} [...]`. | ||
3. Browse to http://localhost:5000 | ||
4. To tear down the environment, run `docker-compose down --remove` | ||
- If you also want to run the app in docker you can with `docker compose up app` | ||
- You can run both postgres and the app with `docker compose up` | ||
|
||
## Deployment | ||
|
||
## Deployment | ||
### Configuration | ||
Create a config file `./config.py` to disable debug logs, connect to a database, set a secure key and optionally set a cache: | ||
|
||
|
@@ -55,7 +51,7 @@ SECRET_KEY = "Please-change-me-to-some-random-string" | |
SQLALCHEMY_ECHO = False | ||
SQLALCHEMY_DATABASE_URI = "postgresql://user:pass@localhost/dbname" | ||
# https://pythonhosted.org/Flask-Caching/#configuring-flask-caching | ||
CACHE_TYPE= "simple" | ||
CACHE_TYPE= "SimpleCache" | ||
# For signing packages | ||
GNUPG_PATH= "/usr/local/bin/gpg" | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,24 @@ | ||
version: "3.9" | ||
--- | ||
version: '3.8' | ||
|
||
services: | ||
db: | ||
image: postgres:13 | ||
image: postgres:15 | ||
environment: | ||
POSTGRES_DB: spkrepo | ||
POSTGRES_USER: spkrepo | ||
POSTGRES_PASSWORD: spkrepo | ||
spkrepo: | ||
build: . | ||
command: python manage.py runserver -h 0.0.0.0 | ||
ports: | ||
- "5000:5000" | ||
environment: | ||
SPKREPO_SQLALCHEMY_DATABASE_URI: postgresql://spkrepo:spkrepo@db/spkrepo | ||
volumes: | ||
- .:/usr/src/app/ | ||
depends_on: | ||
- db | ||
ports: | ||
- 5432:5432 | ||
app: | ||
build: . | ||
image: ghcr.io/synocommunity/spkrepo:v0.2.4 | ||
command: flask run -h 0.0.0.0 | ||
ports: | ||
- 5000:5000 | ||
environment: | ||
SPKREPO_SQLALCHEMY_DATABASE_URI: postgresql://spkrepo:spkrepo@db/spkrepo | ||
volumes: | ||
- .:/usr/src/app/ | ||
depends_on: | ||
- db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"""Add fs_uniquifier | ||
Revision ID: 76d559b4e873 | ||
Revises: d429595e8362 | ||
Create Date: 2022-10-24 09:31:01.814928 | ||
""" | ||
revision = "76d559b4e873" | ||
down_revision = "d429595e8362" | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
|
||
def upgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.add_column( | ||
"user", sa.Column("fs_uniquifier", sa.String(length=255), nullable=False) | ||
) | ||
op.create_unique_constraint(None, "user", ["fs_uniquifier"]) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade(): | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_constraint(None, "user", type_="unique") | ||
op.drop_column("user", "fs_uniquifier") | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
migrations/versions/dc7687894ba7_.py → ...ions/dc7687894ba7_increase_field_sizes.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
"""empty message | ||
"""Increase field sizes | ||
Revision ID: dc7687894ba7 | ||
Revises: d785f1fb2307 | ||
|
Oops, something went wrong.