summaryrefslogtreecommitdiff
path: root/README.md
blob: af19c3fa9aa794ac4c87ec9e0fb1a5fb3f6a1425 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
# twibooru-on-rails
If you're reading this, may the gods have mercy 'pon you.

Ignore almost everything below this line. It's wrong.

## Installation (Easy mode - For development environments)
#### Prerequisites
 * Latest version of VirtualBox and the VM Extension Pack ([download](https://www.virtualbox.org/wiki/Downloads))
 * Latest version of Vagrant ([download](https://www.vagrantup.com))

#### Installation
1. Download and install the prerequisites
2. Open Command Prompt/Terminal and run the following commands:
   ```
   vagrant plugin install vagrant-hostmanager
   vagrant plugin install vagrant-vbguest
   ```
3. Download and extract the repo
4. `cd` into the repo using Command Prompt/Terminal
5. Run the following command:
     `vagrant up`
5. This would be a good time to rewatch your favorite "PONIES The Anthology" installment, cook & have breakfast/lunch/dinner, walk the dog, clean your room, etc.<br>
   By the time you get back the install will surely have completed.<sup>1</sup>
6. ???
7. Profit!

<sub><sup>1</sup> If the install did not finish by the time an activity is complete please select another activity to avoid crippling boredom.</sub>

Some Bash scripts are provided in the `vagrant` directory for your convenience. You can use `vagrant/restart`, `vagrant/stop`, `vagrant/start` and `vagrant/status` from the project root directory to manage the systemd service within the container. Likewise, `vagrant/migrate` and `vagrant/rollback` can be used to run or roll back database migrations, respectively.

If you run into any other issues or need direct command line access you can use `vagrant ssh` to log into the virtual environment's shell and run any commands you deem necessary.

## Installation and requirements (Hard mode - For production, servers)
You should be able to install from top to bottom

#### OS
* Linux (Debian stretch or newer, Ubuntu 18.04 will work)

#### Packages
##### Root install commands
```bash
# Add repositories and keys
apt-get update; apt-get -qq -y install apt-transport-https
echo "deb http://deb.debian.org/debian stretch-backports main" > /etc/apt/sources.list.d/stretch-backports.list
echo "deb https://artifacts.elastic.co/packages/6.x/apt stable main" > /etc/apt/sources.list.d/elasticsearch-6.x.list
echo "deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main" > /etc/apt/sources.list.d/pgdg.list
echo "deb https://deb.nodesource.com/node_12.x stretch main" > /etc/apt/sources.list/nodesource.list
wget -qO - https://packages.elastic.co/GPG-KEY-elasticsearch | apt-key add -
wget -qO - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
wget -qO - https://deb.nodesource.com/gpgkey/nodesource.gpg.key | apt-key add -

# Install dependencies
apt-get update
apt-get install elasticsearch ffmpeg gifsicle git libcurl4-openssl-dev \
  libicu-dev libjpeg-progs libopencv-dev libpq-dev libreadline-dev libxml2-dev \
  nodejs optipng libgit2-27 redis-server postgresql-11 nginx libbison-dev \
  libffi-dev libgdbm-dev libncurses5-dev libssl-dev libyaml-dev

# Configure PostgreSQL
sed -i -e 's/md5/trust/' /etc/postgresql/11/main/pg_hba.conf
service postgresql restart
sudo -u postgres createuser -s $APP_USER

# Configure Elasticsearch
# Set this to whatever you think is reasonable
sed -i -e 's/\(-Xm[sx]\)1g/\1256m/' /etc/elasticsearch/jvm.options
systemctl enable elasticsearch
systemctl start elasticsearch

# Follow the instructions at <https://ryanbigg.com/2014/10/ubuntu-ruby-ruby-install-chruby-and-you>
# to install chruby and ruby-install, using chruby 0.3.9 and ruby-install 0.7.0.
# Append these lines into ~/.bashrc for $APP_USER:
#   source /usr/local/share/chruby/chruby.sh
#   source /usr/local/share/chruby/auto.sh

# Then install ruby as follows:
ruby-install ruby 2.6.3

# You will need to manually configure nginx. Usually this is done by
# copying or symlinking config/nginx.conf.example into /etc/nginx/conf.d/.
#
# Then, run
systemctl enable nginx
systemctl start nginx
```

##### User install commands
```bash
# Install and configure the bundler gem
gem install bundler
bundler config github.https true

# Enter the app directory
cd $APP_DIR

# Run bundler
bin/bundle install

# Run setup
bin/setup
```

##### Compiling tools (needed for Ruby compilation and gems)
* GCC
* Make

##### Image processing
* ImageMagick (6.7 or greater)
* gifsicle (1.64 or greater)
* optipng
* jpegtran (libjpeg-progs)
* Inkscape (for SVG rendering)
* libopencv-dev (below 3, for dedupe)
* ffmpeg (for WebMs)

##### General
* Development headers for: libxml, libxslt, zlib1g, openssl (required for Ruby and Nokogiri gem; packages end in -dev)
* node.js (8 or greater, for script compilation)
* libicu-dev (for character conversion)
* curl.h (required by Patron gem; libcurl4-openssl-dev and similar provide)
* libreadline-dev (required for Ruby)
* curl
* Java runtime environment (default-jre-headless; required for Elasticsearch)
* libgit2 (27; instructions [here](https://github.com/libgit2/libgit2), use /usr for install path)

#### Services
* Elasticsearch (6.0 or newer)
* PostgreSQL (9.6 or newer)
* Redis (redis-server)
* nginx >1.6 (nginx)

#### Ruby
* Using `chruby`, [install](http://ryanbigg.com/2014/10/ubuntu-ruby-ruby-install-chruby-and-you) the version of Ruby specified in *.ruby-version*.

#### Gems
* Bundler gem (`gem install bundler`)
* `bundler config github.https true`

## Setup
### Services autostart
* `sudo systemctl start postgresql elasticsearch redis`

### PostgreSQL
#### User creation
* `sudo -u postgres createuser $APP_USER`

#### Localhost access
* In `/etc/postgresql/<version>/main/pg_hba.conf`, change ```md5``` on both lines to ```trust```
```
host    all             all             127.0.0.1/32            md5
host    all             all             ::1/128                 md5
```
* One-liner: `sed -i -e 's/md5/trust/' /etc/postgresql/11/main/pg_hba.conf`

### Installation
* `git clone [email protected]:derpibooru/derpibooru.git`
* `cd derpibooru`
* Replace the default nginx site configuration (*/etc/nginx/sites-enabled/default*) with *config/nginx.conf.example*.
Remember to adjust it if your app is somewhere other than */home/derpibooru*.
* `./bin/setup`

You can rerun `./bin/setup` whenever you need to reset your environment.    
If setup is failing (particularly on schema loading), you can do:
* `rake db:drop`
* `rake db:create`
* `rake db:schema:load`
* `rake db:seed DEV_SEED='y'`

## Configuring serving endpoints
The default configuration serves all content locally.

In config/booru/settings.yml:
```yml
# What's your public hostname? Used in creating email links
public_host: ''
# Where is your site? No trailing slash.
public_url_root: ""
# Where is your CDN root? Set this to an Amazon CloudFront distribution domain or CNAME origined at the public_url_root,
# or just set this to the same as public_url_root if you're not using CloudFront or a similar CDN. No trailing slash.
cdn_url_root: ""
# Where are images located? Match this with your nginx configuration; normally should be "/path" on your CDN,
# with no trailing slash.
image_url_root: "/img"
```

## Testing
`rails test`

## Deployment
You need a key installed on the server you target, and the git remote installed in your ssh configuration.

    git remote add production derpibooru@<serverip>:derpibooru/

The general syntax is:

    git push production master

And if everything goes wrong:

    git reset HEAD^ --hard
    git push -f production master

(to be repeated until it works again)