Skip to content

Commit

Permalink
Merge pull request #177 from fabricebrito/calrissian-172
Browse files Browse the repository at this point in the history
Addresses issue #172 introducing hatch and pyproject.toml
  • Loading branch information
fabricebrito authored Dec 13, 2024
2 parents 4ee2108 + 98af45d commit 62093d9
Show file tree
Hide file tree
Showing 16 changed files with 328 additions and 324 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/build-and-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Build & Tests
on: [push, pull_request]

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: "3.10"
cache: "pip"
- name: Install dependencies
run: |
# python -m pip install --upgrade pip
pip install hatch
- name: Cache Hatch
id: cache-hatch
uses: actions/cache@v3
with:
path: /home/runner/.local/share/hatch/env/virtual/
key: ${{ runner.os }}-hatch
- name: Build
run: hatch build
- name: Test
run: |
hatch -e test run nose2 --verbose
27 changes: 0 additions & 27 deletions .github/workflows/build.yaml

This file was deleted.

80 changes: 30 additions & 50 deletions .github/workflows/package.yaml
Original file line number Diff line number Diff line change
@@ -1,65 +1,45 @@
name: package
name: Publish to PyPI

on:
release:
types: [created]

permissions:
contents: read

jobs:
deploy:

version:
runs-on: ubuntu-latest
outputs:
app-version: ${{ steps.set-version.outputs.version }}
steps:
- uses: actions/checkout@v4
- run: echo "APP_VERSION=$(python setup.py --version)" >> $GITHUB_ENV
- run: echo app version is $APP_VERSION
- id: set-version
run: echo "::set-output name=version::$APP_VERSION"

deploy:
runs-on: ubuntu-latest

environment: release
permissions:
id-token: write # IMPORTANT: this permission is mandatory for trusted publishing

steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10"
python-version: '3.10'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python3 -m venv venv
. venv/bin/activate
pip install setuptools wheel twine
pip install -r requirements.txt
- name: verify git tag vs. version
run: |
python3 -m venv venv
. venv/bin/activate
python setup.py verify
- name: Build
run: |
. venv/bin/activate
python setup.py bdist_wheel --universal
- name: Publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_APIKEY }}
run: |
. venv/bin/activate
twine upload dist/*
container-build:
needs: version
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- run: echo version ${{needs.version.outputs.app-version}}
- run: echo "${{ secrets.GITHUB_TOKEN }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin
- name: build & push image
run: |
IMAGE_ID=ghcr.io/duke-gcb/calrissian/calrissian
docker build . --file Dockerfile --tag calrissian
docker tag calrissian $IMAGE_ID:${{needs.version.outputs.app-version}}
docker push $IMAGE_ID:${{needs.version.outputs.app-version}}
# python -m pip install --upgrade pip
pip install hatch
- name: Build package
run: hatch build
- name: Test package
run: hatch -e test run nose2 --verbose
- name: Publish package distributions to Test PyPI
if: github.ref != 'refs/heads/main'
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
repository-url: https://test.pypi.org/legacy/
- name: Publish package distributions to PyPI
if: github.ref == 'refs/heads/main'
uses: pypa/gh-action-pypi-publish@release/v1
with:
skip-existing: true
repository-url: https://upload.pypi.org/legacy/
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ build
*.whl
*.zip
env-calrissian*
*.tar.gz
27 changes: 27 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,33 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [v0.18.0] - 2024-12-13

### Changes

- Drop setup.py and requirements.txt in favour of PEP 517 and 518 by @fabricebrito in https://github.com/Duke-GCB/calrissian/pull/177

## [v0.17.2] - 2024-05-02

### Changes

- calls `setup_kubernetes` before `_setup` to set `cudaDeviceCount` by @fabricebrito in https://github.com/Duke-GCB/calrissian/pull/170

## [v0.17.1] - 2024-05-02

### Changes

## [v0.17.0] - 2024-05-02

- broken release

### Changes

- Create codemeta.json by @fabricebrito in https://github.com/Duke-GCB/calrissian/pull/163
- Conformance 1.2.1 by @fabricebrito in https://github.com/Duke-GCB/calrissian/pull/164
- Update README.md by @fabricebrito in https://github.com/Duke-GCB/calrissian/pull/165
- adds `cudaVersionMin`, `cudaComputeCapability` in `CUDARequirement` by @fabricebrito in https://github.com/Duke-GCB/calrissian/pull/168

## [v0.16.0] - 2023-11-23

### Changes
Expand Down
62 changes: 48 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,56 @@
FROM python:3.10.0-slim-buster
LABEL maintainer="dan.leehr@duke.edu"
# Stage 1: Build stage
FROM rockylinux:9.3-minimal AS build

# cwltool requires nodejs
RUN apt-get update && apt-get install -y nodejs
# Install necessary build tools
RUN microdnf install -y curl tar

RUN mkdir -p /app
COPY . /app
RUN pip install /app
WORKDIR /app
# Download the hatch tar.gz file from GitHub
RUN curl -L https://github.com/pypa/hatch/releases/latest/download/hatch-x86_64-unknown-linux-gnu.tar.gz -o /tmp/hatch-x86_64-unknown-linux-gnu.tar.gz

# Extract the hatch binary
RUN tar -xzf /tmp/hatch-x86_64-unknown-linux-gnu.tar.gz -C /tmp/

# Stage 2: Final stage
FROM rockylinux:9.3-minimal

# Install runtime dependencies
RUN microdnf install -y --nodocs nodejs && \
microdnf clean all

# Create a default user and home directory
# Set up a default user and home directory
ENV HOME=/home/calrissian
# home dir is created by useradd with group (g=0) to comply with
# https://docs.openshift.com/container-platform/3.11/creating_images/guidelines.html#openshift-specific-guidelines

# Create a user with UID 1001, group root, and a home directory
RUN useradd -u 1001 -r -g 0 -m -d ${HOME} -s /sbin/nologin \
-c "Default Calrissian User" calrissian && \
chown -R 1001:0 /app && \
chmod g+rwx ${HOME}
-c "Default Calrissian User" calrissian && \
mkdir -p /app && \
mkdir -p /prod && \
chown -R 1001:0 /app && \
chmod g+rwx ${HOME} /app

# Copy the hatch binary from the build stage
COPY --from=build /tmp/hatch /usr/bin/hatch

# Ensure the hatch binary is executable
RUN chmod +x /usr/bin/hatch

# Switch to the non-root user
USER calrissian

# Copy the application files into the /app directory
COPY --chown=1001:0 . /tmp
WORKDIR /tmp

# Set up virtual environment paths
ENV VIRTUAL_ENV=/app/envs/calrissian
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

# Prune any existing environments and create a new production environment
RUN cd /tmp && hatch env prune && \
hatch env create prod && \
rm -fr /tmp/* /tmp/.git /tmp/.pytest_cache

WORKDIR /app

# Set the default command to run when the container starts
CMD ["calrissian"]
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,45 @@ When encountering a Kubernetes API exception, Calrissian uses a library to retry
- `RETRY_MIN`: Default `5`. Minimum interval between retries.
- `RETRY_MAX`: Default `1200`. Maximum interval between retries.
- `RETRY_ATTEMPTS`: Default `10`. Max number of retries before giving up.

## For developers

### Installing for Development

Note that for development you can just use [Hatch] directly as described below.

### Installing Hatch

The main tool that is used for development is [Hatch]. It manages dependencies (in a virtualenv that is created on the fly) and is also the command runner.

So first, [install it][install Hatch]. Ideally in an isolated way with **`pipx install hatch`** (after [installing `pipx`]), or just `pip install hatch` as a more well-known way.

### Running tests

```
hatch run test:test
```

Verbose:

```
hatch run test:testv
```

### Running test coverage

```
hatch run test:cov
```

### Running calrissian

```
hatch run calrissian
```

### Serve the documentation

```
hatch run docs:serve
```
1 change: 1 addition & 0 deletions calrissian/__about__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version="0.18.0"
Loading

0 comments on commit 62093d9

Please sign in to comment.