diff --git a/Dockerfile b/Dockerfile index f33cf2b..5d9b6e7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,24 +18,20 @@ RUN \ apk add --no-cache \ ffmpeg \ file \ - icu-libs \ imagemagick \ - libpq \ - libidn \ nodejs \ ruby \ - ruby-bundler \ - yarn && \ + ruby-bundler && \ apk add --no-cache --virtual=build-dependencies \ build-base \ icu-dev \ - libidn-dev \ + libidn-dev \ libpq-dev \ libxml2-dev \ libxslt-dev \ openssl-dev \ - npm \ - ruby-dev && \ + ruby-dev \ + yarn && \ echo "**** install mastodon ****" && \ mkdir -p /app/www && \ if [ -z ${MASTODON_VERSION+x} ]; then \ @@ -49,18 +45,66 @@ RUN \ /tmp/mastodon.tar.gz -C \ /app/www/ --strip-components=1 && \ cd /app/www && \ + # https://github.com/mastodon/mastodon/pull/24702 + sed -En "s/.*\brequire\('([^']+)'\).*/\"\1\"/p" streaming/index.js > streaming-requires.txt && \ + jq --slurpfile requires streaming-requires.txt \ + '{ dependencies: .dependencies | with_entries(select([.key] | inside($requires))) }' \ + package.json > streaming/package.json && \ bundle config set --local deployment 'true' && \ - bundle config set --local without 'development test' && \ + bundle config set --local without 'development test exclude' && \ bundle config set silence_root_warning true && \ - bundle install -j"$(nproc)" && \ - yarn install --pure-lockfile --production && \ + bundle install -j"$(nproc)" --no-cache && \ + yarn install --production --frozen-lockfile --check-files && \ + cd streaming && \ + yarn install --production --check-files && \ OTP_SECRET=precompile_placeholder SECRET_KEY_BASE=precompile_placeholder rails assets:precompile && \ echo "**** cleanup ****" && \ + yarn cache clean && \ apk del --purge \ build-dependencies && \ - yarn cache clean && \ + # Remove assets not needed in runtime because they were compiled & copied to public + rm -r \ + /app/www/app/javascript/fonts \ + /app/www/app/javascript/icons \ + /app/www/app/javascript/packs \ + /app/www/app/javascript/styles && \ rm -rf \ - /tmp/* + # Remove vendored sources for building native extensions. + /app/www/vendor/bundle/ruby/*/gems/hiredis-*/vendor/hiredis \ + /app/www/vendor/bundle/ruby/*/gems/nokogiri-*/gumbo-parser \ + /app/www/vendor/bundle/ruby/*/gems/nokogiri-*/patches \ + /app/www/vendor/bundle/ruby/*/gems/pghero-*/app/assets \ + # Remove build logs, temp files, and cache. + /app/www/vendor/bundle/ruby/*/build_info/ \ + /app/www/vendor/bundle/ruby/*/cache/ \ + /app/www/node_modules/.cache \ + /app/www/tmp/cache \ + $HOME/.bundle/cache \ + $HOME/.composer \ + /tmp/* && \ + find /app/www/vendor/bundle/ruby/*/extensions/ \( -name gem_make.out -o -name mkmf.log \) -delete && \ + # Remove tests, documentations and other useless files. + find /app/www/vendor/bundle/ruby/*/gems/ \( -name 'doc' \ + -o -name 'spec' \ + -o -name 'test' \) \ + -type d -maxdepth 2 -exec rm -fr "{}" + && \ + find /app/www/vendor/bundle/ruby/*/gems/ \( -name 'README*' \ + -o -name 'CHANGELOG*' \ + -o -name 'CONTRIBUT*' \ + -o -name '*LICENSE*' \ + -o -name 'Rakefile' \ + -o -name '.*' \) \ + -type f -delete && \ + # Remove source maps, TS files, docs, tests and other useless files. + find /app/www/streaming/node_modules \( -name '.*' \ + -o -name '*.map' \ + -o -name '*.md' \ + -o -name '*.ts' \ + -o -name 'LICENSE*' \ + -o -name 'Makefile' \ + -o -name 'README*' \) \ + -type f -delete && \ + rm -rf /app/www/streaming/node_modules/*/test COPY root/ / diff --git a/Dockerfile.aarch64 b/Dockerfile.aarch64 index 32b578b..1e5907a 100644 --- a/Dockerfile.aarch64 +++ b/Dockerfile.aarch64 @@ -18,26 +18,22 @@ RUN \ apk add --no-cache \ ffmpeg \ file \ - icu-libs \ imagemagick \ - libpq \ - libidn \ nodejs \ ruby \ - ruby-bundler \ - yarn && \ + ruby-bundler && \ apk add --no-cache --virtual=build-dependencies \ build-base \ gcompat \ icu-dev \ - libidn-dev \ + libidn-dev \ libpq-dev \ libxml2-dev \ libxslt-dev \ openssl-dev \ - npm \ python3-dev \ - ruby-dev && \ + ruby-dev \ + yarn && \ echo "**** install mastodon ****" && \ mkdir -p /app/www && \ if [ -z ${MASTODON_VERSION+x} ]; then \ @@ -51,19 +47,66 @@ RUN \ /tmp/mastodon.tar.gz -C \ /app/www/ --strip-components=1 && \ cd /app/www && \ + # https://github.com/mastodon/mastodon/pull/24702 + sed -En "s/.*\brequire\('([^']+)'\).*/\"\1\"/p" streaming/index.js > streaming-requires.txt && \ + jq --slurpfile requires streaming-requires.txt \ + '{ dependencies: .dependencies | with_entries(select([.key] | inside($requires))) }' \ + package.json > streaming/package.json && \ bundle config set --local deployment 'true' && \ - bundle config set --local without 'development test' && \ + bundle config set --local without 'development test exclude' && \ bundle config set silence_root_warning true && \ - bundle config set force_ruby_platform true && \ - bundle install -j"$(nproc)" && \ - yarn install --pure-lockfile --production && \ + bundle install -j"$(nproc)" --no-cache && \ + yarn install --production --frozen-lockfile --check-files && \ + cd streaming && \ + yarn install --production --check-files && \ OTP_SECRET=precompile_placeholder SECRET_KEY_BASE=precompile_placeholder rails assets:precompile && \ echo "**** cleanup ****" && \ + yarn cache clean && \ apk del --purge \ build-dependencies && \ - yarn cache clean && \ + # Remove assets not needed in runtime because they were compiled & copied to public + rm -r \ + /app/www/app/javascript/fonts \ + /app/www/app/javascript/icons \ + /app/www/app/javascript/packs \ + /app/www/app/javascript/styles && \ rm -rf \ - /tmp/* + # Remove vendored sources for building native extensions. + /app/www/vendor/bundle/ruby/*/gems/hiredis-*/vendor/hiredis \ + /app/www/vendor/bundle/ruby/*/gems/nokogiri-*/gumbo-parser \ + /app/www/vendor/bundle/ruby/*/gems/nokogiri-*/patches \ + /app/www/vendor/bundle/ruby/*/gems/pghero-*/app/assets \ + # Remove build logs, temp files, and cache. + /app/www/vendor/bundle/ruby/*/build_info/ \ + /app/www/vendor/bundle/ruby/*/cache/ \ + /app/www/node_modules/.cache \ + /app/www/tmp/cache \ + $HOME/.bundle/cache \ + $HOME/.composer \ + /tmp/* && \ + find /app/www/vendor/bundle/ruby/*/extensions/ \( -name gem_make.out -o -name mkmf.log \) -delete && \ + # Remove tests, documentations and other useless files. + find /app/www/vendor/bundle/ruby/*/gems/ \( -name 'doc' \ + -o -name 'spec' \ + -o -name 'test' \) \ + -type d -maxdepth 2 -exec rm -fr "{}" + && \ + find /app/www/vendor/bundle/ruby/*/gems/ \( -name 'README*' \ + -o -name 'CHANGELOG*' \ + -o -name 'CONTRIBUT*' \ + -o -name '*LICENSE*' \ + -o -name 'Rakefile' \ + -o -name '.*' \) \ + -type f -delete && \ + # Remove source maps, TS files, docs, tests and other useless files. + find /app/www/streaming/node_modules \( -name '.*' \ + -o -name '*.map' \ + -o -name '*.md' \ + -o -name '*.ts' \ + -o -name 'LICENSE*' \ + -o -name 'Makefile' \ + -o -name 'README*' \) \ + -type f -delete && \ + rm -rf /app/www/streaming/node_modules/*/test COPY root/ /