From 516ef77614360e7a24d9068242fbc988ea00d407 Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Sat, 22 Feb 2020 00:46:48 +0100 Subject: [PATCH] Docker: add single image This adds an image containing its own PostgreSQL service. --- extra/docker-single/Dockerfile | 105 +++++++++++++++++++++++++ extra/docker-single/README.md | 23 ++++++ extra/docker-single/db/.gitignore | 4 + extra/docker-single/docker-compose.yml | 25 ++++++ extra/docker-single/entrypoint.sh | 46 +++++++++++ 5 files changed, 203 insertions(+) create mode 100644 extra/docker-single/Dockerfile create mode 100644 extra/docker-single/README.md create mode 100644 extra/docker-single/db/.gitignore create mode 100644 extra/docker-single/docker-compose.yml create mode 100755 extra/docker-single/entrypoint.sh diff --git a/extra/docker-single/Dockerfile b/extra/docker-single/Dockerfile new file mode 100644 index 00000000..bd7faae7 --- /dev/null +++ b/extra/docker-single/Dockerfile @@ -0,0 +1,105 @@ +FROM ubuntu:18.04 +MAINTAINER DocMarty84 + +# Reconfigure locales to use UTF-8 encoding +RUN set -x; \ + apt-get update -qq && \ + apt-get install -y --no-install-recommends -qq locales + +RUN set -x; \ + dpkg-reconfigure -fnoninteractive locales && \ + sed -i 's/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g' /etc/locale.gen && \ + locale-gen en_US.UTF-8 && \ + /usr/sbin/update-locale LANG=en_US.UTF-8 +ENV LC_ALL en_US.UTF-8 + +# Install apt dependencies +ARG DEBIAN_FRONTEND=noninteractive +RUN set -x; \ + apt-get update -qq && \ + apt-get install -y --no-install-recommends -qq \ + adduser \ + build-essential \ + ffmpeg \ + libtag1-dev \ + lsb-base \ + mediainfo \ + postgresql-common \ + python3-babel \ + python3-chardet \ + python3-dateutil \ + python3-decorator \ + python3-dev \ + python3-docutils \ + python3-feedparser \ + python3-gevent \ + python3-html2text \ + python3-jinja2 \ + python3-libsass \ + python3-lxml \ + python3-mako \ + python3-mock \ + python3-passlib \ + python3-pil \ + python3-pip \ + python3-polib \ + python3-psutil \ + python3-psycopg2 \ + python3-pydot \ + python3-pyldap \ + python3-pyparsing \ + python3-pypdf2 \ + python3-qrcode \ + python3-reportlab \ + python3-requests \ + python3-setuptools \ + python3-tz \ + python3-vatnumber \ + python3-vobject \ + python3-werkzeug \ + python3-wheel \ + python3-xlsxwriter \ + python3-yaml \ + python3-zeep \ + wget && \ + apt-get clean -qq + +# Install pip dependencies +RUN set -x; \ + pip3 install \ + mutagen==1.43.0 \ + pytaglib==1.4.5 \ + num2words==0.5.6 \ + webvtt-py==0.4.2 + +# PostgreSQL install: deactivate automatic cluster creation since it will created at runtime in a +# mounted location. Copied from https://github.com/docker-library/postgres/tree/master/10 +RUN set -x; \ + sed -ri 's/#(create_main_cluster) .*$/\1 = false/' /etc/postgresql-common/createcluster.conf && \ + apt-get install -y --no-install-recommends -qq \ + postgresql \ + postgresql-client + +# Set up user and mount point +RUN set -x; \ + useradd -m koozic && \ + mkdir -p /mnt/host && \ + chown -R koozic /mnt/host + +# Install KooZic +RUN set -x; \ + v=v3.0.0 && \ + wget -q https://github.com/DocMarty84/koozic/releases/download/${v}/koozic-${v}.tar.gz && \ + tar xfz koozic-*.tar.gz && \ + rm -rf koozic-*.tar.gz +RUN set -x; \ + mv koozic /usr/local/ && \ + chown -R koozic /usr/local/koozic + +# Copy entrypoint script +COPY ./entrypoint.sh / + +# Expose KooZic services +EXPOSE 8069 8072 + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/extra/docker-single/README.md b/extra/docker-single/README.md new file mode 100644 index 00000000..5e865e44 --- /dev/null +++ b/extra/docker-single/README.md @@ -0,0 +1,23 @@ +This folder provides a basic Docker configuration using Docker-compose in order to run a fully +functional KooZic installation. It includes: +- Ubuntu 18.04 +- KooZic v3 +- PostgreSQL 10 + +# Set up containers + +1. Install Docker Compose following the +[official instructions](https://docs.docker.com/compose/) +2. Build: +``` +docker-compose build +``` +3. Configure: +Edit `docker-compose.yml` and replace `/music` by the music folder you want to share. +4. Run: +``` +docker-compose up -d +``` + +KooZic should now be available at [http://localhost:8069](http://localhost:8069). +Don't forget to add `/mnt/host` in the Folders section. diff --git a/extra/docker-single/db/.gitignore b/extra/docker-single/db/.gitignore new file mode 100644 index 00000000..5e7d2734 --- /dev/null +++ b/extra/docker-single/db/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore diff --git a/extra/docker-single/docker-compose.yml b/extra/docker-single/docker-compose.yml new file mode 100644 index 00000000..075b93db --- /dev/null +++ b/extra/docker-single/docker-compose.yml @@ -0,0 +1,25 @@ +version: '3.7' + +services: + + app: + container_name: koozic_app + restart: always + + # Pull the pre-built image from the server: + #image: docmarty84/koozic + # Build the image locally (useful to customize the entrypoint.sh file): + build: . + image: koozic_app:latest + + # Change '/music' to the actual location of your music. + volumes: + - koozic_app:/home/koozic/.local + - ./db:/var/lib/postgresql/10/main/ + - /music:/mnt/host:ro + ports: + - 8069:8069 + - 8072:8072 + +volumes: + koozic_app: diff --git a/extra/docker-single/entrypoint.sh b/extra/docker-single/entrypoint.sh new file mode 100755 index 00000000..d5ed4950 --- /dev/null +++ b/extra/docker-single/entrypoint.sh @@ -0,0 +1,46 @@ +#!/bin/bash + +# Create PostgreSQL cluster +if [[ ! -f "/etc/postgresql/10/main/postgresql.conf" ]] +then + pg_createcluster 10 main --start + sed -i 's/5432/54321/g' /etc/postgresql/10/main/postgresql.conf + cp /etc/postgresql/10/main/*.conf /var/lib/postgresql/10/main/ +fi + +# Restart PostgreSQL and create koozic user +service postgresql restart +sleep 5 +su - postgres -c "createuser -s koozic" + +# Give to koozic user the right to write in app volume +chown -R koozic /home/koozic/.local + +# Initialize db (odoo automatically detects if db is already initialized) +echo "KooZic init process starting" +su - koozic -c "/usr/local/koozic/odoo-bin \ + -d koozic-v3 \ + --db_port=54321 \ + -u oomusic,oovideo \ + --without-demo=all \ + --stop-after-init \ + --logfile /home/koozic/.local/koozic.log \ + --log-level=warn" +echo "KooZic init process complete" + +# Start koozic +echo "Starting KooZic" +echo "The log is available by connecting to the container:" +echo " docker exec -ti /bin/bash" +echo " tail -f /home/koozic/.local/koozic.log" +su - koozic -c "/usr/local/koozic/odoo-bin \ + --workers=4 \ + --limit-time-cpu=1800 \ + --limit-time-real=3600 \ + -d koozic-v3 \ + --db-filter=koozic-v3 \ + --db_port=54321 \ + --without-demo=all \ + --no-database-list \ + --logfile /home/koozic/.local/koozic.log \ + --log-level=warn"