diff --git a/Dockerfile b/Dockerfile index f82badf..73e8989 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,165 +1,170 @@ # DOWNLOAD BASE IMAGE OF CENTOS7 FROM centos:centos7 MAINTAINER alexis rapin # CREATE APP USER RUN adduser -m genocrunch_user WORKDIR /home/genocrunch_user # MISC RUN yum -y install nano # INSTALL RUBY WITH RBENV # Install dependencies RUN yum -y update && yum clean all RUN yum install -y git-core \ zlib \ zlib-devel \ gcc \ gcc-c++ \ patch \ readline \ readline-devel \ libyaml-devel \ libffi-devel \ openssl-devel \ make \ bzip2 \ bzip2-devel \ autoconf \ automake \ libtool \ bison \ curl \ sqlite-devel \ epel-release \ nodejs && yum clean all # Install rbenv from github USER genocrunch_user RUN git clone https://github.com/rbenv/rbenv.git ~/.rbenv -RUN echo 'export PATH="(~/.rbenv/bin:$PATH"' >> ~/.bashrc -RUN echo 'eval "$(~/.rbenv/bin/rbenv init -)"' >> ~/.bashrc -RUN source ~/.bashrc +RUN echo 'export PATH="~/.rbenv/bin:$PATH"' >> ~/.bashrc \ + && echo 'eval "$(~/.rbenv/bin/rbenv init -)"' >> ~/.bashrc RUN git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build USER root RUN cd /home/genocrunch_user/.rbenv/plugins/ruby-build && ./install.sh # Install ruby USER genocrunch_user -RUN ~/.rbenv/bin/rbenv install 2.3.1 -RUN ~/.rbenv/bin/rbenv global 2.3.1 +RUN source ~/.bashrc \ + && rbenv install 2.3.1 \ + && rbenv global 2.3.1 # Install rails RUN echo "gem: --no-document" > ~/.gemrc -RUN ~/.rbenv/shims/gem install bundler -RUN ~/.rbenv/shims/gem install rails -v 5.0.1 -RUN ~/.rbenv/bin/rbenv rehash +RUN source ~/.bashrc \ + && gem install bundler \ + && gem install rails -v 5.0.1 \ + && rbenv rehash RUN echo 'export PATH="~/.rbenv/versions/2.3.1/bin:$PATH"' >> .bashrc # INSTALL POSTGRESQL USER root RUN yum -y install postgresql \ postgresql-contrib \ postgresql-devel \ postgresql-libs #RUN postgresql-setup initdb #RUN sed -i 's/^\(host.*\)ident$/\1md5/g;' /var/lib/pgsql/data/pg_hba.conf #RUN systemctl start postgresql #RUN systemctl enable postgresql # INSTALL PYTHON2.7 #RUN yum install -y python-pip #RUN pip install numpy #RUN yum -y groupinstall 'Development Tools' # INSTALL R RUN yum install -y R-core \ R-base \ R-devel \ libcurl-devel # Install R packages RUN yum install -y libxml2-devel RUN echo "options(repos=structure(c(CRAN='https://cran.uib.no')))" >> .Rprofile RUN echo ".libPaths('/usr/share/R/library')" >> .Rprofile RUN Rscript -e "install.packages('ineq')" RUN Rscript -e "install.packages('rjson')" RUN Rscript -e "install.packages('fpc')" RUN Rscript -e "install.packages('multcomp')" RUN Rscript -e "install.packages('FactoMineR')" RUN Rscript -e "install.packages('colorspace')" RUN Rscript -e "install.packages('vegan')" RUN Rscript -e "install.packages('optparse')" RUN Rscript -e "install.packages('gplots')" RUN Rscript -e "install.packages('fossil')" RUN Rscript -e "install.packages('coin')" RUN Rscript -e "install.packages('SNFtool')" RUN Rscript -e "install.packages('devtools')" RUN Rscript -e "library(devtools); install_github('igraph/rigraph')" RUN Rscript -e "source('https://bioconductor.org/biocLite.R'); biocLite('sva')" # INSTALL THE APP USER genocrunch_user # Create a new Rails project WORKDIR /home/genocrunch_user -RUN ~/.rbenv/versions/2.3.1/bin/rails new genocrunch -d postgresql -B +RUN source ~/.bashrc \ + && rails new genocrunch -d postgresql -B +#RUN GIT_CURL_VERBOSE=1 git clone https://git@c4science.ch/source/genocrunch-2.1.git /tmp/genocrunch +RUN git clone https://git@c4science.ch/source/genocrunch-2.1.git /tmp/genocrunch WORKDIR /home/genocrunch_user/genocrunch -RUN GIT_CURL_VERBOSE=1 git clone https://git@c4science.ch/source/genocrunch-2.1.git /tmp/genocrunch RUN rsync -r /tmp/genocrunch/ ./ RUN rm -r /tmp/genocrunch # Install R/python scripts USER root RUN chmod 755 install.sh && ./install.sh USER genocrunch_user # Install gems -RUN ~/.rbenv/versions/2.3.1/bin/bundle install - -RUN cp ~/.rbenv/versions/*/lib/ruby/gems/*/gems/jquery-datatables-rails-*/app/assets/javascripts/dataTables/jquery.dataTables.js ~/.rbenv/versions/*/lib/ruby/gems/*/gems/jquery-datatables-rails-*/app/assets/javascripts/dataTables/jquery.dataTables.js.bkp -RUN sed -i -e 's/No data available in table/This table is empty/g' ~/.rbenv/versions/*/lib/ruby/gems/*/gems/jquery-datatables-rails-*/app/assets/javascripts/dataTables/jquery.dataTables.js +RUN source ~/.bashrc \ + && ~/.rbenv/versions/2.3.1/bin/bundle install +RUN table_fp=$(cd ~/.rbenv/versions/*/lib/ruby/gems/*/gems/jquery-datatables-rails-*/app/assets/javascripts/dataTables/ && pwd) \ + && cp "${table_fp}"/jquery.dataTables.js "${table_fp}"/jquery.dataTables.js.bkp \ + && sed -i -e 's/No data available in table/This table is empty/g' "${table_fp}"/jquery.dataTables.js # Get versions (print a json file with versions of R packages) RUN lib/genocrunch_console/bin/get_version.py # Configure the app USER root EXPOSE 3000 USER genocrunch_user # config/config.yml RUN cp config/config.yml.keep config/config.yml RUN sed -i 's/data_dir:.*$/data_dir: \/home\/genocrunch_user\/genocrunch/g' config/config.yml RUN sed -i 's/info_links:.*$/info_links: []/g' config/config.yml RUN sed -i 's/user_confirmable:.*$/user_confirmable: false/g' config/config.yml # config/initializers/devise.rb RUN cp config/initializers/devise.rb.keep config/initializers/devise.rb RUN sed -i 's/config.mailer_sender =.*$/config.mailer_sender = "noreply.genocrunch@gmail.com"/g' config/initializers/devise.rb # config/environments/development.rb RUN cp config/environments/development.rb.keep config/environments/development.rb RUN sed -i 's/config.action_mailer.default_url_options =.*$/config.action_mailer.default_url_options = {:host => "localhost:3000"}/g' config/environments/development.rb RUN sed -i 's/:address =>.*$/:address => "smtp.gmail.com",/g' config/environments/development.rb RUN sed -i 's/:port =>.*$/:port => 587,/g' config/environments/development.rb RUN sed -i 's/:domain =>.*$/:domain => "mail.google.com",/g' config/environments/development.rb RUN sed -i 's/:user_name =>.*$/:user_name => "noreply.genocrunch@gmail.com",/g' config/environments/development.rb RUN sed -i 's/:password =>.*$/:password => "email_password",/g' config/environments/development.rb RUN sed -i 's/:authentication =>.*$/:authentication => :plain,/g' config/environments/development.rb RUN sed -i 's/:enable_starttls_auto =>.*$/:enable_starttls_auto => true/g' config/environments/development.rb # config/database.yml RUN cp config/database.yml.keep config/database.yml RUN sed -i 's/^.*username:.*$/ username: genocrunch_user/g' config/database.yml RUN sed -i 's/database:.*$/database: genocrunch/g' config/database.yml RUN sed -i 's/^.*password:.*$/ password: genocrunch_db_password/g' config/database.yml RUN sed -i 's/^.*host:.*$/ host: hostaddress/g' config/database.yml RUN cp db/seeds.rb.keep db/seeds.rb # Run Genocrunch -CMD source /home/genocrunch_user/.bashrc && RAILS_ENV=development ruby bin/delayed_job -n 2 start; /home/genocrunch_user/genocrunch/bin/rails server +CMD source ~/.bashrc \ + && RAILS_ENV=development ruby bin/delayed_job -n 2 start; /home/genocrunch_user/genocrunch/bin/rails server diff --git a/README.md b/README.md index 5be9be9..c9db68b 100644 --- a/README.md +++ b/README.md @@ -1,172 +1,167 @@ Genocrunch in Docker ==================== A Dockerfile to run Genocrunch web application on Docker. ## Resources - **Git clone URL:** - **Documentation:** - **Genocrunch documentation:** - **Genocrunch official web server:** ## Requirements -- **PostgreSQL** - **Docker version 17.12.0-ce** ## Installation (on Debian linux) +Note: you may have to use `sudo` with docker commands if docker is not configured to be used as a non-root user. + ### Set the Docker container external resources -The genocrunch web application will need to store some data files and to use \ -a database. To avoid data loses when updating a container, you can set both \ -data storage location and database on the host. +The Genocrunch web application will need to store some data files and to use a database. To avoid data loses when updating a container, you can set both data storage location and database on the host (as opposed to on the docker container itself). -Create a new data storage directory that will be used by genocrunch: +First, create a new data storage directory on the host side. This directory will be used by the Genocrunch web app running on the docker container: ``` $ mkdir /path/to/genocrunch/storage ``` -Install PostgreSQL and create a new database: +Also create a PostgreSQL database on the host side. This database will be used by the Genocrunch web app running on the docker container: ``` $ sudo apt-get install postgresql postgresql-contrib $ sudo su postgres $ psql postgres=# create role genocrunch_user with login password 'genocrunch_db_password'; postgres=# create database genocrunch owner genocrunch_user; postgres=# \q $ exit ``` -Allow the docker container to be listened from the database by modifying the \ -`/etc/postgresql/9.?/main/postgresql.conf` file as following: +Then, allow the docker container to be listened from the database by modifying the `/etc/postgresql/9.?/main/postgresql.conf` file as following: ``` #/etc/postgresql/9.?/main/postgresql.conf ... listen_addresses = '*' ... ``` Also add the following line to `/etc/postgresql/9.?/main/pg_hba.conf`: ``` #/etc/postgresql/9.?/main/pg_hba.conf ... host all all 0.0.0.0/0 md5 ... ``` -Restart the PostgreSQL service: +Finally, restart the PostgreSQL service: ``` $ sudo /etc/init.d/postgresql restart ``` ### Build the docker image -Download the Dockerfile with git: +First, download the Dockerfile from its git repository: ``` $ git clone https://c4science.ch/source/genocrunch_docker.git -$ cd genocrunch_docker ``` -Set up the genocrunch web app configuration from the Dockefile: +Before building a docker image using the Dockerfile, you may want to edit the Dockerfile in order to customize the installation of the Genocrunch web app. +For this, open `genocrunch_docker/Dockerfile` with your favorite editor and follow the following instructions: -Edit this line to define any custom link to be included in the info menu of \ -the genocrunch web app topbar: +Edit this line to define any custom link to be included in the info menu of the Genocrunch web app topbar: ``` #Dockerfile ... # config/config.yml ... RUN sed -i 's/info_links:.*$/info_links: [{name: "link_name", href: "link_url", target: "_blank"}]/g' config/config.yml ``` -Edit this line to define whether new users will be asked to confirm their \ -email address via a confirmation link or not: +Edit this line to define whether new users will be asked to confirm their email address via a confirmation link or not: ``` #Dockerfile ... # config/config.yml ... RUN sed -i 's/user_confirmable:.*$/user_confirmable: false/g' config/config.yml ``` Edit these lines to set the email address to be used by the web app: ``` #Dockerfile ... # config/initializers/devise.rb ... RUN sed -i 's/config.mailer_sender =.*$/config.mailer_sender = "app_email@gmail.com"/g' config/initializers/devise.rb # config/environments/development.rb ... RUN sed -i 's/config.action_mailer.default_url_options =.*$/config.action_mailer.default_url_options = {:host => "localhost:3000"}/g' config/environments/development.rb RUN sed -i 's/:address =>.*$/:address => "smtp.gmail.com",/g' config/environments/development.rb RUN sed -i 's/:port =>.*$/:port => 587,/g' config/environments/development.rb RUN sed -i 's/:domain =>.*$/:domain => "mail.google.com",/g' config/environments/development.rb RUN sed -i 's/:user_name =>.*$/:user_name => "app_email@gmail.com",/g' config/environments/development.rb RUN sed -i 's/:password =>.*$/:password => "app_email_password",/g' config/environments/development.rb RUN sed -i 's/:authentication =>.*$/:authentication => :plain,/g' config/environments/development.rb RUN sed -i 's/:enable_starttls_auto =>.*$/:enable_starttls_auto => true/g' config/environments/development.rb ... ``` Edit these lines to fit the database name, user and password set previously: ``` #Dockerfile ... # config/database.yml ... RUN sed -i 's/^.*username:.*$/ username: genocrunch_user/g' config/database.yml RUN sed -i 's/database:.*$/database: genocrunch/g' config/database.yml RUN sed -i 's/^.*password:.*$/ password: genocrunch_db_password/g' config/database.yml ... ``` -Finally, build the docker image (you may have to use sudo with this command if \ -docker is not configured to be used as non-root user): +Finally, build the docker image: ``` $ docker build --rm -t genocrunch . ``` -### Run a docker container +### Database initialization -Run the docker container with the command below. Make sure to replace \ -`/path/to/genocrunch/storage` with the appropriate path and replace \ -`host.ip.address` by the host ip address. -This will automatically start the Genocrunch web server which will be \ -accessible in a web browser at on the host and `host_ip_address:3000` on the network. +Complete the installation of the Genocrunch web app by initializing its database from within a docker container using rails schema (`db/schema.rb`) and seeds (`db/seeds.rb`). +Caution: this will overwrite the database and should be applied only for initialization/re-initialization, not updates. For updates, use migrations or SQL queries. ``` -$ cd /path/to/genocrunch -$ docker run -v /path/to/genocrunch/storage:/home/genocrunch_user/genocrunch/users -p 3000:3000 --add-host=hostaddress:host.ip.address -it genocrunch -``` +$ docker run -v /path/to/genocrunch/storage:/home/genocrunch_user/genocrunch/users -p 3000:3000 --add-host=hostaddress:host.ip.address -it genocrunch bash +$ rails db:schema:load -Complete the installation by initializing the database from within a docker \ -container using `db/schema.rb` and `db/seeds.rb`: +# To change default guest and admin passwords and emails, edit the `User.create` query in the db/seeds.rb file with nano: +$ nano db/seeds.rb +# Finally, seed the database: +$ rails db:seed +$ exit ``` -$ docker run -v /path/to/genocrunch/storage:/home/genocrunch_user/genocrunch/users -p 3000:3000 --add-host=hostaddress:host.ip.address -it genocrunch bash -# Caution: this will overwrite the current database. -# For updates, use migrations instead -$ rails db:schema:load -$ rails db:seeds -$ exit +### Run a docker container + +Run a docker container using the command below. Make sure to replace `/path/to/genocrunch/storage` with the appropriate path (see the `Set the Docker container external resources` section above) and replace `host.ip.address` by the host ip address. +This will automatically start the Genocrunch web server which will be accessible in a web browser at on the host and `host.ip.address:3000` on your network. + +``` +$ docker run -v /path/to/genocrunch/storage:/home/genocrunch_user/genocrunch/users -p 3000:3000 --add-host=hostaddress:host.ip.address -it genocrunch ```