diff --git a/.dockerignore b/.dockerignore index 98e9945a2..c9bfa05d9 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,6 +1,4 @@ * !dist -!platform_api.egg-info !alembic !alembic.ini -**/*.pyc diff --git a/.github/dependabot.yml b/.github/dependabot.yml index 86a28a6f0..8438a053a 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -8,18 +8,6 @@ updates: open-pull-requests-limit: 10 ignore: - dependency-name: sqlalchemy - versions: - - 1.4.0 - - 1.4.1 - - 1.4.10 - - 1.4.2 - - 1.4.3 - - 1.4.4 - - 1.4.5 - - 1.4.6 - - 1.4.7 - - 1.4.8 - - 1.4.9 - package-ecosystem: github-actions directory: / schedule: diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 647d29e33..5c4375560 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -32,8 +32,7 @@ jobs: uses: actions/cache@v2.1.6 with: path: ~/.cache/pip - key: ${{ runner.os }}-py-3.8.10-${{ hashFiles('requirements/*.txt') }}-${{ - hashFiles('setup.py') }} + key: ${{ runner.os }}-py-3.8.10-${{ hashFiles('pyproject.toml') }}-${{ hashFiles('setup.cfg') }} - name: Install dependencies run: make setup - name: Lint diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..c5824c502 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,29 @@ +ARG PYTHON_VERSION=3.8.12 +ARG PYTHON_BASE=buster + +FROM python:${PYTHON_VERSION} AS installer + +ENV PATH=/root/.local/bin:$PATH + +# Copy to tmp folder to don't pollute home dir +RUN mkdir -p /tmp/dist +COPY dist /tmp/dist + +RUN ls /tmp/dist +RUN pip install --user --find-links /tmp/dist platform-api + +FROM python:${PYTHON_VERSION}-${PYTHON_BASE} AS service + +LABEL org.opencontainers.image.source = "https://github.com/neuro-inc/platform-api" + +WORKDIR /app + +COPY --from=installer /root/.local/ /root/.local/ +COPY alembic.ini alembic.ini +COPY alembic alembic + +ENV PATH=/root/.local/bin:$PATH +ENV NP_API_PORT=8080 +EXPOSE $NP_API_PORT + +CMD platform-api diff --git a/Dockerfile.k8s b/Dockerfile.k8s deleted file mode 100644 index f4cd0f233..000000000 --- a/Dockerfile.k8s +++ /dev/null @@ -1,31 +0,0 @@ -FROM python:3.8.10-buster as installer - -# Separate step for requirements to speed up docker builds -COPY platform_api.egg-info/requires.txt requires.txt -RUN python -c 'from pkg_resources import Distribution, PathMetadata;\ -dist = Distribution(metadata=PathMetadata(".", "."));\ -print("\n".join(str(r) for r in dist.requires()));\ -' > requirements.txt -RUN pip install -U pip && pip install --user -r requirements.txt - -ARG DIST_FILENAME - -# Install service itself -COPY dist/${DIST_FILENAME} ${DIST_FILENAME} -RUN pip install --user $DIST_FILENAME - -FROM python:3.8.10-buster AS service - -LABEL org.opencontainers.image.source = "https://github.com/neuro-inc/platform-api" - -WORKDIR /neuromation - -COPY --from=installer /root/.local/ /root/.local/ -COPY alembic.ini alembic.ini -COPY alembic alembic - -ENV PATH=/root/.local/bin:$PATH -ENV NP_API_PORT=8080 -EXPOSE $NP_API_PORT - -CMD platform-api diff --git a/Makefile b/Makefile index 79d0f80ac..19947c418 100644 --- a/Makefile +++ b/Makefile @@ -32,11 +32,11 @@ include k8s.mk setup: pip install -U pip - pip install -r requirements/test.txt + pip install -e .[dev] pre-commit install lint: format - mypy --show-error-codes platform_api tests setup.py alembic + mypy --show-error-codes platform_api tests alembic format: ifdef CI_LINT_RUN @@ -52,9 +52,12 @@ test_integration: pytest -vv --maxfail=3 --cov platform_api --cov-config=setup.cfg --cov-report xml:.coverage-integration.xml tests/integration docker_build: - python setup.py sdist - docker build -f Dockerfile.k8s -t $(IMAGE_NAME):latest \ - --build-arg DIST_FILENAME=`python setup.py --fullname`.tar.gz . + rm -rf build dist + pip install -U build + python -m build + docker build \ + --build-arg PYTHON_BASE=slim-buster \ + -t $(IMAGE_NAME):latest . docker_push: docker_build docker tag $(IMAGE_NAME):latest $(IMAGE_REPO):$(TAG) diff --git a/README.md b/README.md index dfd8ac222..a4fbb48cd 100644 --- a/README.md +++ b/README.md @@ -29,9 +29,9 @@ kubectl apply -f tests/k8s/storageclass.yml python -m venv venv source venv/bin/activate ``` -7. Install testing dependencies: +7. Install dev dependencies: ```shell -pip install -r requirements/test.txt +pip install -e .[dev] ``` 8. Run the unit test suite: ```shell diff --git a/pyproject.toml b/pyproject.toml index b1fa10ad9..e1bc083bd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,9 +1,19 @@ +[build-system] +requires = [ + "setuptools>=45", + "wheel", + "setuptools_scm>=6.2", +] +build-backend = "setuptools.build_meta" + +[tool.setuptools_scm] +git_describe_command = "git describe --dirty --tags --long --match v*.*.*" + [tool.black] exclude = ''' /( \.git | venv | __pycache__ - | \.tox )/ ''' diff --git a/requirements/syntax.txt b/requirements/syntax.txt deleted file mode 100644 index 76d3dbf08..000000000 --- a/requirements/syntax.txt +++ /dev/null @@ -1,8 +0,0 @@ --e . -black==21.9b0 -flake8==3.9.2 -flake8-isort==4.0.0 -isort==5.9.3 -mypy==0.910 -pre-commit==2.15.0 -types-setuptools==57.4.0 diff --git a/requirements/test.txt b/requirements/test.txt deleted file mode 100644 index 62a51b609..000000000 --- a/requirements/test.txt +++ /dev/null @@ -1,8 +0,0 @@ --e . --r syntax.txt -aiodocker==0.21.0 -codecov==2.1.12 -pytest==6.2.5 -pytest-asyncio==0.15.1 -pytest-cov==3.0.0 -requests==2.26.0 diff --git a/setup.cfg b/setup.cfg index 35909c2ac..0c646b0a7 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,3 +1,63 @@ +[metadata] +name = platform-api +description = Neu.ro platform api +url = https://github.com/neuro-inc/platform-api +long_description = file: README.md, LICENSE +license = Apache 2 +classifiers = + License :: OSI Approved :: Apache 2 + Programming Language :: Python :: 3 + +[options] +zip_safe = False +python_requires = >=3.8 +include_package_data = True +packages = find: +platforms = any +install_requires = + aiohttp==3.7.4.post0 + iso8601==0.1.16 + trafaret==2.1.0 + neuro-auth-client==21.9.13.1 + cryptography==35.0.0 + aiorwlock==1.1.0 + neuro-notifications-client==21.9.11.1 + neuro-logging==21.9 + aiohttp-cors==0.7.0 + aiozipkin==1.1.0 + asyncpg==0.24.0 + sqlalchemy==1.3.23 + asyncpgsa==0.27.1 + alembic==1.7.4 + psycopg2-binary==2.9.1 + sentry-sdk==1.4.3 + typing-extensions==3.10.0.2 + neuro-admin-client==21.9.10 + +[bdist_wheel] +universal = 1 + +[options.entry_points] +console_scripts = + platform-api = platform_api.api:main + platform-api-poller = platform_api.poller_main:main + +[options.extras_require] +dev = + black==21.9b0 + flake8==4.0.1 + flake8-isort==4.1.1 + isort==5.9.3 + mypy==0.910 + pre-commit==2.15.0 + types-setuptools==57.4.0 + aiodocker==0.21.0 + codecov==2.1.12 + pytest==6.2.5 + pytest-asyncio==0.15.1 + pytest-cov==3.0.0 + requests==2.26.0 + [flake8] ignore = E203,W503 max-line-length = 88 diff --git a/setup.py b/setup.py deleted file mode 100644 index e845ab71d..000000000 --- a/setup.py +++ /dev/null @@ -1,46 +0,0 @@ -from setuptools import find_packages, setup - - -setup_requires = ("setuptools_scm",) - -install_requires = ( - "aiohttp==3.7.4.post0", - "iso8601==0.1.16", - "trafaret==2.1.0", - "neuro-auth-client==21.9.13.1", - # Circle CI fails on the latest cryptography version - # because the server has too old OpenSSL version - "cryptography==35.0.0", - "aiorwlock==1.1.0", - "neuro-notifications-client==21.9.11.1", - "neuro-logging==21.9", - "aiohttp-cors==0.7.0", - "aiozipkin==1.1.0", - "asyncpg==0.24.0", - "sqlalchemy==1.4.25", - "asyncpgsa==0.27.1", - "alembic==1.7.4", - "psycopg2-binary==2.9.1", - "sentry-sdk==1.4.3", - "typing-extensions==3.10.0.2", - "neuro-admin-client==21.9.10", -) - -setup( - name="platform-api", - url="https://github.com/neuro-inc/platform-api", - use_scm_version={ - "git_describe_command": "git describe --dirty --tags --long --match v*.*.*", - }, - packages=find_packages(), - python_requires=">=3.8.0", - setup_requires=setup_requires, - install_requires=install_requires, - entry_points={ - "console_scripts": [ - "platform-api=platform_api.api:main", - "platform-api-poller=platform_api.poller_main:main", - ] - }, - zip_safe=False, -)