Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
15 changes: 0 additions & 15 deletions .dockerignore

This file was deleted.

7 changes: 0 additions & 7 deletions .flake8

This file was deleted.

104 changes: 83 additions & 21 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,95 @@
name: Publish Python package
name: Build and publish the package to internal PDBe PyPi registry, DockerHub and GitLab Container Registry
permissions:
contents: read

on:
release:
types: [published]
workflow_dispatch:
pull_request:
branches:
- main
push:
branches:
- main
tags:
- "*"

permissions:
contents: read
id-token: write
env:
BASE_PYTHON_VERSION: &base_python_version "3.12"

jobs:
publish:
build:
name: Lint and Test (Python ${{ matrix.python-version }})
runs-on: ubuntu-latest
environment: pypi
strategy:
matrix:
python-version: [*base_python_version, "3.13", "3.14"]

steps:
- name: Check out repository
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
python-version: "3.11"

- name: Set up UV
uses: astral-sh/setup-uv@v5
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
uv sync --locked --group test
- name: Run pre-commit checks
uses: pre-commit/action@v3.0.1
if: matrix.python-version == env.BASE_PYTHON_VERSION
- name: Run Tests
run: |
uv run make test

- name: Build distributions
run: uv build
publish:
name: Publish
if: startsWith(github.ref, 'refs/tags/v')
needs: build
runs-on: ubuntu-latest
environment:
name: pypi
url: https://pypi.org/project/pdbe-shape-retrieval
permissions:
id-token: write # IMPORTANT: mandatory for trusted publishing

- name: Publish to PyPI
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
python-version: "${{ env.BASE_PYTHON_VERSION }}"
- name: Create distribution
run: |
uv build
- name: Publish to internal PyPi
run: |
pip install twine
TWINE_PASSWORD=${{ secrets.TWINE_PASSWORD }} TWINE_USERNAME=${{ secrets.TWINE_USERNAME }} python -m twine upload --repository-url ${{ secrets.PIP_INDEX_URL }} dist/*
- name: Publish to public PyPi
uses: pypa/gh-action-pypi-publish@release/v1

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Extract Docker tag from GitHub ref
run: echo "DOCKER_TAG=${GITHUB_REF_NAME#v}" >> $GITHUB_ENV
- name: Build and push
uses: docker/build-push-action@v6
with:
push: true
platforms: linux/amd64,linux/arm64/v8
tags: |
${{ secrets.DOCKER_USERNAME }}/pdbe-shape-retrieval:${{ env.DOCKER_TAG }}
${{ secrets.DOCKER_USERNAME }}/pdbe-shape-retrieval:latest
- name: Login to GitLab Container Registry
run: echo ${{ secrets.REGISTRY_PASSWORD }} | docker login -u ${{ secrets.REGISTRY_USERNAME }} --password-stdin ${{ vars.REGISTRY_URL }}
- name: Build and tag Docker image
run: docker build -t ${{ vars.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/packages/pdbe-shape-retrieval:latest -t ${{ vars.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/packages/pdbe-shape-retrieval:${{ env.DOCKER_TAG }} .
- name: Push Docker image to GitLab Container Registry
run: |
docker push ${{ vars.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/packages/pdbe-shape-retrieval:latest
docker push ${{ vars.REGISTRY_URL }}/${{ secrets.REGISTRY_USERNAME }}/packages/pdbe-shape-retrieval:${{ env.DOCKER_TAG }}
73 changes: 1 addition & 72 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
**/.vscode/
.idea/
Pipfile
# Vagrant
.vagrant/

# Mac/OSX
.DS_Store
Expand Down Expand Up @@ -40,16 +38,6 @@ wheels/
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
Expand All @@ -59,72 +47,13 @@ htmlcov/
.cache
nosetests.xml
coverage.xml
report.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json
.envrc


TODO
34 changes: 15 additions & 19 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
default_install_hook_types:
- pre-commit
- post-checkout
- post-merge
- post-rewrite

repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.1.0
rev: v6.0.0
hooks:
- id: check-yaml
- id: check-added-large-files
Expand All @@ -12,23 +18,13 @@ repos:
- id: fix-byte-order-marker
- id: end-of-file-fixer
- id: check-ast
- id: no-commit-to-branch
- repo: https://gitlab.com/pycqa/flake8
rev: 4.0.1
- repo: https://github.com/astral-sh/uv-pre-commit
rev: 0.11.28
hooks:
- id: flake8
additional_dependencies: [flake8-bugbear==21.4.3]
- repo: https://github.com/asottile/blacken-docs
rev: v1.12.0
- id: uv-lock
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.15.20
hooks:
- id: blacken-docs
additional_dependencies: [black==20.8b1]
- repo: https://github.com/pycqa/isort
rev: 5.10.1
hooks:
- id: isort
name: isort (python)
- repo: https://github.com/psf/black
rev: 21.12b0
hooks:
- id: black
- id: ruff-check
args: [ --fix ]
- id: ruff-format
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.12
50 changes: 35 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,23 +1,43 @@
FROM python:3.11-slim
# Inspired from https://github.com/astral-sh/uv-docker-example/blob/5748835918ec293d547bbe0e42df34e140aca1eb/multistage.Dockerfile
FROM ghcr.io/astral-sh/uv:python3.12-bookworm-slim AS builder

ENV PYTHONUNBUFFERED=1 \
PIP_NO_CACHE_DIR=1 \
MAP2ZERNIKE_SETUP_DIR=/usr/local/bin \
OBJ2GRID_PATH=/usr/local/bin/obj2grid \
PATH="/usr/local/bin:${PATH}"
ENV UV_COMPILE_BYTECODE=1 UV_LINK_MODE=copy

# Omit development dependencies
ENV UV_NO_DEV=1

ENV UV_PYTHON_DOWNLOADS=0

ARG PIP_INDEX_URL
ENV UV_DEFAULT_INDEX=$PIP_INDEX_URL
ENV UV_EXTRA_INDEX_URL=https://pypi.org/simple

WORKDIR /app
COPY pyproject.toml uv.lock /app/
RUN uv sync --locked --no-install-project --no-dev

COPY shape_retrieval /app/shape_retrieval
RUN uv tool install shape_retrieval

FROM python:3.12-slim-bookworm
LABEL maintainer="Sreenath Sasidharan Nair <sreenath@ebi.ac.uk>"

RUN apt-get update \
&& apt-get install -y --no-install-recommends libgl1 libglib2.0-0 libgomp1 \
&& rm -rf /var/lib/apt/lists/*
RUN groupadd --system --gid 101 nonroot \
&& useradd --system --gid 101 --uid 101 --create-home nonroot

RUN python -m pip install --upgrade pip uv
COPY --from=builder --chown=nonroot:nonroot /app /app

COPY . /app
ENV PATH="/app/.venv/bin:$PATH"

RUN install -m 0755 /app/bin/map2zernike /usr/local/bin/map2zernike \
&& install -m 0755 /app/bin/obj2grid /usr/local/bin/obj2grid \
&& uv pip install --system .
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

# Disable core dumps
RUN echo -e "* soft core 0\n* hard core 0" >> /etc/security/limits.conf

USER nonroot

# Set the working directory to /app
WORKDIR /app

ENTRYPOINT ["shape_retrieval"]
CMD ["shape_retrieval"]
1 change: 0 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ software distributed under the License is distributed on an
either express or implied. See the License for the specific
language governing permissions and limitations under the
License.

Loading
Loading