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

Docker related updates #159

Merged
merged 25 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
42f958d
auto sync & publish upstream release (#2)
rmfranken Mar 24, 2023
09e93ff
Update readme for 1.4.2
rmfranken Mar 27, 2023
ad6e45f
Fixing deprecated automatic release action
supermaxiste Mar 31, 2023
80ccb36
Fixed container image name (#4)
supermaxiste Apr 6, 2023
ceb375e
doc: fix typos in readme
cmdoret Apr 6, 2023
b8973a6
Merge pull request #3 from SDSC-ORD/fix-release
cmdoret Apr 24, 2023
e3d689b
Switched to alpine to minimize image size
Aug 21, 2023
8d327de
Cyril's advice and Jena approach
Aug 21, 2023
1045d0d
Merge pull request #5 from SDSC-ORD/container-opt
supermaxiste Aug 23, 2023
b2a3212
fix: multi-architecture container build (#6)
supermaxiste Aug 31, 2023
a98f2f2
Fixed base image for arm
supermaxiste Sep 5, 2023
4602c17
Merge pull request #7 from SDSC-ORD/fix_arm
supermaxiste Sep 5, 2023
388abda
fix: multiarch Github action to have both x86 and arm64
supermaxiste Sep 21, 2023
433757c
Merge pull request #8 from SDSC-ORD/docker_os
supermaxiste Sep 22, 2023
fe697f9
Adding Docker manifest build
supermaxiste Sep 25, 2023
c4598d1
Merge pull request #9 from SDSC-ORD/docker_os
supermaxiste Oct 17, 2023
ac4f167
Update docker-image.yml
supermaxiste Oct 17, 2023
41a3f08
Fix docker-image.yml
supermaxiste Oct 17, 2023
31fe19e
Remove tags for docker building
supermaxiste Oct 17, 2023
d359599
Lowercase repository
supermaxiste Oct 17, 2023
9b0e852
Add lowercase image name to merge
supermaxiste Oct 17, 2023
5eb8f7d
Add version to Docker image
supermaxiste Oct 17, 2023
6cbf667
fix checkout
supermaxiste Oct 17, 2023
ea687b2
remove sdsc from readme
rmfranken Nov 20, 2023
e4e6fd1
Prepare PR for TQ (#10)
rmfranken Nov 27, 2023
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
11 changes: 5 additions & 6 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
FROM eclipse-temurin:11 as jre-build
ARG ARCH_BASE
FROM $ARCH_BASE as jre-build

WORKDIR /app

ARG VERSION
Expand All @@ -21,9 +23,7 @@ RUN $JAVA_HOME/bin/jlink \
--compress=2 \
--output /javaruntime

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

# Compile with maven, extract binaries and copy into image
COPY . /app
Expand All @@ -32,7 +32,7 @@ RUN unzip target/shacl-${VERSION}-bin.zip -d /app/

# BUILD STAGE 2: keep only Java and SHACL

FROM ubuntu:jammy
FROM alpine:3.18

ARG VERSION

Expand All @@ -42,5 +42,4 @@ 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 --from=jre-build "/app/.docker/entrypoint.sh" "/entrypoint.sh"

ENTRYPOINT ["/entrypoint.sh"]
4 changes: 2 additions & 2 deletions .docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh

set -e

Expand Down Expand Up @@ -27,4 +27,4 @@ EOF
exit 1
fi

exec "$@"
exec "$@"
10 changes: 10 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# By default, normalize line endings
* text=auto

# Force microsofty files to use CRLF
*.{cmd,[cC][mM][dD]} text eol=crlf
*.{bat,[bB][aA][tT]} text eol=crlf
*.{reg,[rR][eE][gG]} text eol=crlf

# Force Unix bash files to use LF
*.sh text eol=lf
97 changes: 91 additions & 6 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,26 @@ on:

env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
matrix:
include:
- platform: linux/amd64
base: eclipse-temurin:11-alpine
- platform: linux/arm64
base: amazoncorretto:11-alpine3.18-jdk

steps:
- name: lowercase image name
run: |
echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV}

- name: Checkout repository
uses: actions/checkout@v3

Expand Down Expand Up @@ -62,13 +72,88 @@ jobs:
password: ${{ secrets.GITHUB_TOKEN }}

# https://github.com/docker/build-push-action
- name: Build and push Docker image
- name: Build and push Docker image for x86 and arm64
id: build
uses: docker/build-push-action@3b5e8027fcad23fda98b2e3ac259d8d67585f671 #v4.0.0
with:
file: .docker/Dockerfile
push: true
platforms: linux/amd64,linux/arm64
tags: ${{ steps.meta.outputs.tags }}
platforms: ${{ matrix.platform }}
labels: ${{ steps.meta.outputs.labels }}
build-args: VERSION=${{ steps.get_version.outputs.version_build }}
outputs: type=image
build-args: |
VERSION=${{ steps.get_version.outputs.version_build }}
ARCH_BASE=${{ matrix.base }}
outputs: type=image,name=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }},push-by-digest=true,name-canonical=true,push=true

# https://github.com/actions/upload-artifact
- name: Export digest
run: |
mkdir -p /tmp/digests
digest="${{ steps.build.outputs.digest }}"
touch "/tmp/digests/${digest#sha256:}"
- name: Upload digest
uses: actions/upload-artifact@v3
with:
name: digests
path: /tmp/digests/*
if-no-files-found: error
retention-days: 1

merge:
runs-on: ubuntu-latest
needs:
- build-and-push-image
steps:
- name: lowercase image name
run: |
echo "IMAGE_NAME=${GITHUB_REPOSITORY,,}" >> ${GITHUB_ENV}

- name: Checkout repository
uses: actions/checkout@v3

# inspired by https://github.com/reloc8/action-latest-release-version
- name: Get release version
id: get_version
run: |
git fetch --tags
git fetch --prune --unshallow || true

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/actions/download-artifact
- name: Download digests
uses: actions/download-artifact@v3
with:
name: digests
path: /tmp/digests
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

# 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
uses: docker/login-action@f4ef78c080cd8ba55a85445d5b36e214a81df20a # v2.1.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Create manifest list and push
working-directory: /tmp/digests
run: |
docker buildx imagetools create $(jq -cr '.tags | map("-t " + .) | join(" ")' <<< "$DOCKER_METADATA_OUTPUT_JSON") \
$(printf '${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}@sha256:%s ' *)
- name: Inspect image
run: |
docker buildx imagetools inspect ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.meta.outputs.version }}
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Releases are available in the central maven repository:
<version>*VER*</version>
</dependency>
```

## Command Line Usage

Download the latest release from:
Expand All @@ -58,15 +59,15 @@ To use them, set up your environment similar to https://jena.apache.org/document
For example, on Windows:

```
SET SHACLROOT=C:\Users\Holger\Desktop\shacl-1.4.1-bin
SET SHACLROOT=C:\Users\Holger\Desktop\shacl-1.4.2-bin
SET PATH=%PATH%;%SHACLROOT%\bin
```

As another example, for Linux, add to .bashrc these lines:

```
# for shacl
export SHACLROOT=/home/holger/shacl/shacl-1.4.1-bin/shacl-1.4.1/bin
export SHACLROOT=/home/holger/shacl/shacl-1.4.2-bin/shacl-1.4.2/bin
export PATH=$SHACLROOT:$PATH
```

Expand All @@ -83,11 +84,12 @@ The tools print the validation report or the inferences graph to the output scre

## Dockerfile Usage

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:
The `Dockerfile` in the `.docker` folder includes a minimal Java Runtime Environment for the SHACL API that clocks in at ~85Mb. To get the latest release of the image use:

```
docker build -f .docker/Dockerfile -t ghcr.io/topquadrant/shacl:1.4.2 --build-arg VERSION=1.4.2 .
```
> :warning: It is generally better to use a fixed version of the docker image, rather than the `latest` tag. Consult the package page to find what versions are available.

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

Expand Down Expand Up @@ -117,3 +119,15 @@ PARAMETERS:
-shapesfile /data/myshapes.ttl [OPTIONAL]
shapes for validation (only .ttl format supported)
```

If you'd like to build the image locally in an `x86` architecture, use:

```
docker build -f .docker/Dockerfile -t ghcr.io/topquadrant/shacl:1.4.2 --build-arg VERSION=1.4.2 --build-arg ARCH_BASE=eclipse-temurin:11-alpine .
```

If your architecture is `arm`, use:

```
docker build -f .docker/Dockerfile -t ghcr.io/topquadrant/shacl:1.4.2 --build-arg VERSION=1.4.2 --build-arg ARCH_BASE=amd64/eclipse-temurin:11-alpine .
```