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

Addresses issue #172 introducing hatch and pyproject.toml #177

Merged
merged 33 commits into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
19a414e
WIP hatch
fabricebrito Aug 30, 2024
d9340c2
removes old files
fabricebrito Aug 30, 2024
f624c19
CI WIP
fabricebrito Aug 30, 2024
93cefa0
CI WIP
fabricebrito Aug 30, 2024
af0e01c
CI WIP
fabricebrito Aug 30, 2024
c95a033
CI WIP
fabricebrito Aug 30, 2024
6a674f9
CI WIP
fabricebrito Aug 30, 2024
f2c110b
fixes tests in CI
fabricebrito Aug 30, 2024
544be85
CI
fabricebrito Aug 30, 2024
9c625d7
updates cwltool to 3.1.20240708091337
fabricebrito Aug 30, 2024
0fc174b
CI package WIP
fabricebrito Aug 30, 2024
d3c4a1e
CI temporary
fabricebrito Aug 30, 2024
28c99c2
CI temp package
fabricebrito Aug 30, 2024
4937183
test pypi
fabricebrito Aug 31, 2024
b9e8bd0
adds updates pyproject.toml
fabricebrito Sep 2, 2024
9940976
updates pyproject.toml
fabricebrito Sep 2, 2024
8f2e312
enhances README
fabricebrito Sep 2, 2024
b7fd240
adds docs env and script
fabricebrito Sep 2, 2024
cb27e13
removes scripts
fabricebrito Sep 2, 2024
7f8d6cd
updates gitignore
fabricebrito Sep 2, 2024
1c321dc
fixes environment console
fabricebrito Sep 2, 2024
5660d9a
adds dockerfile based on rockylinux and attemps to pin setuptools to …
fabricebrito Sep 2, 2024
f70ab5d
adds dependencies and updates CI
fabricebrito Sep 26, 2024
205175a
bumpds version for CI/pypi test
fabricebrito Sep 26, 2024
0b30a2f
fixes on condition for CI
fabricebrito Sep 26, 2024
3e0540d
empty commit
emmanuelmathot Dec 13, 2024
2ab0db4
simplifies workflow triggers for build and test actions
emmanuelmathot Dec 13, 2024
14c8c0d
Updates changelog
fabricebrito Dec 13, 2024
5394bee
Merge branch 'calrissian-172' of https://github.com/fabricebrito/calr…
fabricebrito Dec 13, 2024
baaebfd
Merge branch 'master' into calrissian-172
emmanuelmathot Dec 13, 2024
6dbbb67
Updates change log
fabricebrito Dec 13, 2024
394db0b
Merge branch 'calrissian-172' of https://github.com/fabricebrito/calr…
fabricebrito Dec 13, 2024
98af45d
sets version 0.18.0
fabricebrito Dec 13, 2024
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
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
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.17.4"
Loading
Loading