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

Fix and improve docker build action #151

Merged
merged 9 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 7 additions & 6 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@ RUN $JAVA_HOME/bin/jlink \
--output /javaruntime

RUN apt-get -y update && \
apt-get -y install curl zip && \
apt-get -y install maven curl zip && \
rm -rf /var/lib/apt/lists/*

# Download and unpack binary version for appropriate release
RUN curl -s https://repo1.maven.org/maven2/org/topbraid/shacl/${VERSION}/shacl-${VERSION}-bin.zip > shacl.zip
RUN unzip shacl.zip && rm shacl.zip
# Compile with maven, extract binaries and copy into image
COPY . /app
RUN mvn versions:set -DnewVersion=${VERSION} && mvn package -Dmaven.test.skip=true
RUN unzip target/shacl-${VERSION}-bin.zip -d /app/

# BUILD STAGE 2: keep only Java and SHACL

Expand All @@ -40,6 +41,6 @@ ENV PATH "/app/shacl-${VERSION}/bin:${PATH}"

COPY --from=jre-build /javaruntime $JAVA_HOME
COPY --chmod=0755 --from=jre-build /app/shacl-${VERSION} /app/shacl-${VERSION}
COPY --chmod=0755 "entrypoint.sh" "/entrypoint.sh"
COPY --chmod=0755 --from=jre-build "/app/.docker/entrypoint.sh" "/entrypoint.sh"

ENTRYPOINT ["/entrypoint.sh"]
ENTRYPOINT ["/entrypoint.sh"]
17 changes: 11 additions & 6 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name: Create and publish SHACL API Docker image
on:
release:
type: [published]
pull_request:
branches: [master]
push:
branches: [master]

Expand Down Expand Up @@ -38,15 +36,22 @@ jobs:
run: |
git fetch --tags
git fetch --prune --unshallow || true
LATEST_RELEASE=$(git describe --abbrev=0 --tags)

LATEST_RELEASE=$(git describe --abbrev=0 --tags | sed 's/^v//')
echo "latest-release=${LATEST_RELEASE}" >> $GITHUB_OUTPUT
echo "version_build=${LATEST_RELEASE}_"$(git rev-parse --short "$GITHUB_SHA") >> $GITHUB_OUTPUT

# https://github.com/docker/metadata-action
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@507c2f2dc502c992ad446e3d7a5dfbe311567a96 #v4.3.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ github.event_name == 'push' }}
type=raw,value=${{ steps.get_version.outputs.version_build}},enable=${{ github.event_name == 'push' }}
type=raw,value=${{ steps.get_version.outputs.latest-release}},enable=${{ github.event_name == 'release' }}


# https://github.com/docker/login-action
- name: Log in to the Container registry
Expand All @@ -60,10 +65,10 @@ jobs:
- name: Build and push Docker image
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 #v4.0.0
with:
context: .docker/
file: .docker/Dockerfile
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.get_version.outputs.latest-release }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: VERSION=${{ steps.get_version.outputs.latest-release }}
build-args: VERSION=${{ steps.get_version.outputs.version_build }}
outputs: type=image
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,26 +86,26 @@ The tools print the validation report or the inferences graph to the output scre
The `Dockerfile` in the `.docker` folder includes a minimal Java Runtime Environment for the SHACL API that clocks in at 144Mb. To build the docker image use:

```
docker build -t topquadrant/shacl:1.4.2 --build-arg VERSION=1.4.2 .docker/
docker build -f .docker/Dockerfile -t ghcr.io/topquadrant/shacl:1.4.2 --build-arg VERSION=1.4.2 .
```

To use the Docker image, there are two possible commands. To run the validator:

```
docker run --rm -v /path/to/data:/data topquadrant/shacl:1.4.2 validate -datafile /data/myfile.ttl -shapesfile /data/myshapes.ttl
docker run --rm -v /path/to/data:/data ghcr.io/topquadrant/shacl:1.4.2 validate -datafile /data/myfile.ttl -shapesfile /data/myshapes.ttl
```

To run rule inferencing:

```
docker run --rm -v /path/to/data:/data topquadrant/shacl:1.4.2 infer -datafile /data/myfile.ttl -shapesfile /data/myshapes.ttl
docker run --rm -v /path/to/data:/data ghcr.io/topquadrant/shacl:1.4.2 infer -datafile /data/myfile.ttl -shapesfile /data/myshapes.ttl
```

Any other command after `topquadrant/shacl:1.4.2` will print the following help page:
Any other command after `ghcr.io/topquadrant/shacl:1.4.2` will print the following help page:

```
Please use this docker image as follows:
docker run -v /path/to/data:/data topquadrant/shacl:1.4.2 [COMMAND] [PARAMETERS]
docker run -v /path/to/data:/data ghcr.io/topquadrant/shacl:1.4.2 [COMMAND] [PARAMETERS]
COMMAND:
validate
to run validation
Expand Down