Nuleculizing Koel Music App

Koel is a personal music streaming server. And it needs Laravel and MariaDB services for running. So this was the perfect application to Nuleculize, because it follows a micro services architecture. So what is Nulecule? Nulecule is a composite Container-based Application Specification. Read more about Nulecule. Atomic App is a reference implementation of the Nulecule specification. It can be used to bootstrap packaged container environments and then run them. Atomic App is designed to be ran within a container.

Install docker and atomic as a dependencies.

$ sudo yum install docker atomic

Containerize the application

To containerize the application, clone the Koel code from github.

[vagrant@centos7-adb ~]$ git clone https://github.com/phanan/koel
[vagrant@centos7-adb ~]$ cd koel

Goto the koel directory and add two files one is Dockerfile and entrypoint.sh. Add the code as following in those files.

Dockerfile

[vagrant@centos7-adb koel]$ cat Dockerfile
FROM fedora

RUN dnf install -y composer php-mysqlnd npm git

RUN mkdir -p /koel
WORKDIR /koel
COPY . /koel

RUN composer install
RUN npm install
CMD /koel/entrypoint.sh

entrypoint.sh file

[vagrant@centos7-adb koel]$ cat entrypoint.sh
#!/bin/bash

WAIT_SEC=5
echo Wait for database to come up for $WAIT_SEC seconds
sleep $WAIT_SEC

npm install --unsafe-perm
php artisan koel:init && php artisan serve --host=0.0.0.0

Change the file mode

[vagrant@centos7-adb koel]$ chmod a+x entrypoint.sh

Build the application container.

[vagrant@centos7-adb koel]$ docker build -t koel-server .

Now you can check the box is available on the machine

[vagrant@centos7-adb ~]$ docker images
REPOSITORY        TAG     IMAGE ID      CREATED         VIRTUAL SIZE
koel-server       latest  d95d660f9ccd  31 seconds ago  939.1 MB
docker.io/fedora  latest  6daa45be2ca9  12 days ago     204.5 MB

Nuleculizing the app

Make a directory called koel-atomicapp and make the directory structure like this, or you can simply clone the repository from here.

[vagrant@centos7-adb ~]$ mkdir koel-atomicapp
[vagrant@centos7-adb koel-atomicapp]$ tree
.
├── artifacts
│   └── docker
│       └── koel-run
├── Dockerfile
├── Nulecule
└── README.md

2 directories, 4 files

Nulecule file

[vagrant@centos7-adb koel-atomicapp]$ cat Nulecule
---
specversion: 0.0.2
id: koel-atomicapp

metadata:
  name: Koel Music App
  appversion: 2.0.0
  description: Music server for your music streaming from anywhere in your local network.
graph:
  - name: mariadb-centos7-atomicapp
    source: docker://projectatomic/mariadb-centos7-atomicapp
  - name: koel-music-app
    params:
      - name: image
        description: Koel Image
        default: koel-server
      - name: db_user
        description: Username for Database
      - name: db_pass
        description: Password for Database user
      - name: db_name
        description: Database Name
      - name: db_host
        description: Database Host
        default: mariadb:3306
      - name: db_conn
        description: Database connection name
        default: mysql
      - name: koel_http_port
        description: Port for Docker port mapping (used only with docker provider)
        default: 80
      - name: music_path
        description: Path to Music directory
      - name: app_admin_email
        description: Koel App server Admin Email
      - name: app_admin_name
        description: Koel App server Admin name
      - name: app_admin_pass
        description: Koel App server Admin Password
    artifacts:
      docker:
        - file://artifacts/docker/koel-run

Docker artifact file

[vagrant@centos7-adb koel-atomicapp]$ cat artifacts/docker/koel-run
docker run -d --name koel-music-atomicapp -p $koel_http_port:8000 --link mariadb-atomicapp-app:mariadb -e DB_CONNECTION=$db_conn -e DB_HOST=$db_host -e DB_DATABASE=$db_name -e DB_USERNAME=$db_user -e DB_PASSWORD=$db_pass -e ADMIN_EMAIL=$app_admin_email -e ADMIN_NAME=$app_admin_name -e ADMIN_PASSWORD=$app_admin_pass -v $music_path:$music_path:Z $image

Dockerfile

[vagrant@centos7-adb koel-atomicapp]$ cat Dockerfile
FROM projectatomic/atomicapp:0.4.2
LABEL io.projectatomic.nulecule.specversion="0.0.2" \
io.projectatomic.nulecule.providers="docker" \
Build="docker build --rm --tag test/koel-music-atomicapp ."

ADD /Nulecule /Dockerfile README.md /application-entity/
ADD /artifacts /application-entity/artifacts

Build Koel atomicapp image

[vagrant@centos7-adb koel-atomicapp]$ docker build -t koel-atomicapp .

Run the container, answer the interactively asked questions and there you go.

Note: When you will answer the app_admin_email, make sure that it is in the <some>@<thing>.com format.

[vagrant@centos7-adb ~]$ sudo atomic run koel-atomicapp --provider=docker

Find your IP address and open it in browser

[vagrant@centos7-adb koel-atomicapp]$ ip a sh eth0 | grep inet
inet 192.168.121.96/24 brd 192.168.121.255 scope global dynamic eth0
inet6 fe80::5054:ff:fe35:1604/64 scope link

I can now goto 192.168.121.96 and access the music server.

Limitations:

  • Currently this only works on docker as a provider, but further we would like to make it run using Kubernetes.
  • Using this way user has to provide the music directory path twice, once when starting the app and once when in the browser inside the app.
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s