From 077d78d0c22e0821545be77b9e2fb42464187028 Mon Sep 17 00:00:00 2001 From: Oliver Woolland Date: Wed, 12 Jun 2024 10:01:28 +0100 Subject: [PATCH 1/5] Add help module --- workflowhub_graph/help.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 workflowhub_graph/help.py diff --git a/workflowhub_graph/help.py b/workflowhub_graph/help.py new file mode 100644 index 0000000..3d30a52 --- /dev/null +++ b/workflowhub_graph/help.py @@ -0,0 +1,22 @@ +import argparse + +def main(): + parser = argparse.ArgumentParser( + description="Provide help and examples for the workflowhub graph builder." + ) + args = parser.parse_args() + + # Print a list of poetry scripts + print( + """ + The following commands are available: + + - 'source-crates': Download ROCrates from the WorkflowHub API. + - 'absolutize': Make all paths in an ROCrate absolute. + - 'upload': Upload an ROCrate to Zenodo. + - 'merge': Merge multiple ROCrates into an RDF graph. + """ + ) + +if __name__ == "__main__": + main() From e0ef0039f27904ee0143f701f7b49ad09bf53a05 Mon Sep 17 00:00:00 2001 From: Oliver Woolland Date: Wed, 12 Jun 2024 10:01:43 +0100 Subject: [PATCH 2/5] Refactor script names for ease --- pyproject.toml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index d02aa68..b693b8b 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -18,10 +18,11 @@ certifi = "^2024.2.2" pytest = ">=8.2.1" [tool.poetry.scripts] -workflowhub-graph-source-crates = "workflowhub_graph.source_crates:main" -workflowhub-graph-absolutize = "workflowhub_graph.absolutize:main" -workflowhub-graph-merge = "workflowhub_graph.merge:main" -workflowhub-graph-upload = "workflowhub_graph.upload:main" +source-crates = "workflowhub_graph.source_crates:main" +absolutize = "workflowhub_graph.absolutize:main" +merge = "workflowhub_graph.merge:main" +upload = "workflowhub_graph.upload:main" +help = "workflowhub_graph.help:main" [tool.poetry.group.dev.dependencies] pytest = ">=8.2.1" From 8ea414317e3e59c298d0527edf0059a851888202 Mon Sep 17 00:00:00 2001 From: Oliver Woolland Date: Wed, 12 Jun 2024 10:01:59 +0100 Subject: [PATCH 3/5] Create dockerfile for running poetry scripts --- Dockerfile | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e3ad270 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,25 @@ +# Docker container with poetry for python package management + +FROM python:3.10-slim + +# Install poetry +RUN pip install poetry + +# Set the working directory +WORKDIR /app + +# Copy the pyproject.toml +COPY pyproject.toml /app/ + +# Install the dependencies +RUN poetry install --no-root + +# Copy the rest of the files +COPY . /app + +# Install the package +RUN poetry install + +# Run the application +CMD ["help"] +ENTRYPOINT ["poetry", "run"] From 98e364e27c45327bbda586ccbd230e6bb3770bb8 Mon Sep 17 00:00:00 2001 From: Oliver Woolland Date: Wed, 12 Jun 2024 10:02:14 +0100 Subject: [PATCH 4/5] Update README with getting started guide --- README.md | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/README.md b/README.md index 029fd2b..f253ba7 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,38 @@ # WorkflowHub Knowledge Graph +## Getting started + +### Obtaining workflowhub-graph + +workflowhub-graph is available packaged as a Docker container. You can pull the latest version of the container by running: + +```bash +docker pull ghcr.io/uomresearchit/workflowhub-graph:latest +``` + +This provides the a wrapper for the executable `workflowhub-graph` which can be used to run the various tools provided by the package. + +### Running workflowhub-graph + +There are several tools provided by the `workflowhub-graph` package. These are: +- 'help': Display help information. +- 'source-crates': Download ROCrates from the WorkflowHub API. +- 'absolutize': Make all paths in an ROCrate absolute. +- 'upload': Upload an ROCrate to Zenodo. +- 'merge': Merge multiple ROCrates into an RDF graph. + +To run any of these tools, you can use the following command: + +```bash +docker run ghcr.io/uomresearchit/workflowhub-graph:latest +``` + +For example, to download ROCrates from the WorkflowHub API, you can run: + +```bash +docker run ghcr.io/uomresearchit/workflowhub-graph:latest source-crates +``` + ## Contributing ### Coding Style From eaabb8271c6568df2a77b5d67031f9f7738cdbba Mon Sep 17 00:00:00 2001 From: Oliver Woolland Date: Wed, 12 Jun 2024 10:27:59 +0100 Subject: [PATCH 5/5] Add workflow to build and push docker container --- .github/workflows/push-docker.yaml | 90 ++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 .github/workflows/push-docker.yaml diff --git a/.github/workflows/push-docker.yaml b/.github/workflows/push-docker.yaml new file mode 100644 index 0000000..83e3fe8 --- /dev/null +++ b/.github/workflows/push-docker.yaml @@ -0,0 +1,90 @@ +name: Docker + +on: + push: + branches: [ "develop" ] + # Publish semver tags as releases. + tags: [ 'v*.*.*' ] + pull_request: + branches: [ "develop" ] + workflow_dispatch: + +env: + REGISTRY: ghcr.io + ACTOR: OliverWoolland + IMAGE_NAME: ghcr.io/uomresearchit/workflowhub-graph + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + # This is used to complete the identity challenge + # with sigstore/fulcio when running outside of PRs. + id-token: write + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + # Install the cosign tool except on PR + # https://github.com/sigstore/cosign-installer + - name: Install cosign + if: github.event_name != 'pull_request' + uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 #v3.5.0 + with: + cosign-release: 'v2.2.4' + + # Set up BuildKit Docker container builder to be able to build + # multi-platform images and export cache + # https://github.com/docker/setup-buildx-action + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0 + + # Login against a Docker registry except on PR + # https://github.com/docker/login-action + - name: Log into registry ${{ env.REGISTRY }} + if: github.event_name != 'pull_request' + uses: docker/login-action@343f7c4344506bcbf9b4de18042ae17996df046d # v3.0.0 + with: + registry: ${{ env.REGISTRY }} + username: ${{ env.ACTOR }} + password: ${{ secrets.GITHUB_TOKEN }} + + # Extract metadata (tags, labels) for Docker + # https://github.com/docker/metadata-action + - name: Extract Docker metadata + id: meta + uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0 + with: + images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + # Build and push Docker image with Buildx (don't push on PR) + # https://github.com/docker/build-push-action + - name: Build and push Docker image + id: build-and-push + uses: docker/build-push-action@0565240e2d4ab88bba5387d719585280857ece09 # v5.0.0 + with: + context: . + push: ${{ github.event_name != 'pull_request' }} + tags: ${{ steps.meta.outputs.tags }} + labels: ${{ steps.meta.outputs.labels }} + cache-from: type=gha + cache-to: type=gha,mode=max + + # Sign the resulting Docker image digest except on PRs. + # This will only write to the public Rekor transparency log when the Docker + # repository is public to avoid leaking data. If you would like to publish + # transparency data even for private images, pass --force to cosign below. + # https://github.com/sigstore/cosign + - name: Sign the published Docker image + if: ${{ github.event_name != 'pull_request' }} + env: + # https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable + TAGS: ${{ steps.meta.outputs.tags }} + DIGEST: ${{ steps.build-and-push.outputs.digest }} + # This step uses the identity token to provision an ephemeral certificate + # against the sigstore community Fulcio instance. + run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}