Last active
January 10, 2019 08:19
-
-
Save tomohiro/d727b161fd3b9f6fe96dd9da23a01833 to your computer and use it in GitHub Desktop.
(Experimental) Ruby Container size reducing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM ruby:2.6.0-slim-stretch | |
RUN set -ex \ | |
&& apt-get update -qq && apt-get install -y --no-install-recommends \ | |
build-essential=12.3 \ | |
libxml2-dev=2.9.4+dfsg1-2.2+deb9u2 \ | |
libxslt1-dev=1.1.29-2.1 \ | |
libsqlite3-dev=3.16.2-5+deb9u1 \ | |
&& apt-get clean \ | |
&& apt-get autoclean \ | |
&& rm -rf /var/lib/apt/lists/* | |
WORKDIR /usr/src/app | |
COPY Gemfile . | |
COPY Gemfile.lock . | |
RUN gem update bundler | |
RUN bundle install --frozen --jobs=4 --clean | |
COPY . . | |
CMD ["ruby", "./url.rb"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Build for install dependency RubyGems | |
FROM ruby:2.6.0-stretch AS bundle | |
COPY Gemfile . | |
COPY Gemfile.lock . | |
RUN gem update bundler | |
RUN bundle install --frozen --jobs=4 --clean | |
# Build for run the Ruby | |
FROM ruby:2.6.0-slim-stretch | |
COPY --from=bundle /usr/local/bundle /usr/local/bundle | |
RUN set -ex \ | |
&& apt-get update -qq && apt-get install -y --no-install-recommends \ | |
libxml2=2.9.4+dfsg1-2.2+deb9u2 \ | |
libxslt1.1=1.1.29-2.1 \ | |
libsqlite3-0=3.16.2-5+deb9u1 \ | |
&& apt-get clean \ | |
&& apt-get autoclean \ | |
&& rm -rf /var/lib/apt/lists/* | |
WORKDIR /usr/src/app | |
COPY . . | |
CMD ["ruby", "./url.rb"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source "https://rubygems.org" | |
gem "sqlite3" | |
gem "nokogiri" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
GEM | |
remote: https://rubygems.org/ | |
specs: | |
mini_portile2 (2.4.0) | |
nokogiri (1.10.0) | |
mini_portile2 (~> 2.4.0) | |
sqlite3 (1.3.13) | |
PLATFORMS | |
ruby | |
DEPENDENCIES | |
nokogiri | |
sqlite3 | |
BUNDLED WITH | |
2.0.1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'sqlite3' | |
require 'nokogiri' | |
require 'open-uri' | |
URLS = [ | |
'https://www.google.co.jp', | |
'https://www.apple.com' | |
] | |
# Initialize Database | |
db = SQLite3::Database.new 'test.db' | |
db.results_as_hash = true | |
db.execute('CREATE TABLE urls (id INTEGER PRIMARY KEY, url TEXT, title TEXT);') | |
# Create site information from URL list | |
URLS.each do |url| | |
html = Nokogiri::HTML(open(url)) | |
title = html.search('title').text | |
db.execute('INSERT INTO URLS (url, title) values (?, ?)', url, title) | |
end | |
# Show URL information | |
db.execute('SELECT * FROM urls') do |row| | |
puts "ID: #{row['id']} | #{row['url']} | #{row['title']}" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Compare
Build
Result
Large:
Small: