From 8809fefd0b63cf9fa8bb3f7b4b07c0d6c004c917 Mon Sep 17 00:00:00 2001 From: Stefan Peters Date: Wed, 21 Feb 2024 13:43:54 +0100 Subject: [PATCH] Add first iteration of Docker image to build vocabularies https://github.com/gbv/coli-conc-server/issues/1 --- .docker/Dockerfile | 33 ++++++++++++++++++++++++ .docker/README.md | 43 +++++++++++++++++++++++++++++++ .docker/docker-compose.yml | 10 ++++++++ .docker/entrypoint.sh | 31 +++++++++++++++++++++++ .github/workflows/docker.yml | 49 ++++++++++++++++++++++++++++++++++++ .gitignore | 1 + 6 files changed, 167 insertions(+) create mode 100644 .docker/Dockerfile create mode 100644 .docker/README.md create mode 100644 .docker/docker-compose.yml create mode 100644 .docker/entrypoint.sh create mode 100644 .github/workflows/docker.yml diff --git a/.docker/Dockerfile b/.docker/Dockerfile new file mode 100644 index 0000000..156252d --- /dev/null +++ b/.docker/Dockerfile @@ -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"] diff --git a/.docker/README.md b/.docker/README.md new file mode 100644 index 0000000..bf42455 --- /dev/null +++ b/.docker/README.md @@ -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. diff --git a/.docker/docker-compose.yml b/.docker/docker-compose.yml new file mode 100644 index 0000000..2fd0d10 --- /dev/null +++ b/.docker/docker-compose.yml @@ -0,0 +1,10 @@ +version: "3" +services: + + jskos-data: + build: + context: .. + dockerfile: .docker/Dockerfile + volumes: + - ./data:/jskos-data + restart: no diff --git a/.docker/entrypoint.sh b/.docker/entrypoint.sh new file mode 100644 index 0000000..4fb9efe --- /dev/null +++ b/.docker/entrypoint.sh @@ -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 + diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 0000000..c346e7b --- /dev/null +++ b/.github/workflows/docker.yml @@ -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 }} diff --git a/.gitignore b/.gitignore index 8b8ffce..b7b2ae8 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ skos2jskos/*.jsonld vendor/ composer.lock node_modules/ +.docker/data