diff --git a/.github/workflows/docker.yml b/.github/workflows/docker.yml new file mode 100644 index 000000000..0b8a904fe --- /dev/null +++ b/.github/workflows/docker.yml @@ -0,0 +1,29 @@ +name: Publish Docker +on: [push] +jobs: + publish: + runs-on: ubuntu-latest + if: github.ref != 'refs/heads/master' + steps: + - uses: actions/checkout@master + - name: Publish to Registry + uses: elgohr/Publish-Docker-Github-Action@master + with: + name: coliconc/cocoda + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + dockerfile: docker/Dockerfile + tag_semver: true + publish-main: + runs-on: ubuntu-latest + if: github.ref == 'refs/heads/master' + steps: + - uses: actions/checkout@master + - name: Publish to Registry + uses: elgohr/Publish-Docker-Github-Action@master + with: + name: coliconc/cocoda + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + dockerfile: docker/Dockerfile + tags: latest diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4d5acd5c8..16320d5e3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -249,6 +249,8 @@ The user interface is currently available in English and German. To facilitate c **For maintainers only** +### New Release + Before creating a release, be aware of the following prerequisites: - You are on the dev branch and your working tree is clean. @@ -271,3 +273,11 @@ npm run release major After successfully creating a release, the script will show you some possible next steps. If there were any errors during the release, make sure to clean up your repository before trying again (reverting the version commit, etc.). + +### Docker + +Docker-related files are available in the `docker` folder. Images are published to Docker Hub via a GitHub Action (see `.github/workflows/docker.yml`). To make that work, `DOCKER_USERNAME` and `DOCKER_PASSWORD` must be set in GitHub under Settings -> Secrets. See [Publish Docker](https://github.com/marketplace/actions/publish-docker) for more details. + +The Docker Hub repository is https://hub.docker.com/repository/docker/coliconc/cocoda. [@stefandesu](https://github.com/stefandesu) currently maintains the organization. + +Due to restrictions in the Docker API, it is currently not possible to automatically set the Docker Hub description through a GitHub Action. Therefore, whenever `docker/README.md` is updated, the content must be manually copied and pasted into the Docker Hub description. diff --git a/README.md b/README.md index 3f1c76119..c57773440 100644 --- a/README.md +++ b/README.md @@ -61,6 +61,10 @@ http-server -p 8000 cocoda/ # serve the pre-built release http-server -p 8000 dist/ # or serve the build version ``` +### Docker + +Cocoda is also available via Docker. Please refer to the documentation at https://hub.docker.com/repository/docker/coliconc/cocoda for more details. + ## Usage There is a detailled end-user manual available [in German](https://gbv.github.io/cocoda/dev/user-manual-de.html) and [in English](https://gbv.github.io/cocoda/dev/user-manual-en.html). The German version will likely be more up-to-date. Documentation sources are located in directory `docs`. diff --git a/docker/.dockerignore b/docker/.dockerignore new file mode 100644 index 000000000..26fc0586c --- /dev/null +++ b/docker/.dockerignore @@ -0,0 +1,24 @@ +.DS_Store +node_modules/ +/dist*/ +/styleguide/ +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +build/build-info.json +docs/user-manual* + +# Relases (when using bin/build-all.sh) +releases/ + +# Temporary folder +temp/ + +# Editor directories and files +.idea +.vscode +*.suo +*.ntvs* +*.njsproj +*.sln diff --git a/docker/Dockerfile b/docker/Dockerfile new file mode 100644 index 000000000..011ab83b2 --- /dev/null +++ b/docker/Dockerfile @@ -0,0 +1,33 @@ +# Step 1: Build Cocoda via node:12-alpine image. +FROM node:12-alpine AS builder +WORKDIR /usr/src/app + +## We need bash and git. +RUN apk add --no-cache bash +RUN apk add --no-cache git + +## Install dependencies (separate step to utilize caching) +COPY package*.json ./ +RUN npm ci + +## Copy app source and build application +COPY . . +RUN npm run build + +# Step 2: Use nginx:alpine image as actual base image and copy files from dist/ into it. +FROM nginx:alpine +WORKDIR /usr/share/nginx/html + +## Copy application from builder +COPY --from=builder /usr/src/app/dist . + +## Create symlink for configuration +## -> The config folder can then be mounted via /config +RUN mkdir /config +RUN mv ./cocoda.json ./cocoda-previous.json +RUN ln -s /config/cocoda.json ./cocoda.json + +COPY docker/docker-entrypoint.sh /usr/local/bin/ + +ENTRYPOINT ["docker-entrypoint.sh"] +CMD ["%%CMD%%"] diff --git a/docker/README.md b/docker/README.md new file mode 100644 index 000000000..ab71d2952 --- /dev/null +++ b/docker/README.md @@ -0,0 +1,59 @@ +# [Cocoda Mapping Tool](https://github.com/gbv/cocoda) +[![GitHub release](https://img.shields.io/github/release/gbv/cocoda.svg)](https://github.com/gbv/cocoda/releases/latest) +[![GitHub](https://img.shields.io/github/license/gbv/cocoda.svg)](https://github.com/gbv/cocoda/blob/master/LICENSE) +[![Build Status](https://travis-ci.org/gbv/cocoda.svg?branch=dev)](https://travis-ci.org/gbv/cocoda) + +Cocoda is a web-based tool for creating mappings between knowledge organization systems. It is part of a larger infrastructure of [Project coli-conc](https://coli-conc.gbv.de). + +- See [GitHub](https://github.com/gbv/cocoda) for more information about the tool. +- Hosted versions of Cocoda can be found [here](https://coli-conc.gbv.de/cocoda/). + +## Supported Architectures +Currently, only `x86-64` is supported, but we are planning to add more architectures soon. + +## Available Tags +- The current release version is available under `latest`. However, new major versions might break compatibility of the previously used config file, therefore it is recommended to use a version tag instead. +- We follow SemVer for versioning the application. Therefore, `x` offers the latest image for the major version x, `x.y` offers the latest image for the minor version `x.y`, and `x.y.z` offers the image for a specific patch version x.y.z. +- Additionally, the latest development version of Cocoda is available under `dev`. + +## Usage +Here are some example snippets to help you get started running the image. + +### docker +```bash +docker run -it \ + --name=cocoda \ + -p 8080:80 \ + -v /path/to/appdata:/config \ + --restart unless-stopped \ + coliconc/cocoda +``` + +This will create and start a Cocoda container running under host port 8080 with the configuration folder mounted under `/path/to/appdata`. Use `/path/to/appdata/cocoda.json` to configure the application (see below) and access it under `http://localhost:8080`. + +### docker-compose +`docker-compose.yml`: +```yml +version: "3" + +services: + cocoda: + image: coliconc/cocoda + volumes: + # Mount ./config folder into container + - ./config:/config + ports: + # Default to port 8080 + - ${PORT:-8080}:80 + restart: always +``` + +Then start the application using `docker-compose up`. This will create and start a Cocoda container running under host port 8080 (or a custom port in `PORT`) with the configuration folder mounted under `./config`. Use `./config/cocoda.json` to configure the application (see below) and access it under `http://localhost:8080`. + +## Application Setup + +Cocoda will create a configuration file under `/config/cocoda.json` inside the image which can be used to configure the application. By default, the file is empty (or rather an empty object `{}`). The file is merged with a default configuration (see [`cocoda.default.json`](https://github.com/gbv/cocoda/blob/dev/config/cocoda.default.json)) that offers a selection of preconfigured registries and other configurations. + +Please refer to the [documentation](https://github.com/gbv/cocoda#configuration) on how to use the configuration file. + +After editing `cocoda.json`, the container does not have to be restarted. It is sufficient to reload the application in the browser. diff --git a/docker/docker-entrypoint.sh b/docker/docker-entrypoint.sh new file mode 100755 index 000000000..706cfcbd8 --- /dev/null +++ b/docker/docker-entrypoint.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +# Copy default configuration file if necessary +if [ ! -f /config/cocoda.json ]; then + cp ./cocoda-previous.json /config/cocoda.json +fi + +# Run nginx +exec nginx -g 'daemon off;'