Skip to content

Commit

Permalink
Add first iteration of Docker image to build vocabularies
Browse files Browse the repository at this point in the history
  • Loading branch information
stefandesu committed Feb 21, 2024
1 parent 68912a8 commit 8809fef
Show file tree
Hide file tree
Showing 6 changed files with 167 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
FROM ubuntu:22.04
WORKDIR /usr/src/app

# Install dependencies
RUN apt update
RUN apt install -y curl wget bash git make jq

# Perl dependencies
RUN apt install -y perl build-essential librdf-query-perl librdf-query-client-perl libexpat1-dev libssl-dev zlib1g-dev
RUN yes | cpan App::cpanminus
# XML::Parser XML::SemanticDiff Test::XML XML::LibXML Catmandu::SRU
RUN cpanm -n App::skos2jskos Catmandu Catmandu::MARC Catmandu::Breaker Catmandu::Importer::SRU Catmandu::Importer::SRU::Parser::picaxml PICA::Data

# Python dependencies
RUN python3 python3-pip
RUN pip3 install --upgrade mc2skos namedentities

# Node.js via NodeSource (see https://github.com/nodesource/distributions/blob/master/README.md)
RUN curl -fsSL https://deb.nodesource.com/setup_20.x | bash
RUN apt install -y nodejs

# Deno
RUN curl -fsSL https://deno.land/install.sh | sh

# Dependencies for specific vocabularies
## nkostypes
RUN apt install -y raptor2-utils
RUN npm install -g wikibase-cli@latest

# Make Docker-related scripts available in root folder
COPY .docker/*.sh .

CMD ["bash", "entrypoint.sh"]
43 changes: 43 additions & 0 deletions .docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# jskos-data Docker

This container aims to offer all the tools and dependencies needed to build vocabularies in this repository. Work in progress.

## To-Dos
- [ ] Test all vocabularies
- [ ] Add script that updates repo and rebuilds vocabularies where files were changed
- [ ] Error with `nkostypes`
- [ ] Error with `ssg`
- [ ] `rvk`:
- [ ] Make sure it works with just `make`
- [ ] Install mc2skos from Git as described in README?

Create a `docker-compose.yml` file:

```yml
version: "3"
services:

jskos-data:
image: ghcr.io/gbv/jskos-data
volumes:
- ./data:/jskos-data
restart: no
```
Start the container:
```sh
docker compose up
```

The latest version of jskos-data will be pulled from GitHub.

To run an interactive shell:

```sh
docker compose run -it jskos-data bash
```

## Publishing the Docker Image

Currently, only the `master` branch will be published by the GitHub workflow, and only whenever Docker-related files (`Dockerfile`, `entrypoint.sh`) are changed.
10 changes: 10 additions & 0 deletions .docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "3"
services:

jskos-data:
build:
context: ..
dockerfile: .docker/Dockerfile
volumes:
- ./data:/jskos-data
restart: no
31 changes: 31 additions & 0 deletions .docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash

# Clone site if not yet done
if [ ! -e /jskos-data ]; then
git clone --depth 1 https://github.com/gbv/jskos-data /jskos-data
fi

cd /jskos-data
# TODO: Only when updated
if [ ! -e node_modules ]; then
npm ci
fi

node --version
npm --version
deno --version

# # Pull changes
# git pull

# if [ -e _site/.git-commit ] && [ "$(git rev-parse HEAD)" == "$(cat _site/.git-commit)" ]; then
# echo "Site rebuild skipped because there was no update."
# else
# # Might need to update dependencies after each pull
# npm ci
# # Build the site
# npm run build -- --pathprefix="$PATHPREFIX" --url="$URL"
# # Remember the current commit
# git rev-parse HEAD > _site/.git-commit
# fi

49 changes: 49 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Publish Docker
# Only run when Docker-related files are changed
on:
push:
branches:
- master
paths:
- .docker/Dockerfile
- .docker/entrypoint.sh

# Adapted from:
# - https://github.com/docker/metadata-action#semver
# - https://docs.github.com/en/actions/publishing-packages/publishing-docker-images#publishing-images-to-github-packages

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

jobs:
publish:
runs-on: ubuntu-latest
steps:
-
name: Checkout
uses: actions/checkout@v3
-
name: Docker Meta
id: meta
uses: docker/metadata-action@v4
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }}
-
name: Login to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
-
name: Build and Push
uses: docker/build-push-action@v4
with:
context: .
file: .docker/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ skos2jskos/*.jsonld
vendor/
composer.lock
node_modules/
.docker/data

0 comments on commit 8809fef

Please sign in to comment.