Skip to content

Commit

Permalink
Merge pull request #10 from InsanityRadio/dockerize
Browse files Browse the repository at this point in the history
Dockerize Nerve
  • Loading branch information
Jamie0 committed Jul 13, 2018
2 parents 4b60079 + 55a2c16 commit b6581d5
Show file tree
Hide file tree
Showing 10 changed files with 439 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ Gemfile.lock
config.yml
export
schema.current.sql
config/root.txt
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,21 @@ You'll also need to mount your playout drives on the "master" node
This project is a part of the [Insanity Tech Masterplan](https://wiki.insanityradio.com/wiki/Technical_Masterplan).


## Docker Volumes

To mount your AudioWall in Docker, run the following command on the host.

sudo docker volume create --driver local --opt type=cifs --opt device=//10.32.0.222/AudioWall --opt o=username=Nerve,password=password,_netdev,uid=999,gid=999 audiowall

You'll also want to load the database schema, as this isn't done automatically. (Do this after building)

docker-compose run --rm worker sh -c "bundle exec rake db:schema:load db:migrate"

To run database migrations, after building but before launching, run:

docker-compose run --rm worker sh -c "bundle exec rake db:migrate"


## Quick Tasks / To-do

- Create recall button on interface that invokes Nerve::Job::Recall
Expand Down
6 changes: 4 additions & 2 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
require_relative 'modules'

Bundler.require
$config = YAML::load(File.read(File.join(File.dirname(__FILE__), "config.yml")))
$genres = YAML::load(File.read(File.join(File.dirname(__FILE__), "genres.yml")))

$config = YAML::load(ERB.new(File.read(File.join(File.dirname(__FILE__), "config.yml"))).result(binding))
$genres = YAML::load(ERB.new(File.read(File.join(File.dirname(__FILE__), "genres.yml"))).result(binding))

$env = {:slave => false}

require_relative 'database'
Expand Down
9 changes: 6 additions & 3 deletions app/models/track.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,19 @@ def why_unsafe
end

def delete! soft = false

_local_path = $config["export"]["directory"] + "/" + local_path
File.unlink(_local_path) rescue nil
File.unlink(_local_path) rescue puts "Failed to delete #{id}: #{$!}"

if soft
self.status = 6
self.save
else
File.unlink(_local_path + ".ogg") rescue nil
File.unlink(_local_path + ".dat") rescue nil
File.unlink(_local_path + ".ogg") rescue puts "Failed to delete #{id} preview: #{$!}"
File.unlink(_local_path + ".dat") rescue puts "Failed to delete #{id} form: #{$!}"
destroy
end

end

def get_json extended = false
Expand Down
5 changes: 3 additions & 2 deletions database.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
require 'sinatra'
require 'sinatra/activerecord'

set :database, $config['database']['development']
set :database, $config['database'][ENV['RACK_ENV'] || 'development']
Resque.redis = $config['database']['redis']

module Nerve
module Database
Expand All @@ -16,4 +17,4 @@ def self.last_id
end

end
end
end
10 changes: 10 additions & 0 deletions db/migrate/20180713103629_add_times.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class AddTimes < ActiveRecord::Migration
def change

execute 'ALTER TABLE albums ALTER COLUMN creation_date SET DEFAULT NOW()'
execute 'ALTER TABLE artists ALTER COLUMN creation_date SET DEFAULT NOW()'
execute 'ALTER TABLE nerve_cache ALTER COLUMN creation_date SET DEFAULT NOW()'
execute 'ALTER TABLE tracks ALTER COLUMN creation_date SET DEFAULT NOW()'

end
end
84 changes: 84 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
version: '3.1'

services:
mariadb:
restart: always
image: mariadb
environment:
- MYSQL_ROOT_PASSWORD_FILE=/config/root.txt
- MYSQL_DATABASE=nerve
volumes:
- ./config:/config
redis:
image: redis

http:
restart: always
build:
context: .
dockerfile: docker/Dockerfile.http
args:
- http_proxy
- https_proxy
- RESOLVER=8.8.8.8
ports:
- "9292:80"
links:
- redis
- mariadb
secrets:
- source: "nerve_root_pw"
target: "nerve_root_pw"
uid: "9999"
gid: "9999"
mode: 0400
environment:
- http_proxy
- https_proxy
volumes:
- tmp:/tmp
- music:/music
- ./config:/config
worker:
restart: always
build:
context: .
dockerfile: docker/Dockerfile.worker
args:
- http_proxy
- https_proxy
- RESOLVER=8.8.8.8
links:
- redis
- mariadb
secrets:
- source: "nerve_root_pw"
target: "nerve_root_pw"
uid: "9999"
gid: "9999"
mode: 0400
environment:
- http_proxy
- https_proxy
volumes:
- tmp:/tmp
- music:/music
- audiowall:/audiowall
- ./config:/config
volume_own:
restart: "no"
image: alpine
command: "chown -R 999:999 /music"
volumes:
- music:/music
- audiowall:/audiowall
secrets:
nerve_root_pw:
file: ./config/root.txt

volumes:
music:
tmp:
audiowall:
external:
name: audiowall
31 changes: 31 additions & 0 deletions docker/Dockerfile.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM phusion/passenger-ruby23:latest
MAINTAINER _@insanityradio.com

ARG RESOLVER=8.8.8.8

RUN apt-get update && apt-get install -y \
build-essential git libc6-dev wget

WORKDIR /tmp
RUN wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-1.00.27.tar.gz && \
tar -xzf freetds-1.00.27.tar.gz
WORKDIR /tmp/freetds-1.00.27
RUN ./configure --prefix=/usr/local --with-tdsver=7.3 && make && make install

RUN rm -f /etc/service/nginx/down

WORKDIR /home/app

COPY ./Gemfile ./
RUN gem install bundler && bundle install --jobs 20 --retry 5

COPY ./docker/nginx.conf /etc/nginx/sites-enabled/default

RUN ln -s /config/config.yml ./config.yml

COPY ./ ./
RUN rm config/root.txt
RUN chown -R app: .

CMD ["/sbin/my_init"]

Loading

0 comments on commit b6581d5

Please sign in to comment.