Skip to content

Commit

Permalink
Merge pull request #574 from gbv/docker
Browse files Browse the repository at this point in the history
Add deployment via Docker (#553)
  • Loading branch information
stefandesu authored Jun 26, 2020
2 parents 3575c5b + a742a16 commit dadc7c4
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
24 changes: 24 additions & 0 deletions docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -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
33 changes: 33 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -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%%"]
59 changes: 59 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 9 additions & 0 deletions docker/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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;'

0 comments on commit dadc7c4

Please sign in to comment.