-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #177 from fabricebrito/calrissian-172
Addresses issue #172 introducing hatch and pyproject.toml
- Loading branch information
Showing
16 changed files
with
328 additions
and
324 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,4 @@ build | |
*.whl | ||
*.zip | ||
env-calrissian* | ||
*.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
version="0.18.0" |
Oops, something went wrong.