diff --git a/.gitignore b/.gitignore index 23e3551..a12e5e5 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,5 @@ validation-report.json # Folders to ignore node_modules + +tmp diff --git a/Gemfile b/Gemfile index c802e0d..112b566 100644 --- a/Gemfile +++ b/Gemfile @@ -4,3 +4,6 @@ gem "jekyll" gem "jekyll-gist" gem "jekyll-paginate" gem "jekyll-seo-tag" + +gem 'rake' +gem 'docker-api' diff --git a/Gemfile.lock b/Gemfile.lock index ca0c913..df27728 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -5,10 +5,14 @@ GEM public_suffix (>= 2.0.2, < 5.0) colorator (1.1.0) concurrent-ruby (1.1.6) + docker-api (2.0.0) + excon (>= 0.47.0) + multi_json em-websocket (0.5.1) eventmachine (>= 0.12.9) http_parser.rb (~> 0.6.0) eventmachine (1.2.7) + excon (0.76.0) faraday (1.0.1) multipart-post (>= 1.2, < 3) ffi (1.13.1) @@ -49,6 +53,7 @@ GEM rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) mercenary (0.4.0) + multi_json (1.15.0) multipart-post (2.1.1) octokit (4.18.0) faraday (>= 0.9) @@ -56,6 +61,7 @@ GEM pathutil (0.16.2) forwardable-extended (~> 2.6) public_suffix (4.0.5) + rake (13.0.1) rb-fsevent (0.10.4) rb-inotify (0.10.1) ffi (~> 1.0) @@ -75,10 +81,12 @@ PLATFORMS ruby DEPENDENCIES + docker-api jekyll jekyll-gist jekyll-paginate jekyll-seo-tag + rake BUNDLED WITH 2.1.4 diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..a6d0a04 --- /dev/null +++ b/Rakefile @@ -0,0 +1,78 @@ +require 'rake' +require 'docker' + +MARKDOWN_RESUME_IMAGE_NAME = 'there4/markdown-resume' +RESUME_TYPES = %w[ + pdf + html +] + +namespace :resume do + task :clean do |_t, args| + dirs = [ + 'tmp', + 'assets/resumes' + ] + + dirs.each do |dir| + dir_name = File.join(Dir.pwd, dir) + unless File.directory?(dir_name) + FileUtils.mkdir_p(dir_name) + end + end + end + + # remove jekyll related content and write to tmp/ dir + task :write_temp_resume do |_t, args| + f = File.read('resume.md') + resume = f.partition("").last + + File.write('tmp/resume.md', resume) + end + + task :pull_image do |_t, args| + puts "Pulling image, #{MARKDOWN_RESUME_IMAGE_NAME} ..." + Docker::Image.create( + 'fromImage' => MARKDOWN_RESUME_IMAGE_NAME, + ) + end + + desc 'Build resume from markdown. Example - rake resume:build[html]' + task :build, [:type] => [:clean, :write_temp_resume, :pull_image] do |_t, args| + type = args[:type] || 'pdf' + + unless RESUME_TYPES.include?(type) + raise "#{type} is not a supported resume type, try one of these: #{RESUME_TYPES.join(',')}" + end + + puts "Building resume from markdown file ..." + container = Docker::Container.create( + 'Cmd' => [ + 'md2resume', + type, + 'tmp/resume.md', + 'assets/resumes/' + ], + 'Image' => MARKDOWN_RESUME_IMAGE_NAME, + 'Volumes' => { + Dir.pwd => { '/resume' => 'rw' }, + }, + 'HostConfig' => { + 'Binds' => ["#{Dir.pwd}:/resume"], + }, + ) + + container.start + result = container.wait['StatusCode'] + + if !result.zero? + raise "Got bad status code when building resume: #{result}" + end + + puts "Deleting container ..." + container.delete(:force => true) + + puts "Done. You can find your #{type} resume in /assets/resumes" + end +end + diff --git a/assets/resumes/resume.pdf b/assets/resumes/resume.pdf new file mode 100644 index 0000000..7ea4eb9 Binary files /dev/null and b/assets/resumes/resume.pdf differ