Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ref!: various upgrades and fixes #102

Merged
merged 33 commits into from
Dec 31, 2023
Merged
Show file tree
Hide file tree
Changes from 26 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
2276ad2
ref!: various upgrades and fixes
Diaoul May 3, 2023
8b67ac8
fix: some things
Diaoul May 8, 2023
16a6c72
fix: pre-commit
Diaoul May 8, 2023
5e3673c
fix: flake8
Diaoul May 8, 2023
1efb756
fix: add instructions
Diaoul May 8, 2023
093f134
fix: update github actions
Diaoul May 8, 2023
5067dbb
fix: pre-commit action
Diaoul May 8, 2023
3763735
fix: python 3.11
Diaoul May 8, 2023
b38660d
fix: migrations sequence
mreid-tt Dec 30, 2023
f708234
Merge branch 'main' into diaoul/refactor
mreid-tt Dec 30, 2023
3ad7cfe
fix: duplicate db column
mreid-tt Dec 30, 2023
d6ea8d6
fix: api key form validation
mreid-tt Dec 30, 2023
39c9c88
fix: cli user creation
mreid-tt Dec 30, 2023
1aa2837
rollback: hide inactive packages
mreid-tt Dec 30, 2023
b4185ab
fix: python linting
mreid-tt Dec 30, 2023
91ccd9b
fixed several deprication warnings
publicarray Dec 31, 2023
4666ce6
fixed several deprecation warnings
publicarray Dec 31, 2023
b668f41
pass pre-commit hook
publicarray Dec 31, 2023
d7a3340
fix: redirect check
mreid-tt Dec 31, 2023
c43aeb8
fix: login for logged user
mreid-tt Dec 31, 2023
34db367
fix: babel keyerror
mreid-tt Dec 31, 2023
960043b
fix: pre-commit check
mreid-tt Dec 31, 2023
bd1f23d
update: readme
mreid-tt Dec 31, 2023
656104a
Update project requirements
mreid-tt Dec 31, 2023
1902668
fix: api test post
mreid-tt Dec 31, 2023
6d8df77
fix: pre-commit check
mreid-tt Dec 31, 2023
c935a44
Fixed more warnings in tests
publicarray Dec 31, 2023
840fe63
fix: api test post headers
mreid-tt Dec 31, 2023
8127f7b
update README
publicarray Dec 31, 2023
d379e7f
leftover cleanup
publicarray Dec 31, 2023
4247322
Minor readme correction
mreid-tt Dec 31, 2023
72c9c42
Revert "Minor readme correction"
mreid-tt Dec 31, 2023
c7e67e9
Update docker build
publicarray Dec 31, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .flake8
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/*
24 changes: 11 additions & 13 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
30 changes: 15 additions & 15 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,23 @@ jobs:
pypi:
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 library
- name: Install project
run: poetry install --no-interaction
- name: Publish
env:
Expand All @@ -36,20 +36,20 @@ jobs:
contents: read
packages: write
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}
- name: Log in to the Container registry
uses: docker/login-action@v1
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v3
with:
images: ghcr.io/${{ github.repository }}
- name: Build and push Docker image
uses: docker/build-push-action@v2
uses: docker/build-push-action@v4
with:
context: .
push: true
Expand Down
15 changes: 9 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
---
default_language_version:
python: python3.11
repos:
- repo: https://github.com/python-poetry/poetry
rev: master
rev: 1.4.2
hooks:
- id: poetry-export
- repo: https://github.com/psf/black
rev: 22.1.0
rev: 23.3.0
hooks:
- id: black
- repo: https://gitlab.com/PyCQA/flake8
rev: 3.9.2
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
- repo: https://github.com/PyCQA/isort
rev: 5.10.1
rev: 5.12.0
hooks:
- id: isort
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
Expand Down
1 change: 0 additions & 1 deletion .python-version

This file was deleted.

2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.9.7-buster
FROM python:3.11

WORKDIR /usr/src/app

Expand Down
54 changes: 25 additions & 29 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 clean`

### 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:

Expand Down
30 changes: 17 additions & 13 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
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: .
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
28 changes: 28 additions & 0 deletions migrations/versions/76d559b4e873_add_fs_uniquifier.py
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 ###
6 changes: 2 additions & 4 deletions migrations/versions/d429595e8362_update_build_path_length.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,13 @@
Create Date: 2022-10-22 21:31:03.050850

"""
revision = 'd429595e8362'
down_revision = 'dc7687894ba7'
revision = "d429595e8362"
down_revision = "dc7687894ba7"

import sqlalchemy as sa
from alembic import op




def upgrade():
op.alter_column(
"build",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""empty message
"""Increase field sizes

Revision ID: dc7687894ba7
Revises: d785f1fb2307
Expand Down
Loading