Ruby Rose: deploying moebooru for development
This time I’m going to show how to deploy moebooru on good ol debian. Most of the parts are valid for any other linux distros too. So, moebooru is a RoR+postgreSQL server application and that means that we need both of these installed on the server beforehand. But to do that, we must prepare the server. In this guide I assume that you are running the commands as root if not stated otherwise.
Part 0: Pre-requirements
In most (if not all) of the manuals curl is used to get files from web. As RVM installer depends on curl internally and not only for downloading itself, we’ll need to install it, updating the existing packages at the same time. It may also be a good practice to install sudo because in older versions rvm required it even if run from the root user.
Now we’re ready to go to next step and deal with ruby.
Part 1: Ruby
Ok, we’re ready to install ruby, but first we need to install rvm that will help us to manage ruby versions dynamically. It is important because in most of distros (minus arch, slackware and gentoo) it is either quite hard to manage ruby versions (RHEL-based) or outright impossible (Debian-based). Firstly we have to add a mpapis public key:
We had to do it because rvm have to run checks during installation and it won’t install if the kay is not imported. We now may proceed with the installation itself.
This may take time, but be patient because it is one of the most important steps. It is very hard to clean the mess after the broken rvm installation - trust me. When it finishes, you will have to add users that need to have access to ruby to rvm group.
We are not finished yet, but we have to relogin for the changes in user groups to apply. After successful relogin execute
source /etc/profile.d/rvm.sh to make rvm usable. Now we should list versions of ruby available to be installed.
Right now version 2.2.0 is the latest more or less stable one so I’m going to install it, but you will have to choose it yourselves.
RVM will try to download and install the precompiled version, but if it fails, it will automatically try to compile the correct version of ruby for your system. This will look like:
If the server you have started the proccess on is not very fast (4+ cores, 8gb ram), this may take a lot of time so I would advice getting yourself a cup or two of coffee while you wait. When it finishes compilation, it will install ruby and proceed with gems installation.
Yay. It’s installed! Now just execute
rvm use 2.2.0 (or another version of your choice) and we are ready proceed with Postgres and miscellaneous other tools (i.e., nginx and Node.JS) that will make our life easier.
Part 2: PostgreSQL
In comparison with the pain of installing Ruby, Postgres installation will be a breeze. All we have to do is import the repository key, add repository and apt-get postgres.
“And that’s it?” - you ask - “nope, not quite.” We still have to configure Postgres to be able to handle moebooru.
You will be dropped into postgres root console. Just in case we better reset the whole database encoding because sometimes encoding is set improperly in the linux distro and this will result in numerous errors and will ultimately fail moebooru installation.
After this done we can add a database for moebooru with corresponding login credentials.
And don’t forget to change
%password% to the password you wish to use. You may also change the username, but I don’t think it is all that necessary.
Part 3: Miscellaneous software
Now let’s talk about nginx. “Why should we even bother?” you ask and will be wrong. Ruby may be a good and rich language, but it is EXTREMELY resources hungry. And that’s the reason we need nginx. It will serve static files, taking load off of Ruby. It may also be a good practice to use varnish between nginx and moebooru, but making a proper config for it is a hard task so I will leave it for later. We found out why we need nginx - now let’s install it:
So we have finished dealing with dependencies - let’s proceed with the installation of moebooru itself!
Part 4: moebooru
We have finished with the dependencies on the previous step, but there are still some packages that should be installed for moebooru to work properly.
Let me explain:
build-essential- a meta-package that installs various tools and libraries necessary for program (mostly C++ and Perl) compilation and interpretation.
libxml2- library that is required for XML support. It is necessary for moebooru’s external API to work.
libxslt1- extension of libxml that allows better xml parsing and converting.
libpq-dev- library that is necessary to build postgres connection module for ruby.
git- version control system - we will use it for moebooru installation and updating.
jhead- image processing tool that extracts EXIF information from image files.
libgd2-noxpm- an image processing library.
libgs2-noxpm-dev- an extension for compiling GD2 support for applications.
imagemagick- collection of tools for image processing
This will also install a whole lot of dependencies. After that run
gem install bundler to make one last step of preparation. Now let’s switch to the non-root user that we added to the rvm group earlier and continue with the installation.
config/database.yml accordingly to what you executed in part 2 and
config/local_config.rb as you wish.
config/local_config.rb is well commented so I don’t see a point in explaining it. All that’s left is to create some directories necessary to run moebooru and kick the installer.
I would not provide example output of these commands because it is huge (more than 2 1200x1920 screens on 8px font). Here’s the paste with it, though.
/etc/nginx/nginx.conf to your liking, but minding the following parameters:
We’re almost there. Let’s create moebooru config for nginx. In this installation nginx configs are at the directory
/etc/nginx/conf.d/, but in your case it might be different.
You can leave it as it is, only changing the directory with the moebooru installation. Now last two steps:
Aaaaahhh… Feels good, right?
Hope you liked this as much as I did. I did not cover init script here, but it’s relatively easy to write it so I leave it to your imagination to come up with it. Enjoy and have fun!