Skip to content

Commit

Permalink
Have docker cache wasmer before installing (#3358)
Browse files Browse the repository at this point in the history
* Have docker cache wasmer before installing

Wasmer has a lot of trouble properly installing
in our Docker environment when we are using deployment
mode. If not deploying, the asset compile can't find
it. So we use deployment mode, but have to cache the wasmer
gem before we do that or we get a git error due, I suspect
due to the gem not being formed properly, but wasn't able to
ascertain the exact reason.

* Update Dockerfile

Co-authored-by: Albert Wang <[email protected]>

Co-authored-by: Albert Wang <[email protected]>
  • Loading branch information
tsmartt and yachtcaptain23 authored Aug 11, 2021
1 parent b263b23 commit 2adb6b0
Show file tree
Hide file tree
Showing 5 changed files with 129 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
logs/
tmp/
node_modules/
storage/

# Ignore bundler config.
/.bundle
Expand All @@ -24,6 +25,8 @@ coverage
/public/c/*
/public/i/*
/public/assets/*
/public/packs-test/
/public/creators-landing/node_modules/

# Ignore node_modules
node_modules/
Expand Down
6 changes: 5 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ RUN apt-get install -y nodejs \

RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y


RUN ["rm", "-rf", "/var/lib/apt/lists/*"]
ENV LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2

SHELL [ "/bin/bash", "-l", "-c" ]

ENV PATH="/root/.cargo/bin:${PATH}"
RUN curl --silent -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash
RUN gem install bundler

Expand All @@ -35,6 +37,9 @@ COPY package.json yarn.lock .nvmrc ./

# Install the dependencies.
RUN nvm install && nvm use
RUN gem install wasmer -v 1.0.0
RUN bundle package --all
RUN bundle config set --local deployment 'true'
RUN bundle check || PATH="/root/.cargo/bin:${PATH}" bundle install --jobs 20 --retry 5
RUN node --version
RUN npm install -g yarn
Expand All @@ -52,4 +57,3 @@ RUN bundle exec rails assets:precompile DB_ADAPTER=nulldb DATABASE_URL='nulldb:/
EXPOSE 3000
ENTRYPOINT [ "./scripts/entrypoint.sh" ]
CMD ["bundle", "exec", "puma", "-C", "config/puma.rb", "-e","${RACK_ENV:-development}"]

10 changes: 5 additions & 5 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ gem "zendesk_api", "~> 1.26.0"

gem 'activerecord-nulldb-adapter', "0.7.0"

gem "wasm-thumbnail-rb", git: 'https://github.com/brave-intl/wasm-thumbnail.git', tag: '0.0.3', glob: 'wasm-thumbnail-rb/*.gemspec'

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby]

group :development do
gem "better_errors"
gem "binding_of_caller"
Expand Down Expand Up @@ -205,8 +210,3 @@ group :development, :test do
gem 'solargraph'
gem 'dotenv-rails', "2.7.6"
end

# Windows does not include zoneinfo files, so bundle the tzinfo-data gem
gem "tzinfo-data", platforms: [:mingw, :mswin, :x64_mingw, :jruby]

gem "wasm-thumbnail-rb", git: 'https://github.com/brave-intl/wasm-thumbnail.git', tag: '0.0.3'
5 changes: 3 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ GIT
remote: https://github.com/brave-intl/wasm-thumbnail.git
revision: 73ae439ee366156fb2353015a9ee5d487502f2a7
tag: 0.0.3
glob: wasm-thumbnail-rb/*.gemspec
specs:
wasm-thumbnail-rb (0.1.0)
wasmer (~> 1.0)
Expand Down Expand Up @@ -112,7 +113,7 @@ GEM
autoprefixer-rails (10.3.1.0)
execjs (~> 2)
aws-eventstream (1.1.1)
aws-partitions (1.483.0)
aws-partitions (1.484.0)
aws-sdk-core (3.119.0)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.239.0)
Expand Down Expand Up @@ -664,4 +665,4 @@ RUBY VERSION
ruby 2.7.3p183

BUNDLED WITH
2.2.15
2.2.25
115 changes: 113 additions & 2 deletions bin/bundle
Original file line number Diff line number Diff line change
@@ -1,3 +1,114 @@
#!/usr/bin/env ruby
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
load Gem.bin_path('bundler', 'bundle')
# frozen_string_literal: true

#
# This file was generated by Bundler.
#
# The application 'bundle' is installed as part of a gem, and
# this file is here to facilitate running it.
#

require "rubygems"

m = Module.new do
module_function

def invoked_as_script?
File.expand_path($0) == File.expand_path(__FILE__)
end

def env_var_version
ENV["BUNDLER_VERSION"]
end

def cli_arg_version
return unless invoked_as_script? # don't want to hijack other binstubs
return unless "update".start_with?(ARGV.first || " ") # must be running `bundle update`
bundler_version = nil
update_index = nil
ARGV.each_with_index do |a, i|
if update_index && update_index.succ == i && a =~ Gem::Version::ANCHORED_VERSION_PATTERN
bundler_version = a
end
next unless a =~ /\A--bundler(?:[= ](#{Gem::Version::VERSION_PATTERN}))?\z/
bundler_version = $1
update_index = i
end
bundler_version
end

def gemfile
gemfile = ENV["BUNDLE_GEMFILE"]
return gemfile if gemfile && !gemfile.empty?

File.expand_path("../../Gemfile", __FILE__)
end

def lockfile
lockfile =
case File.basename(gemfile)
when "gems.rb" then gemfile.sub(/\.rb$/, gemfile)
else "#{gemfile}.lock"
end
File.expand_path(lockfile)
end

def lockfile_version
return unless File.file?(lockfile)
lockfile_contents = File.read(lockfile)
return unless lockfile_contents =~ /\n\nBUNDLED WITH\n\s{2,}(#{Gem::Version::VERSION_PATTERN})\n/
Regexp.last_match(1)
end

def bundler_version
@bundler_version ||=
env_var_version || cli_arg_version ||
lockfile_version
end

def bundler_requirement
return "#{Gem::Requirement.default}.a" unless bundler_version

bundler_gem_version = Gem::Version.new(bundler_version)

requirement = bundler_gem_version.approximate_recommendation

return requirement unless Gem::Version.new(Gem::VERSION) < Gem::Version.new("2.7.0")

requirement += ".a" if bundler_gem_version.prerelease?

requirement
end

def load_bundler!
ENV["BUNDLE_GEMFILE"] ||= gemfile

activate_bundler
end

def activate_bundler
gem_error = activation_error_handling do
gem "bundler", bundler_requirement
end
return if gem_error.nil?
require_error = activation_error_handling do
require "bundler/version"
end
return if require_error.nil? && Gem::Requirement.new(bundler_requirement).satisfied_by?(Gem::Version.new(Bundler::VERSION))
warn "Activating bundler (#{bundler_requirement}) failed:\n#{gem_error.message}\n\nTo install the version of bundler this project requires, run `gem install bundler -v '#{bundler_requirement}'`"
exit 42
end

def activation_error_handling
yield
nil
rescue StandardError, LoadError => e
e
end
end

m.load_bundler!

if m.invoked_as_script?
load Gem.bin_path("bundler", "bundle")
end

0 comments on commit 2adb6b0

Please sign in to comment.