Is there any way to compile and statically link ru

2020-03-30 08:30发布

UPDATED 6 29 2015:

InfraRuby compiler and runtime for statically typed Ruby on the JVM!


I'd like to have a single binary, statically linked, out of a simple ruby crawler to build a slim docker container.

Something like what Go produces with:

CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .

(from Building Minimal Docker Containers for Go Applications).

Is there a way of doing this with ruby/rails?

1条回答
萌系小妹纸
2楼-- · 2020-03-30 09:02

Why bother? When you create a docker container for your ruby app you are already creating a convenient package for distribution.

I would suggest checking out the ruby and rails official images. During the container build process they will run the gem bundler in order to package dependencies.

Example

Simple ruby script project

├── Dockerfile
├── Gemfile
├── Gemfile.lock
└── helloworld.rb

The image is built as normal

docker build -t my-ruby-app .

And run as follows:

$ docker run --rm my-ruby-app
    __  __     ____                             __    __
   / / / /__  / / /___     _      ______  _____/ /___/ /
  / /_/ / _ \/ / / __ \   | | /| / / __ \/ ___/ / __  / 
 / __  /  __/ / / /_/ /   | |/ |/ / /_/ / /  / / /_/ /  
/_/ /_/\___/_/_/\____/    |__/|__/\____/_/  /_/\__,_/ 

Dockerfile

FROM ruby:2.1-onbuild
CMD ["ruby", "helloworld.rb"]

helloworld.rb

require "artii"

a = Artii::Base.new :font => 'slant'
puts a.asciify('Hello world')

Gemfile

source "https://rubygems.org"

gem "artii"
查看更多
登录 后发表回答