Commit Graph

20 Commits

Author SHA1 Message Date
evazion
4d9028f1fd docker: switch Ruby memory allocator to Jemalloc.
Switch the Ruby memory allocator from Glibc malloc to Jemalloc. Jemalloc
supposedly uses less memory than Glibc malloc because it's better at
handling memory fragmentation. It also has detailed internal statistics
to help monitor allocator behavior.

We use the LD_PRELOAD method of loading Jemalloc instead of building it
into Ruby so that we can switch allocators at runtime.
2021-12-19 03:44:59 -06:00
evazion
c1a37d9577 docker: set MALLOC_ARENA_MAX=2.
Setting MALLOC_ARENA_MAX=2 is claimed to reduce memory bloat caused by
fragmentation. Jemalloc 3.x is also claimed to reduce memory bloat, but
modern distros only ship Jemalloc 5.x, and supposedly only 3.x works.

https://devcenter.heroku.com/articles/tuning-glibc-memory-behavior
https://bugs.ruby-lang.org/issues/14718
https://www.speedshop.co/2017/12/04/malloc-doubles-ruby-memory.html
https://www.joyfulbikeshedding.com/blog/2019-03-14-what-causes-ruby-memory-bloat.html
2021-11-28 22:45:50 -06:00
evazion
206a4b5de5 docker: avoid rebuilding CSS/JS assets on every commit.
Restructure the Dockerfile and the CSS/JS files so that we only rebuild
the CSS and JS when they change, not on every commit.

Before it took several minutes to rebuild the Docker image after every
commit, even when the JS/CSS files didn't change. This also made pulling
images slower.

This requires refactoring the CSS and JS to not use embedded Ruby (ERB)
templates, since this made the CSS and JS dependent on the Ruby
codebase, which is why we had to rebuild the assets after every Ruby
change.
2021-10-13 02:48:30 -05:00
evazion
f687bb0608 docker: update Postgres client binaries to 14.0.
Update the Postgres client binaries (psql et al) to version 14.0. This
is so they match the server version, and so that pg_amcheck is
available, which was introduced in 14.0.

This requires updating the base image to Ubuntu 21.04 at the same time
because the Postgres repo doesn't support version 14.0 on Ubuntu 20.10.
2021-10-06 08:08:52 -05:00
evazion
3a05b7e832 docker: add less and tini to base image.
Add `less` to the Docker image to fix an issue with running `bin/rails console`.
The console uses Pry[1], which has an issue where it pipes long output
through `less`, but it tries to use the -X option, which is only
supported by GNU less, not Busybox less. There's a open bug about this
in the Pry repo dating back to 2014[2].

Add `tini` and use it as the Docker entrypoint to ensure we forward
signals to child processes and reap zombie children properly. This fixes
an issue where if you ran something like:

  docker run ghcr.io/danbooru/danbooru bash -c 'bin/rails db:test:prepare && bin/rails test'

Then you couldn't use control-C to stop the container. This was because
bash wasn't forwarding signals to its children, and because by default,
programs running as PID 1 ignore SIGINT and SIGTERM. See [3][4] for details.

1: https://github.com/pry/pry
2: https://github.com/pry/pry/issues.1248
3: https://github.com/krallin/tini/issues.8
4: https://gist.github.com/StevenACoffman/41fee08e8782b411a4a26b9700ad7af5#dont-run-pid-1
2021-09-22 02:52:36 -05:00
evazion
ff9a520e29 docker: update Ruby to 2.7.4, FFmpeg to 4.4. 2021-09-14 05:39:18 -05:00
evazion
3d660953d4 Add MediaMetadata model.
Add a model for storing image and video metadata for uploaded files.

Metadata is extracted using ExifTool. You will need to install ExifTool
after this commit. ExifTool 12.22 is the minimum required version
because we use the `--binary` option, which was added in this release.

The MediaMetadata model is separate from the MediaAsset model because
some files contain tons of metadata, and most of it is non-essential.
The MediaAsset model represents an uploaded file and contains essential
metadata, like the file's size and type, while the MediaMetadata model
represents all the other non-essential metadata associated with a file.

Metadata is stored as a JSON column in the database.

ExifTool returns all the file's metadata, not just the EXIF metadata.
EXIF is one of several types of image metadata, hence why we call
it MediaMetadata instead of EXIFMetadata.
2021-09-08 05:00:54 -05:00
evazion
8aa7608816 github: add docker build workflow action.
Add an action to build a Docker image and push it to the Github Packages
registry.
2021-09-03 23:23:00 -05:00
evazion
f198a52f9e nokogiri: use bundled libxml2.
Make nokogiri use the bundled version of libxml2 instead of the system
version. In the past installing nokogiri was slow because it had to
compile the bundled version of libxml2, which is partly why we switched
to the system library. Now it's faster because the bundled version comes
pre-compiled with the nokogiri gem.

https://nokogiri.org/#native-gems-faster-more-reliable-installation

Reverts 440bbbb28.
2021-09-02 01:58:11 -05:00
evazion
ca34d502c8 docker: include git hash in Docker image.
Put the Git hash of the current commit inside the Docker image built by
Docker Hub. The hash is stored in the REVISION file in the root directory.
2021-05-02 17:40:12 -05:00
evazion
55129b1819 Rework Dockerfile.
* Optimize Dockerfile to minimize size of the Docker image.
* Specify exact versions of important dependencies (Ruby, Node, Vips) to
  ensure our dependencies are up to date and locked to known versions.
* Install Vips from source because the version that ships with Ubuntu is too old.
* Install FFmpeg from source because otherwise using the Ubuntu package
  pulls in tons of video libraries we don't need, bloating the image.
2021-03-29 06:00:37 -05:00
evazion
1a8c70f5ff config: auto generate secret key if none given.
Automatically generate a random secret key for `Danbooru.config.secret_key_base`
if no key is specified.

This so that you can run Danbooru in a Docker container with zero
configuration.

This removes support for the ~/.danbooru/secret_token file and the
SECRET_TOKEN environment variable. If you used either one of these, you
must copy the value either to DANBOORU_SECRET_KEY_BASE in .env.local, or to
`secret_key_base` in config/danbooru_local_config.rb.

   # .env.local
   DANBOORU_SECRET_KEY_BASE=<value>

   # config/danbooru_local_config.rb
   def secret_key_base
      # <value>
   end
2021-03-23 03:11:41 -05:00
evazion
3be72bdb3b Upgrade to Yarn 2. 2021-03-01 00:39:47 -06:00
evazion
9a0a988572 tests: fix test breakage in Github CI.
Fix tests not working in Github. They were failing because the latest
version of Webpack needs a version of Node newer than the version in
shipped Ubuntu 20.04.

Also fix the Docker build failing because of the system timezone
database not being installed in Ubuntu 20.10.
2021-02-05 03:40:16 -06:00
bipface
7546198fcc fix Dockerfile.danbooru
bundle path was getting lost when switching user
2021-02-03 00:25:59 +11:00
evazion
440bbbb288 Update nokogiri gem.
Fix gem version conflicts described in 20abd8a5f. Nokogiri couldn't be
upgraded past 1.10.9 because 1.11.0 causes a build failure in Nokogumbo
2.0.2, but we couldn't stay on 1.10.9 either because it has a hard
requirement on Ruby <2.7 and we require Ruby >=2.7. This made `bundle
update` fail with a Gemfile conflict.

The fix is to disable libxml2 support when building Nokogumbo. Nokogumbo
wants to use the same version of libxml2 as Nokogiri, but Nokogiri
1.11.0 changed how it reports which version of libxml2 it's using, which
causes Nokogumbo's build to fail. Disabling libxml2 may reduce
performance of Nokogumbo ([1]).

While we're at it, we also make Nokogiri use the system version of
libxml2 instead of its own bundled version. Nokogiri really wants
us to use its own patched version of libxml2 instead of the system
version, but the patches it applies look relatively minor and don't seem
relevant to us ([2]). Using the system version reduces build time during CI.

This adds libxml2 and libxslt as OS-level dependencies of Danbooru. You
may need to do `sudo apt-get install libxml2-dev libxslt-dev` to install
these libraries after this commit.

[1]: https://github.com/rubys/nokogumbo#flavors-of-nokogumbo
[2]: https://github.com/sparklemotion/nokogiri/tree/master/patches/libxml2
2020-06-19 02:27:15 -05:00
evazion
5e63a7cf77 Add test workflow. 2020-06-10 17:52:13 -05:00
evazion
8b5b320be7 docker: fix file permission problems.
Store the app in /home/danbooru/app instead of in /app so that we have
permission to write inside the app dir. /app was owned by root, which
prevented the danbooru user from writing to it.
2020-06-09 17:50:47 -05:00
evazion
3033bb4530 Update danbooru Dockerfile.
Split into build stage and runtime stage to reduce image size.
2020-06-09 01:07:42 -05:00
evazion
6d78d22571 Update docker test configuration. 2020-06-07 17:14:41 -05:00