Skip to content

Commit

Permalink
Merge pull request #22 from workflowhub-eu/feature-docker-container
Browse files Browse the repository at this point in the history
Feature docker container
  • Loading branch information
alexhambley authored Jun 12, 2024
2 parents 91533dd + eaabb82 commit 262e220
Show file tree
Hide file tree
Showing 5 changed files with 175 additions and 4 deletions.
90 changes: 90 additions & 0 deletions .github/workflows/push-docker.yaml
Original file line number Diff line number Diff line change
@@ -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}
25 changes: 25 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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 <tool> <args>
```

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
Expand Down
9 changes: 5 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
22 changes: 22 additions & 0 deletions workflowhub_graph/help.py
Original file line number Diff line number Diff line change
@@ -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()

0 comments on commit 262e220

Please sign in to comment.