summaryrefslogtreecommitdiff
path: root/doc/deploy/README.md
blob: 413e43754a7a448425b4ad56dbfd97dded8ea367 (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
## Packages

Last updated: Roughly March 30, 2022
Assumption: Ubuntu 21.04.

```shell
# ElasticSearch repo
wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo gpg --dearmor -o /usr/share/keyrings/elasticsearch-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/elasticsearch-keyring.gpg] https://artifacts.elastic.co/packages/8.x/apt stable main" | sudo tee /etc/apt/sources.list.d/elastic-8.x.list

# PostgreSQL repo
wget -qO - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -
echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list

apt update
apt upgrade # doesn't hurt

apt install apt-transport-https git build-essential cmake default-jre \
            libcurl4-openssl-dev libicu-dev  libopencv-dev libpq-dev libreadline-dev libxml2-dev \
            libbison-dev libffi-dev libgdbm-dev libncurses5-dev libssl-dev libyaml-dev libmagic-dev \
            gifsicle optipng libjpeg-progs \
            nodejs redis-server nginx postgresql-13 elasticsearch
```

### Custom ffmpeg

Custom ffmpeg is needed because upstream has some bugs with certain image formats - this fork fixes them.

You may want to do this building on a separate box, to avoid polluting production with everything `apt build-dep ffmpeg` will pull in.

```shell
# uncomment the deb-src lines in /etc/apt/sources.list

apt update
apt build-dep ffmpeg
git clone https://github.com/philomena-dev/FFmpeg.git
cd FFmpeg
git checkout release/5.0 # commit 43f43e6290fcacd77e256ae668d9ff8cf10a5551 is known to work

./configure --prefix=/usr/local --disable-xlib --enable-avfilter --enable-gpl --enable-libmp3lame --enable-libvorbis \
            --enable-libvpx --enable-libx264 --enable-libx265 --enable-postproc --enable-pic --enable-pthreads \
            --enable-shared --disable-stripping --disable-static --disable-librtmp --enable-libopus --enable-librsvg \
            --enable-libwebp
make -j$(nproc) # or whatever you like
make install
````

### mediatools

Used by the app for detecting image formats and generating thumbnails.

```shell
git clone https://github.com/Twibooru/mediatools.git
cd mediatools
make && make install
```

### ImageMagick

Ubuntu doesn't package new enough ImageMagick for us. Someone made a handy script called IMEI that will install it for us.

```shell
git clone https://github.com/SoftCreatR/imei
cd imei
./imei.sh
```

## Configuration

### ElasticSearch
Edit `/etc/elasticsearch/elasticsearch.yml` to change memory allocation and such if desired. Production has 64GB of RAM and allocates 8GB to ES.
Also, change `enabled: true` under `xpack.security.http.ssl` to `enabled: false`.

`systemctl enable elasticsearch && systemctl start elasticsearch`
`/usr/share/elasticsearch/bin/elasticsearch-reset-password -a -u elastic` and save the generated password.

### Redis
Defaults are fine

`systemctl enable redis && systemctl start redis`

### PostgreSQL
Edit `/etc/postgresql/12/main/pg_hba.conf`, make sure local users don't need authentication, change the following:

```
# IPv4 local connections:
host    all             all             127.0.0.1/32            md5
# IPv6 local connections:
host    all             all             ::1/128                 md5
```

to look like this:

```
# IPv4 local connections:
host    all             all             127.0.0.1/32            trust # <--- this changed
# IPv6 local connections:
host    all             all             ::1/128                 trust # <--- and this
```

If you are in production, punch your server specs into `https://pgtune.leopard.in.ua/` and use the recommended params.

`systemctl enable elasticsearch && systemctl start elasticsearch`

```shell
su - postgres
createuser twibooru --createdb
```

### Nginx
Copy nginx/nginx.conf to `/etc/nginx/nginx.conf` and nginx/twibooru.conf to `/etc/nginx/conf.d/twibooru.conf` and edit as desired.

If you're behind a reverse proxy over a private network, change the listen host to not be 0.0.0.0 and make sure to setup the NGINX realip module appropriately.

`systemctl enable nginx && systemctl start nginx`

## Ruby
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.8.3**.

`ruby-install ruby 3.1.1`

## App

**Change to the app user**

`su - twibooru`

```shell
cat >> ~/.$(basename $SHELL)rc <<EOF
source /usr/local/share/chruby/chruby.sh
source /usr/local/share/chruby/auto.sh
EOF
exec $SHELL

chruby 3.1.1
gem install bundler falcon
cd ~/twibooru # this is your app install dir
export RAILS_ENV=production # or whatever, development or staging works too.
bundle install
```

copy `config/booru/settings.yml` and `config/booru/secrets.yml` to `config/booru/local/`.

Edit settings.yml as you see fit, edit secrets.yml with secure randomly-generated strings for all the keys, plus the ElasticSearch password you saved earlier.

```shell
bundle exec rake db:setup
bundle exec rake booru:features:enable_defaults
bundle exec rake assets:precompile
foreman start -f Procfile.productiom
```

Hope for the best?

## Updating

`git pull`, `bundle` should be enough.

For major Ruby version updates, try `rm -rf ~/.gem` and `rm -rf ~/.bundle` then `gem install bundler` before that.