diff --git a/Dockerfile b/Dockerfile index 9fa774e..e10bd25 100644 --- a/Dockerfile +++ b/Dockerfile @@ -15,27 +15,49 @@ FROM docker.io/library/ruby:$RUBY_VERSION-slim AS base WORKDIR /rails # Install base packages -RUN apt-get update -qq && \ - apt-get install --no-install-recommends -y curl libjemalloc2 libvips postgresql-client && \ - rm -rf /var/lib/apt/lists /var/cache/apt/archives +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ + apt-get update -qq && \ + apt-get install --no-install-recommends -y curl libjemalloc2 libvips postgresql-client xz-utils imagemagick + +# install prebuilt node binary +ARG TARGETARCH +RUN case "$TARGETARCH" in \ + amd64) NODE_ARCH=x64 ;; \ + arm64) NODE_ARCH=arm64 ;; \ + armhf) NODE_ARCH=armv7l ;; \ + *) echo "Unsupported architecture: $TARGETARCH" && exit 1 ;; \ + esac && \ + curl -o node-v22.16.0-linux-${NODE_ARCH}.tar.xz https://nodejs.org/dist/v22.16.0/node-v22.16.0-linux-${NODE_ARCH}.tar.xz && \ + tar -xJf node-v22.16.0-linux-${NODE_ARCH}.tar.xz && \ + mv node-v22.16.0-linux-${NODE_ARCH} /usr/local/node && \ + rm -rf node-v22.16.0-linux-${NODE_ARCH}.tar.xz # Set production environment ENV RAILS_ENV="production" \ BUNDLE_DEPLOYMENT="1" \ BUNDLE_PATH="/usr/local/bundle" \ - BUNDLE_WITHOUT="development" + BUNDLE_WITHOUT="development" \ + PATH="/usr/local/node/bin:/usr/local/node/lib/node_modules:$PATH" + +RUN --mount=type=cache,target=/root/.npm \ + npm install -g defuddle-cli # Throw-away build stage to reduce size of final image FROM base AS build # Install packages needed to build gems -RUN apt-get update -qq && \ - apt-get install --no-install-recommends -y build-essential git libpq-dev libyaml-dev pkg-config && \ - rm -rf /var/lib/apt/lists /var/cache/apt/archives +RUN --mount=type=cache,target=/var/cache/apt,sharing=locked \ + --mount=type=cache,target=/var/lib/apt,sharing=locked \ + apt-get update -qq && \ + apt-get install --no-install-recommends -y build-essential git libpq-dev libyaml-dev pkg-config # Install application gems COPY Gemfile Gemfile.lock ./ -RUN bundle install && \ +RUN --mount=type=cache,target=/tmp/bundle-cache \ + cp -r /tmp/bundle-cache/* "${BUNDLE_PATH}/" 2>/dev/null || true && \ + bundle install && \ + cp -r "${BUNDLE_PATH}"/* /tmp/bundle-cache/ && \ rm -rf ~/.bundle/ "${BUNDLE_PATH}"/ruby/*/cache "${BUNDLE_PATH}"/ruby/*/bundler/gems/*/.git && \ bundle exec bootsnap precompile --gemfile diff --git a/app/jobs/feed_refresher_job.rb b/app/jobs/feed_refresher_job.rb index 9dac3bd..afdc524 100644 --- a/app/jobs/feed_refresher_job.rb +++ b/app/jobs/feed_refresher_job.rb @@ -1,9 +1,9 @@ class FeedRefresherJob < ApplicationJob queue_as :default - def perform(feed = nil) + def perform(feed: nil) if feed.nil? - Feed.all.each { |f| FeedRefresherJob.perform_later(f) } + Feed.find_each { |f| FeedRefresherJob.perform_later(feed: f) } else feed.refresh! end diff --git a/config/application.rb b/config/application.rb index b432fc9..864917c 100644 --- a/config/application.rb +++ b/config/application.rb @@ -44,7 +44,7 @@ class Application < Rails::Application config.good_job.cron = { feed_refresh: { # each recurring job must have a unique key cron: "every 3 hours", # cron-style scheduling format by fugit gem - class: "FeedRefreshJob", # name of the job class as a String; must reference an Active Job job class + class: "FeedRefresherJob", # name of the job class as a String; must reference an Active Job job class description: "Refreshed feeds and creates new entries", # optional description that appears in Dashboard, enabled_by_default: -> { Rails.env.production? } # Only enable in production, otherwise can be enabled manually through Dashboard }