Skip to content

Commit d6fd224

Browse files
committed
add 'run docker build/push' commands
due to Docker Hub disabling auto builds for the average jo...
1 parent ed7b871 commit d6fd224

File tree

2 files changed

+109
-91
lines changed

2 files changed

+109
-91
lines changed

Runfile

Lines changed: 14 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
require "runfile-tasks"
22
require "byebug"
33
require_relative 'lib/bashly'
4+
require_relative 'helpers/example'
45

56
title "Bashly Developer Toolbelt"
67
summary "Runfile tasks for building the Bashly gem"
@@ -41,99 +42,21 @@ action :examples do
4142
end
4243
end
4344

44-
class Example
45-
class << self
46-
def dirs
47-
@dirs ||= Dir['examples/*'].select { |f| File.directory? f }
48-
end
45+
command :docker
4946

50-
def all
51-
dirs.map { |dir| Example.new dir }
52-
end
53-
54-
def executables
55-
all.map &:executable
56-
end
57-
end
58-
59-
attr_reader :dir
60-
61-
def initialize(dir)
62-
@dir = dir
63-
end
64-
65-
def config
66-
@config ||= YAML.load_file(yaml_path)
67-
end
68-
69-
def yaml
70-
@yaml ||= File.read(yaml_path).strip
71-
end
72-
73-
def yaml_path
74-
"#{dir}/src/bashly.yml"
75-
end
76-
77-
def readme_path
78-
"#{dir}/README.md"
79-
end
80-
81-
def readme
82-
File.read readme_path
83-
end
84-
85-
def test_commands
86-
filename = "#{dir}/test.sh"
87-
result = File.read(filename)
88-
.split(/\s*### Try Me ###\s*/).last
89-
.split("\n")
90-
.reject { |line| line.empty? or line.start_with? '#' }
91-
abort "Can't find ### Try Me ### marker in #{filename}" if result.empty?
92-
result
93-
end
94-
95-
def test_output
96-
result = ''
97-
test_commands.each do |command|
98-
result += "### `$ #{command}`\n\n"
99-
result += "```shell\n"
100-
Dir.chdir dir do
101-
result += `#{command} 2>&1`
102-
result += "\n\n"
103-
end
104-
result += "```\n\n"
105-
end
106-
result
107-
end
108-
109-
def regenerate_readme
110-
File.write readme_path, generated_readme
111-
end
112-
113-
def generated_readme
114-
marker = '-----'
115-
content = readme.split(marker)[0].strip
116-
<<~EOF
117-
#{content}
118-
119-
#{marker}
120-
121-
## `bashly.yml`
122-
123-
```yaml
124-
#{yaml}
125-
```
126-
127-
## Generated script output
128-
129-
#{test_output}
130-
131-
EOF
132-
end
47+
help "Build the docker images"
48+
action :build, :b do
49+
run "docker build -t dannyben/bashly ."
50+
run "docker tag dannyben/bashly dannyben/bashly:#{Bashly::VERSION}"
51+
run "docker images |grep bashly"
52+
end
13353

134-
def executable
135-
"#{dir}/#{config['name']}"
136-
end
54+
help "Push the docker images to Docker Hub (since autobuilds are only for the rich and famous...)"
55+
action :push, :p do
56+
run "docker push dannyben/bashly"
57+
run "docker push dannyben/bashly:#{Bashly::VERSION}"
13758
end
13859

60+
endcommand
61+
13962
require './debug.rb' if File.exist? 'debug.rb'

helpers/example.rb

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
# A helper class used in Runfile to generate example README files
2+
class Example
3+
class << self
4+
def dirs
5+
@dirs ||= Dir['examples/*'].select { |f| File.directory? f }
6+
end
7+
8+
def all
9+
dirs.map { |dir| Example.new dir }
10+
end
11+
12+
def executables
13+
all.map &:executable
14+
end
15+
end
16+
17+
attr_reader :dir
18+
19+
def initialize(dir)
20+
@dir = dir
21+
end
22+
23+
def config
24+
@config ||= YAML.load_file(yaml_path)
25+
end
26+
27+
def yaml
28+
@yaml ||= File.read(yaml_path).strip
29+
end
30+
31+
def yaml_path
32+
"#{dir}/src/bashly.yml"
33+
end
34+
35+
def readme_path
36+
"#{dir}/README.md"
37+
end
38+
39+
def readme
40+
File.read readme_path
41+
end
42+
43+
def test_commands
44+
filename = "#{dir}/test.sh"
45+
result = File.read(filename)
46+
.split(/\s*### Try Me ###\s*/).last
47+
.split("\n")
48+
.reject { |line| line.empty? or line.start_with? '#' }
49+
abort "Can't find ### Try Me ### marker in #{filename}" if result.empty?
50+
result
51+
end
52+
53+
def test_output
54+
result = ''
55+
test_commands.each do |command|
56+
result += "### `$ #{command}`\n\n"
57+
result += "```shell\n"
58+
Dir.chdir dir do
59+
result += `#{command} 2>&1`
60+
result += "\n\n"
61+
end
62+
result += "```\n\n"
63+
end
64+
result
65+
end
66+
67+
def regenerate_readme
68+
File.write readme_path, generated_readme
69+
end
70+
71+
def generated_readme
72+
marker = '-----'
73+
content = readme.split(marker)[0].strip
74+
<<~EOF
75+
#{content}
76+
77+
#{marker}
78+
79+
## `bashly.yml`
80+
81+
```yaml
82+
#{yaml}
83+
```
84+
85+
## Generated script output
86+
87+
#{test_output}
88+
89+
EOF
90+
end
91+
92+
def executable
93+
"#{dir}/#{config['name']}"
94+
end
95+
end

0 commit comments

Comments
 (0)