-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rb
78 lines (62 loc) · 2 KB
/
main.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# frozen_string_literal: true
require 'thor'
require 'git'
require 'fileutils'
# WIP WIP WIP
class Main
class << self
NAME = 'ruby'
URI = "https://github.com/docker-library/#{NAME}.git"
DIRECTORY = './tmp/'
def clone_source
Git.clone(URI, NAME, path: './tmp/', depth: 1)
end
def call
begin
FileUtils.remove_dir('./tmp')
rescue StandardError
Errno::ENOENT
end
clone_source
Dir.chdir(File.join(DIRECTORY, NAME)) do
Replace.new.in_project
end
Replace.new.root
end
end
end
# WIP WIP WIP
class Replace < Thor
include Thor::Actions
def in_project
puts `cp '.travis.yml' '../../'`
insert_into_file 'Dockerfile-slim.template',
"\t\tlibjemalloc-dev \\\n",
after: "libgdbm3 \\\n"
insert_into_file 'Dockerfile-slim.template',
"\t\t--with-jemalloc \\\n",
after: "--enable-shared \\\n"
append_file 'Dockerfile-slim.template', <<~RUBY
# Sanity check for jemalloc
RUN ruby -r rbconfig -e "abort 'jemalloc not enabled' unless RbConfig::CONFIG['LIBS'].include?('jemalloc')"
RUBY
puts `PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH" ./update.sh`
end
def root
insert_into_file '.travis.yml',
<<~YAML,
- bundle install
- bundle exec ruby main.rb
- cd ./tmp/ruby/
#
YAML
after: "before_script:\n"
# Only build slim builds for now
comment_lines '.travis.yml', /VARIANT=/
uncomment_lines '.travis.yml', /VARIANT=.*\/slim$/
# Skip Ruby 2.6-rc until jemalloc fix is released
comment_lines '.travis.yml', /VERSION=2\.6-rc/
end
end
Main.call
# Test: cd tmp/ruby/; export VERSION=2.5 VARIANT=stretch/slim; cd "$VERSION/$VARIANT"; export slash='/'; image="jemalloc/ruby:${VERSION}-${VARIANT//$slash/-}"; docker build -t "$image" .