Skip to content

Commit

Permalink
Use Docker-compose and make container stateless
Browse files Browse the repository at this point in the history
Docker container should be stateless to prevent data loss on update.
- Provide docker-compose:
  - Use official PostgreSQL container
  - Store data in volumes
- Minor: add num2words to pip install (to suppress warning)
- DB upgrade can be made at each startup (Odoo automatically detects if
  DB is already initialized and update it if needed)

Closes #15
  • Loading branch information
fl42 authored and DocMarty84 committed Dec 26, 2018
1 parent 2932547 commit 57b0d72
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 56 deletions.
29 changes: 11 additions & 18 deletions extra/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
FROM ubuntu:18.04
MAINTAINER DocMarty84 <[email protected]>

# Reconfigure locales so PostgreSQL uses UTF-8 encoding
# Reconfigure locales to use UTF-8 encoding
RUN set -x; \
apt-get update -qq && \
apt-get install -y --no-install-recommends -qq locales && \
apt-get clean -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 && \
Expand All @@ -22,8 +22,6 @@ RUN set -x; \
libtag1-dev \
lsb-base \
mediainfo \
postgresql \
postgresql-client \
python3-babel \
python3-chardet \
python3-dateutil \
Expand Down Expand Up @@ -66,11 +64,14 @@ RUN set -x; \
RUN set -x; \
pip3 install \
mutagen==1.41.1 \
pytaglib==1.4.4
pytaglib==1.4.4 \
num2words==0.5.6

# Set up mount point
# Set up user and mount point
RUN set -x; \
mkdir -p /mnt/host
useradd -m koozic && \
mkdir -p /mnt/host && \
chown -R koozic /mnt/host

# Install KooZic
RUN set -x; \
Expand All @@ -79,16 +80,8 @@ RUN set -x; \
tar xfz koozic-*.tar.gz && \
rm -rf koozic-*.tar.gz
RUN set -x; \
tar xfz koozic/extra/ffmpeg/ffmpeg-*-64bit.tar.gz -C /usr/local/bin && \
mv koozic /usr/local/

# Set up PostgreSQL and KooZic
RUN set -x; \
sed -i 's/5432/54321/g' /etc/postgresql/10/main/postgresql.conf && \
service postgresql start && \
sleep 5 && \
su - postgres -c "createuser -s root" && \
/usr/local/koozic/odoo-bin -d koozic --db_port=54321 -i oomusic,oovideo --without-demo=all --stop-after-init --log-level=warn
mv koozic /usr/local/ && \
chown -R koozic /usr/local/koozic

# Copy entrypoint script
COPY ./entrypoint.sh /
Expand Down
31 changes: 11 additions & 20 deletions extra/docker/README.md
Original file line number Diff line number Diff line change
@@ -1,33 +1,24 @@
This folder provides a basic Docker configuration file in order to run a fully functional KooZic
installation. It includes:
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 2.0.0
- PostgreSQL 10.0
- FFmpeg 4.1
- PostgreSQL from Docker hub

By default, it is configured to take advantage of multi-processing. The container runs its own
PostgreSQL server on port 54321. Therefore, the latter should be available on your host system.

# Set up the container
# Set up containers

1. Install Docker following the
[official instructions](https://docs.docker.com/engine/installation/)
2. Build:
```
docker build -t koozic .
docker-compose build
```
3. Run:
3. Configure:
Edit `docker-compose.yml` and replace `/music` by the music folder you want to share.
4. Run:
```
docker run -d -p 8069:8069 -p 8072:8072 -v <host_folder>:/mnt/host:ro --name koozic koozic --
docker-compose up -d
```
Replace `<host_folder>` by the music folder you want to share. It will be available in `/mnt/host`
inside the container. KooZic should now be available at
[http://localhost:8069](http://localhost:8069).

# Execute the container

The usual Docker instructions can be used to start and stop the container:
```
docker start koozic
docker stop koozic
```
KooZic should now be available at [http://localhost:8069](http://localhost:8069).
Don't forget to add `/mnt/host` in the Folders section.
32 changes: 32 additions & 0 deletions extra/docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: '3.7'

services:

app:
container_name: koozic_app
restart: always
build: .
image: koozic_app:latest
volumes:
- koozic_app:/home/koozic/.local
- /music:/mnt/host:ro
depends_on:
- db
ports:
- 8069:8069
- 8072:8072

db:
container_name: koozic_db
restart: always
image: postgres:10.6
volumes:
- koozic_db:/var/lib/postgresql
environment:
- POSTGRES_USER=koozic
- POSTGRES_PASSWORD=koozic
- POSTGRES_DB=koozic

volumes:
koozic_app:
koozic_db:
49 changes: 31 additions & 18 deletions extra/docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
#!/bin/bash

set -e

service postgresql restart
# Wait for Postgres to be up
sleep 5

case "$1" in
-- | odoo)
/usr/local/koozic/odoo-bin \
--workers=4 \
--limit-time-cpu=1800 \
--limit-time-real=3600 \
--db_port=54321 \
--without-demo=all \
--no-database-list \
--log-level=warn
;;
*)
exec "$@"
esac
# 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 "Initializing db..."
su - koozic -c "/usr/local/koozic/odoo-bin \
-d koozic-v2 \
--db_host=db \
--db_port=5432 \
--db_user=koozic \
--db_password=koozic \
-u oomusic,oovideo \
--without-demo=all \
--stop-after-init \
--log-level=warn"
echo "DB initialization done"

exit 1
# Start koozic
su - koozic -c "/usr/local/koozic/odoo-bin \
--workers=4 \
--limit-time-cpu=1800 \
--limit-time-real=3600 \
-d koozic-v2 \
--db-filter=koozic-v2 \
--db_host=db \
--db_port=5432 \
--db_user=koozic \
--db_password=koozic \
--without-demo=all \
--no-database-list \
--log-level=warn"

0 comments on commit 57b0d72

Please sign in to comment.