Skip to content

Commit cd34ee9

Browse files
authored
Merge pull request #186 from eScienceLab/refactor-production-readiness
Production-readiness refactor: drop MinIO, make Crate IDs more robust, add async validation and offline cache
2 parents 3ad955b + 6f4c389 commit cd34ee9

63 files changed

Lines changed: 3564 additions & 3481 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/build-with-profiles.yml

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,38 @@ jobs:
1919
id-token: write
2020
steps:
2121
- name: Checkout repository
22-
uses: actions/checkout@v4
22+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
2323

2424
- name: Log in to the Container registry
25-
uses: docker/login-action@v3
25+
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
2626
with:
2727
registry: ${{ env.REGISTRY }}
2828
username: ${{ github.actor }}
2929
password: ${{ secrets.GITHUB_TOKEN }}
3030

3131
- name: Extract metadata (tags, labels) for Docker
3232
id: meta
33-
uses: docker/metadata-action@v5
33+
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
3434
with:
3535
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
3636

3737
- name: Build and push Docker image
3838
id: push
39-
uses: docker/build-push-action@v6
39+
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
4040
with:
4141
context: .
42-
file: ./Dockerfile.fivesafes-profile
4342
push: true
43+
# Add the five-safes profile (via EXTRA_PROFILES_PATH) and warm its
44+
# cache, using the shared Dockerfile's build args.
45+
build-args: |
46+
FIVE_SAFES_PROFILE_VERSION=five-safes-0.7.4-beta
47+
PROFILES_ARCHIVE_URL=https://github.com/eScienceLab/rocrate-validator/archive/refs/tags/five-safes-0.7.4-beta.tar.gz
48+
EXTRA_PROFILES_PATH=/app/extra-profiles
4449
tags: ${{ steps.meta.outputs.tags }}
4550
labels: ${{ steps.meta.outputs.labels }}
4651

4752
- name: Generate artifact attestation
48-
uses: actions/attest-build-provenance@v2
53+
uses: actions/attest-build-provenance@e8998f949152b193b063cb0ec769d69d929409be # v2.4.0
4954
with:
5055
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
5156
subject-digest: ${{ steps.push.outputs.digest }}

.github/workflows/build.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,33 +21,33 @@ jobs:
2121
id-token: write
2222
steps:
2323
- name: Checkout repository
24-
uses: actions/checkout@v4
24+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
2525
- name: Log in to the Container registry
26-
uses: docker/login-action@v3
26+
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
2727
with:
2828
registry: ${{ env.REGISTRY }}
2929
username: ${{ github.actor }}
3030
password: ${{ secrets.GITHUB_TOKEN }}
3131
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
3232
- name: Extract metadata (tags, labels) for Docker
3333
id: meta
34-
uses: docker/metadata-action@v5
34+
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
3535
with:
3636
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
3737
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
3838
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see [Usage](https://github.com/docker/build-push-action#usage) in the README of the `docker/build-push-action` repository.
3939
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.
4040
- name: Build and push Docker image
4141
id: push
42-
uses: docker/build-push-action@v6
42+
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
4343
with:
4444
context: .
4545
push: true
4646
tags: ${{ steps.meta.outputs.tags }}
4747
labels: ${{ steps.meta.outputs.labels }}
4848
# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see [Using artifact attestations to establish provenance for builds](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds).
4949
- name: Generate artifact attestation
50-
uses: actions/attest-build-provenance@v2
50+
uses: actions/attest-build-provenance@e8998f949152b193b063cb0ec769d69d929409be # v2.4.0
5151
with:
5252
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME}}
5353
subject-digest: ${{ steps.push.outputs.digest }}

.github/workflows/lint.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Lint
2+
3+
on:
4+
pull_request:
5+
branches: [ develop ]
6+
7+
jobs:
8+
ruff:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
14+
15+
- name: Set up Python
16+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
17+
with:
18+
python-version: '3.11'
19+
20+
- name: Install ruff
21+
run: |
22+
python -m pip install --upgrade pip
23+
# Keep in sync with requirements-dev.txt
24+
pip install ruff==0.15.17
25+
26+
- name: Lint
27+
run: ruff check .
28+
29+
- name: Format check
30+
run: ruff format --check .

.github/workflows/test_docker.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,26 @@ jobs:
1010

1111
steps:
1212
- name: Checkout code
13-
uses: actions/checkout@v4
13+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
1414

1515
- name: Set up Python
16-
uses: actions/setup-python@v5
16+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
1717
with:
1818
python-version: '3.11'
1919

2020
- name: Install dependencies
2121
run: |
2222
python -m pip install --upgrade pip
23-
pip install pytest requests minio docker
23+
# Keep in sync with requirements-dev.txt
24+
pip install pytest==9.1.0 requests==2.33.1 boto3==1.43.29
2425
25-
- name: Build Docker Compose Containers
26+
- name: Run integration tests (brings up the compose stack)
2627
run: |
2728
cp example.env .env
28-
docker compose -f docker-compose-develop.yml build
29+
pytest -s -v tests/test_integration.py
2930
30-
- name: Spin Up Docker Compose and Run Tests
31-
run: pytest -s -v tests/test_integration.py
32-
33-
- name: Ensure that Docker Compose is Shutdown
31+
- name: Ensure Docker Compose is shut down
3432
if: always()
35-
run: docker compose down
33+
run: >
34+
docker compose -f docker-compose-develop.yml -p cratey_integration
35+
--profile objectstore down -v || true

.github/workflows/unit_tests.yml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,17 @@ jobs:
1010

1111
steps:
1212
- name: Checkout code
13-
uses: actions/checkout@v4
13+
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
1414

1515
- name: Set up Python
16-
uses: actions/setup-python@v5
16+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
1717
with:
1818
python-version: '3.11'
1919

2020
- name: Install dependencies
2121
run: |
2222
python -m pip install --upgrade pip
23-
pip install -r requirements.txt
24-
pip install pytest pytest-mock
23+
pip install -r requirements-dev.txt
2524
2625
- name: Run tests (excluding integration tests)
2726
run: |

Dockerfile

Lines changed: 41 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,53 @@
1+
# syntax=docker/dockerfile:1
12
FROM python:3.11-slim
23

3-
# Install required system packages, including git
4-
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
4+
# git is needed by some dependencies; wget is only used when baking a profile.
5+
RUN apt-get update && apt-get install -y git wget && rm -rf /var/lib/apt/lists/*
56

67
WORKDIR /app
78

89
COPY requirements.txt .
910
RUN pip install --upgrade pip
1011
RUN pip install --no-cache-dir -r requirements.txt
1112

12-
COPY cratey.py LICENSE /app/
13+
COPY wsgi.py LICENSE /app/
1314
COPY app /app/app
1415

16+
# Optionally fetch an extra RO-Crate profile into a normal directory. It is
17+
# *added* to the bundled profiles at runtime via EXTRA_PROFILES_PATH.
18+
# A plain build leaves PROFILES_ARCHIVE_URL empty
19+
# and skips this; the "with profiles" image build passes it as --build-arg.
20+
ARG PROFILES_ARCHIVE_URL=""
21+
ARG FIVE_SAFES_PROFILE_VERSION=""
22+
# Set EXTRA_PROFILES_PATH only for the profiles build (passed as a build arg).
23+
ARG EXTRA_PROFILES_PATH=""
24+
ENV EXTRA_PROFILES_PATH=${EXTRA_PROFILES_PATH}
25+
ENV CACHE_PATH=/app/.rocrate-cache
26+
RUN <<EOF_PROFILES
27+
set -e
28+
if [ -n "$PROFILES_ARCHIVE_URL" ]; then
29+
mkdir -p /app/extra-profiles
30+
wget -O /tmp/profiles.tar.gz "$PROFILES_ARCHIVE_URL"
31+
tar -xzf /tmp/profiles.tar.gz \
32+
-C /app/extra-profiles \
33+
--strip-components=3 \
34+
"rocrate-validator-${FIVE_SAFES_PROFILE_VERSION}/rocrate_validator/profiles/five-safes-crate"
35+
rm /tmp/profiles.tar.gz
36+
fi
37+
EOF_PROFILES
38+
39+
# Pre-populate the HTTP cache so opt-in offline validation
40+
# (VALIDATION_OFFLINE=true) works without network at runtime.
41+
RUN <<EOF_CACHE_WARM
42+
set -e
43+
if [ -n "$EXTRA_PROFILES_PATH" ]; then
44+
rocrate-validator cache warm --all-profiles \
45+
--extra-profiles-path "$EXTRA_PROFILES_PATH" --cache-path "$CACHE_PATH"
46+
else
47+
rocrate-validator cache warm --all-profiles --cache-path "$CACHE_PATH"
48+
fi
49+
EOF_CACHE_WARM
50+
1551
RUN useradd -ms /bin/bash flaskuser
1652
RUN chown -R flaskuser:flaskuser /app
1753

@@ -21,4 +57,5 @@ EXPOSE 5000
2157

2258
CMD ["flask", "run", "--host=0.0.0.0"]
2359

24-
LABEL org.opencontainers.image.source="https://github.com/eScienceLab/Cratey-Validator"
60+
LABEL org.opencontainers.image.source="https://github.com/eScienceLab/RO-Crate-Validation-Service"
61+
LABEL org.ro-crate-validation-service.five-safes-profile-version="${FIVE_SAFES_PROFILE_VERSION}"

Dockerfile.fivesafes-profile

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)