Commit Graph

10633 Commits

Author SHA1 Message Date
evazion
c183237b6b docker: update docker-compose file.
* Listen on port 3000 instead of port 80. Port 80 is prone to conflicts
  with other webservers.

* Use the production version of the Danbooru Docker image. It's less
  likely to have bugs than master.

* Fix the autoinstall script to work with `curl ... | sh`.

* Lower PUMA_WORKERS to 1 to reduce memory usage.
2021-09-24 08:40:33 -05:00
evazion
463e6d7b49 artists: fix deadlock when banning artists.
Caused by d854bf6b. Banning an artist would deadlock because it was
performed in a transaction, which didn't work with the `parallel_each`
inside the "create an implication to banned_artist" step.
2021-09-24 08:40:33 -05:00
evazion
9d62f71cd9 ci: prevent running multiple Docker builds at once. 2021-09-24 08:40:33 -05:00
evazion
e8a09bc400 js: fix eslint warnings. 2021-09-24 08:40:33 -05:00
evazion
dd9c4dd04a Fix #4846: Codeclimate integration broken 2021-09-24 07:46:00 -05:00
evazion
74b03a7bd0 posts: fix incorrect exif rotation for PNGs.
Fix a bug where where PNG images could be incorrectly detected as
exif-rotated. This would happen when a PNG contained the
IFD0:Orientation flag. It's technically possible for a PNG to contain
this flag, but it's ignored by libvips and by browsers.

post #3762340 (nsfw) is an example of a PNG like this.

The fix is to use `autorot` to let libvips apply the rotation instead of
trying to interpret the exif data ourselves. Note that libvips-8.9 has a
bug where it doesn't strip the orientation flag after applying
`autorot`, which leads to the image being incorrectly rotated a second
time when generating the thumbnail. Use libvips-8.11 instead.
2021-09-23 00:10:00 -05:00
evazion
9c0ab258cb Upgrade libvips to 8.11.3. 2021-09-22 23:56:59 -05:00
evazion
e7a455ea44 Merge pull request #4884 from nonamethanks/remove_long_image
Posts: stop autotagging long_image
2021-09-22 23:09:08 -05:00
GlassedSilver
0dd77b0f7f Bump Ruby to 3.0.2 in INSTALL.debian 2021-09-22 23:02:13 -05:00
evazion
ee5cd8330d uploads: fix exception when pruning expired uploads.
Hourly pruning of expired uploads was failing because of nil deference
errors in `media_asset.destroy!`. There are various cases where an
upload doesn't have a media asset, for example when the source url
fails to download or when the upload is of an invalid filetype.
2021-09-22 13:24:27 -05:00
evazion
259e3fde68 ci: fix issue with betabooru deploy workflow.
Just trigger on pushes to the betabooru branch instead of on the Docker
image being built. The workflow_run event keeps triggering on the master
branch even though it's supposed to only trigger on the betabooru
branch. This makes it fail because it doesn't have access to the secrets
in the betabooru environment.

This does mean the deploy will fail if the image hasn't been previously
built by a push to master first.
2021-09-22 12:33:42 -05:00
evazion
6740ef17ab posts: fix detection of exif_rotation tag.
`IFD0:Orientation` is the orientation of the main image.
`IFD1:Orientation` is the orientation of the embedded thumbnail, if it
has one. Using `IFD1:Orientation` was incorrect here because some images
have a non-rotated main image but a rotated thumbnail. Post #1023563 is
an example.
2021-09-22 11:17:28 -05:00
evazion
b378785582 Fix #3692: Rotate pictures based on metadata
Rotate the image based on the EXIF orientation flag when generating
thumbnails and samples.

Also fix the width and height to be calculated correctly for rotated
images. Vips gives us the unrotated width and height of the image; we
have to detect whether the image is rotated and swap the width and
height manually to correct them. For example, if an image with the
"Rotate 90 CW" flag is 100x500 before rotation, then after rotation it's
500x100. This should fix #4883 (Exif rotation breaks Javascript fit-to-window)

We also have to fix it so that regenerating a post updates the width and
height of the post, in the event that it's a rotated image.

Finally we set `image-orientation: from-image;` even though it's
probably not necessary.
2021-09-22 11:12:50 -05:00
evazion
9b6c429d4c ci: automatically deploy betabooru on push.
Make it so that on every push to the `betabooru` branch, the latest
commit is automatically deployed to https://betabooru.donmai.us.
2021-09-22 09:31:26 -05:00
evazion
52f3c22173 rake: clean up rake tasks.
* Make danbooru:images:validate task run in parallel.
* Remove task for regenerating thumbnails.
* Move all rake tasks into same file.
* Add usage instructions.
2021-09-22 05:36:22 -05:00
evazion
d2ba355371 Remove unused SimpleForm scaffold template. 2021-09-22 04:52:29 -05:00
evazion
ac12efb636 tests: fix test failures when running without API keys.
Fix the test suite failing when trying to run it in the default state
with no config file or API keys configured. Most source sites require
API keys or login credentials to be set in order to work. Skip these
tests when credentials aren't configured.
2021-09-22 04:33:36 -05:00
nonamethanks
ce8c8e1ab7 Posts: stop autotagging long_image 2021-09-22 11:16:52 +02: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
8738d8a645 Remove deletion appeal thread updater.
It was already disabled before, remove it completely now.
2021-09-22 01:57:45 -05:00
evazion
28d2753c53 BURs: don't allow builders to edit or reject BURs by other users.
Only admins can edit or reject BURs by other users now. The BUR creator
can still edit or reject their own BURs.
2021-09-22 00:34:44 -05:00
evazion
5af21f03de versions: default ARCHIVE_DATABASE_URL to DATABASE_URL.
Make it so that when ARCHIVE_DATABASE_URL isn't set, it defaults to
DATABASE_URL. In other words, if you don't have a separate archive
database configured, then default to using the main database for
post/pool versions.

Fixes an issue where running the test suite would fail if you didn't
explicitly set ARCHIVE_DATABASE_URL because it tried to use
`archive_test` as the post/pool versions database name.
2021-09-22 00:34:28 -05:00
evazion
d953ca694c docker: remove docker-compose.test.yaml
This was previously used to run the test suite with Docker Compose under
CircleCI. We no longer use this since switching to Github Actions.
2021-09-21 21:35:45 -05:00
evazion
3a0614bb55 db: recreate post versions and pool versions tables.
Add the post and pool versions tables back. Currently only used by the
test suite to make it easier to run. Not yet used for production.
2021-09-21 12:35:46 -05:00
evazion
c69ba54b5a Fix #4442: Autotag image metadata.
Autotag `greyscale`, `non-repeating_animation`, and `exif_rotation`.

Note that this does not detect all (or even most) greyscale images.
Artists often save greyscale images as RGB instead of as greyscale.
2021-09-21 11:18:06 -05:00
evazion
d5981754c4 posts: automatically tag animated_gif & animated_png on tag edit.
Automatically tag animated_gif and animated_png when a post is edited.
Add them back if the user tries to remove them from an animated post,
or remove them if the user tries to add them to a non-animated post.

Before we added these tags at upload time, but it was possible for users
to remove them after upload, or to incorrectly add them to non-animated
posts. They were added at upload time because we couldn't afford to open
the file and parse the metadata on every tag edit. Now that we save the
metadata in the database, we can do this.

This also makes it so you can't tag ugoira on non-ugoira files.

Known bug: it's possible to have an animated GIF where every frame is
identical. Post #3770975 is an example. This will be detected as an
animated GIF even though visually it doesn't appear to be animated.

Fixes #4041: Animated_gif tag not added to preprocessed uploads
2021-09-21 08:26:02 -05:00
evazion
4d0580b160 MediaFile: remove old libvips compatibility code.
Remove code for working with older versions of libvips. This makes
libvips 8.10+ a hard requirement. Older versions were already broken and
failed certain tests in the test suite.
2021-09-21 07:47:48 -05:00
evazion
ae7d964bf1 MediaFile: replace APNGInspector with ExifTool.
Replace our own handwritten APNG parser with ExifTool. This makes
ExifTool a hard requirement for handling APNGs.
2021-09-21 07:47:45 -05:00
evazion
273be55de8 Upgrade to Ruby 3.0.2. 2021-09-21 02:56:23 -05:00
evazion
c6bf3e7934 BURs: don't automatically retry failed BURs.
If a bulk update job fails, don't automatically retry it. Retrying it
will clobber the original error message if it fails again.
2021-09-20 16:33:23 -05:00
evazion
1d8a3bf09f BURs: allow failed BURs to be reapproved.
Fix it so that you can reapprove a failed BUR to run it again. Before
this would fail because it would end up trying to create the aliases
or implications again, which would fail because they already existed.
Now it ignores when an alias or implication already exists. It will
however finish tagging the posts if they haven't been fully moved.
2021-09-20 16:29:38 -05:00
evazion
0fed4b557b Remove Unicorn.
No longer used now that we use Puma in production. If you still used
Unicorn in your install, switch to `bin/rails server` instead. See
config/puma.rb for config settings.
2021-09-20 06:17:57 -05:00
evazion
68769c7c3b Remove Capistrano.
No longer used now that we use Kubernetes to deploy the site instead of
Capistrano.

If you run your own installation of Danbooru, and you used Capistrano to
deploy your site, it is recommended that you switch to either the Docker
Compose file (for personal installs), the Procfile (for non-Dockerized,
development environments), or Kubernetes (for production environments;
see https://github.com/danbooru/danbooru-infrastructure/tree/master/k8s
for Danbooru's production configuration).
2021-09-20 04:57:41 -05:00
evazion
b7b6797b18 tests: skip weibo tests in CI.
Weibo tests keep failing randomly in CI. Give up and skip them to
prevent them from always marking commits as failed.
2021-09-20 02:17:31 -05:00
evazion
98b3c82ac5 tests: fix deadlock during artist ban test.
The artist ban tests deadlocked because of a weird interaction between
threads and database transactions when tagging posts in parallel. Add a
hack to work around it.
2021-09-20 02:09:14 -05:00
evazion
5995571885 clockwork: add heartbeat task.
Add a cron job that touches a file every minute so we can be sure
clockwork (the cronjob daemon) is still running.
2021-09-20 01:32:12 -05:00
evazion
051f2be93f gems: remove whenever gem.
We're now using the `clockwork` gem for cronjobs in production. See
config/initializers/clockwork.rb.
2021-09-20 01:30:52 -05:00
evazion
65c560c2d7 view components: silence with_variant deprecation warnings. 2021-09-20 01:12:14 -05:00
evazion
d854bf6b53 BURs: update posts in parallel.
When processing an alias, rename, implication, mass update, or nuke,
update the posts in parallel. This means that if we alias foo to bar,
for example, then we use four processes at once to retag the posts from
foo to bar.

This doesn't mean that if we have two aliases in a BUR, we process both
aliases in parallel. It simply means that when processing an alias, we
update the posts in parallel for that alias.
2021-09-20 01:12:14 -05:00
evazion
21f0c2acc3 BURs: add processing and failed states.
When a BUR is approved, put it in a `processing` state. After it
successfully finishes processing, put it in the `approved` state. If it
fails processing, put it in the `failed` state.

If approving the BUR fails with a validation error, for example because
the alias already exists or an implication lacks a wiki, then leave the
BUR in the `pending` state. The `failed` state is only for unexpected
errors during processing.
2021-09-20 01:12:14 -05:00
evazion
9ba84efc07 BURs: process BURs sequentially in a single job.
Change the way BURs are processed. Before, we spawned a background job
for each line of the BUR, then processed each job sequentially. Now, we
process the entire BUR sequentially in a single background job.

This means that:

* BURs are truly sequential now. Before certain things like removing
  aliases weren't actually performed in a background job, so they were
  performed out-of-order before everything else in the BUR.

* Before, if an alias or implication line failed, then subsequent alias
  or implication lines would still be processed. This was because each
  alias or implication line was queued as a separate job, so a failure
  of one job didn't block another. Now, if any alias or implication
  fails, the entire BUR will fail and stop processing after that line.
  This may be good or bad, depending on whether we actually need the BUR
  to be processed in order or not.

* Before, BURs were processed inside a database transaction (except for the
  actual updating of posts). Now they're not. This is because we can't
  afford to hold transactions open while processing long-running aliases
  or implications. This means that if BUR fails in the middle when it is
  initially approved, it will be left in a half-complete state. Before
  it would be rolled back and left in a pending state with no changes
  performed.

* Before, only one BUR at a time could be processed. If multiple BURs
  were approved at the same time, then they would queue up and be
  processed one at a time. Now, multiple BURs can be processed at the
  same time. This may be undesirable when processing large BURs, or BURs
  that must be approved in a specific order.

* Before, large tag category changes could time out. This was because
  they weren't actually performed in a background job. Now they are, so
  they shouldn't time out.
2021-09-20 01:12:14 -05:00
evazion
96c5c346ad ci: allow triggering docker build workflow manually.
Add a `workflow_dispatch` so that it's possible it's possible to trigger
the Docker build workflow manually.

https://github.blog/changelog/2020-07-06-github-actions-manual-triggers-with-workflow_dispatch/
2021-09-18 21:34:28 -05:00
evazion
bc73d47643 Remove .github/stale.yml.
Unused.
2021-09-18 06:01:01 -05:00
evazion
020ed7b735 ci: don't tag short commit hash on Docker images.
Tagging both the long and the short commit hash on images creates too
much clutter in the Github UI.
2021-09-18 05:14:36 -05:00
evazion
52cf13dff1 ci: limit workflow permissions.
Make it so pull requests from outside contributors can't edit workflows
under .github/workflows/ without approval. Also limit workflows to the
minimum permissions necessary.
2021-09-18 04:37:00 -05:00
evazion
39fa2fe02d ci: split docker build workflow from test workflow.
Split up the Github workflow. Instead of one workflow with two jobs, one
to build the Docker image and one to test it, split it into two separate
workflows, one to build and one to test. This way if the Docker build
fails it doesn't try to run the tests, and if the tests fail it only
marks the test workflow as failed, not the entire workflow.

This is especially so the workflows page doesn't show everything as
failing just because the tests failed.

https://github.com/danbooru/danbooru/actions
2021-09-18 01:34:07 -05:00
evazion
cfae1d3b35 Merge pull request #4881 from nottalulah/patch-1
Hide posts not visible to anonymous users from Discord slash commands
2021-09-17 19:18:42 -05:00
evazion
1d4e7ba12f Merge pull request #4855 from nottalulah/lock-moderation
Log mod actions for changes to post locks
2021-09-17 19:06:52 -05:00
Lily
22430f2ec1 Update post_embed.rb 2021-09-17 18:39:56 -03:00
evazion
85d70561e5 rake: change docker build task to buildx. 2021-09-16 02:32:02 -05:00