Skip to content

Commit

Permalink
Updates to the export command
Browse files Browse the repository at this point in the history
- export_directory now actually specifies the export from the docker build, not
  where it builds inside Docker
- Can now specify a build cache for exports to save on compile time
- Export Dockerfile now builds Taylor to prime the build cache
  • Loading branch information
HellRok committed Sep 3, 2021
1 parent 44294e4 commit 25e7dba
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 28 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
- Taylor-cli help commands now format nicely
- Taylor-cli can just return the version number
- Add measure_text_ex method
- export_directory now actually specifies the export from the docker build, not
where it builds inside Docker
- Can now specify a build cache for exports to save on compile time
- Export Dockerfile now builds Taylor to prime the build cache

## v0.1.4

Expand Down
20 changes: 18 additions & 2 deletions cli-tool/app/commands/export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def display_help
--help\t\t\tDisplays this message
--dry-run\t\t\tJust display the export command and don't run it
--export_directory directory\tWhat directory do you want your exports (defaults to ./exports)
--build_cache directory\tWhere do you want to store build cache (defaults to nil)
STR
end

Expand All @@ -43,11 +44,12 @@ def setup_options(argv, options)
parser = OptParser.new do |opts|
opts.on(:help, :bool, false)
opts.on(:dry_run, :bool, false)
opts.on(:export_directory, :string, options.fetch(:export_directory, './exports'))
opts.on(:build_cache, :string)
end
parser.parse(argv, true)

@options = parser.opts
@options[:export_directory] = options.fetch(:export_directory, './exports')
end

def check_in_taylor_project!
Expand All @@ -65,9 +67,23 @@ def create_export_folder
end
end

def create_build_cache_folder
return if @options[:dry_run]
return if @options[:build_cache].nil?

unless File.exists?(options[:build_cache]) &&
File.directory?(options[:build_cache])
Dir.mkdir(options[:build_cache])
end
end

def docker_build
command = 'docker run -u $(id -u ${USER}):$(id -g ${USER})'
command << " --mount type=bind,source=#{Dir.pwd},target=/app/game/"
command << " --mount type=bind,source=#{Dir.pwd},target=/app/game"
command << " --mount type=bind,source=#{File.expand_path(@options[:export_directory])},target=/app/game/exports"
unless @options[:build_cache].nil?
command << " --mount type=bind,source=#{@options[:build_cache]},target=/app/taylor/build/"
end
command << " hellrok/taylor:v#{TAYLOR_VERSION}"

if options[:dry_run]
Expand Down
26 changes: 24 additions & 2 deletions cli-tool/test/commands/export.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,32 @@ def test_create_export_folder_dry_run
assert_false Dir.exists?('./exports')
end

def test_check_in_taylor_project_success
def test_create_build_cache_folder
Taylor::Commands::Export.new(['--dry-run'], { build_cache: '/tmp/build/' })
assert_false Dir.exists?('./exports')
end

def test_check_docker_command_default_options
export_command = Taylor::Commands::Export.new(['--dry-run'], {})
assert_include export_command.puts_data, 'docker run'
assert_include export_command.puts_data, Dir.pwd
assert_include export_command.puts_data, File.join(Dir.pwd, 'exports')
assert_include export_command.puts_data, "hellrok/taylor:v#{TAYLOR_VERSION}"
end

def test_check_docker_command_override_export_directory
export_command = Taylor::Commands::Export.new(['--dry-run'], { export_directory: '/tmp/exports' })
assert_include export_command.puts_data, 'docker run'
assert_include export_command.puts_data, '/tmp/exports'
assert_include export_command.puts_data, "hellrok/taylor:v#{TAYLOR_VERSION}"
end

def test_check_docker_command_set_build_cache
# Because this isn't specified by the taylor-config.json we have to pass it
# in via the ARGV
export_command = Taylor::Commands::Export.new(['--dry-run', '--build_cache', '/tmp/build'], {})
assert_include export_command.puts_data, 'docker run'
assert_include export_command.puts_data, File.join(Dir.pwd, 'exports')
assert_include export_command.puts_data, '/tmp/build'
assert_include export_command.puts_data, "hellrok/taylor:v#{TAYLOR_VERSION}"
end
end
24 changes: 12 additions & 12 deletions scripts/export/Dockerfile.template
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
FROM appplant/mruby-cli as build_base

WORKDIR /app/mruby
RUN git clone --branch 3.0.0 --depth 1 https://github.com/mruby/mruby.git . &&\
rake

WORKDIR /app/taylor
RUN git clone --branch $VERSION --depth 1 https://github.com/HellRok/Taylor.git .

WORKDIR /app/export

RUN \
apt-get update -y && \
apt-get install -y g++ zip
RUN git clone --branch 3.0.0 --depth 1 https://github.com/mruby/mruby.git /app/mruby &&\
cd /app/mruby &&\
rake &&\
git clone --branch $VERSION --depth 1 https://github.com/HellRok/Taylor.git /app/taylor &&\
apt-get update -y &&\
apt-get install -y g++ zip &&\
cd /app/taylor &&\
rake linux:release:build &&\
rake windows:release:build &&\
rake osx:release:build &&\
rm -rf dist/*

COPY . /app/export

RUN chmod o+w \
RUN chmod -R o+w \
/app/export \
/app/taylor \
/app/taylor/include
Expand Down
23 changes: 11 additions & 12 deletions scripts/export/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ end

task :squash do
Dir.chdir('../game')
puts `ls -l`
Squasher.call(options)
Dir.chdir('../export')
end
Expand All @@ -41,26 +40,26 @@ end

task :rename do
Dir.chdir('../game')
FileUtils.mkdir_p options['export_directory']
FileUtils.mkdir_p './exports'

puts "Copying linux build"

FileUtils.mkdir_p File.join(options['export_directory'], 'linux')
FileUtils.mkdir_p File.join('./exports', 'linux')
FileUtils.cp '../taylor/dist/linux/release/taylor',
File.join('./', options['export_directory'], 'linux', options['name'])
File.join('./', './exports', 'linux', options['name'])

puts "Copying windows build"

FileUtils.mkdir_p File.join(options['export_directory'], 'windows')
FileUtils.mkdir_p File.join('./exports', 'windows')
FileUtils.cp '../taylor/dist/windows/release/taylor.exe',
File.join('./', options['export_directory'], 'windows', "#{options['name']}.exe")
File.join('./', './exports', 'windows', "#{options['name']}.exe")
FileUtils.cp Dir.glob('../taylor/dist/windows/release/*.dll'),
File.join('./', options['export_directory'], 'windows')
File.join('./', './exports', 'windows')

puts "Copying osx build"

app_path = File.join(
options['export_directory'],
'./exports',
'osx',
"#{options['name']}.app",
'Contents',
Expand All @@ -72,22 +71,22 @@ task :rename do
end

task :compress do
Dir.chdir(options['export_directory'])
Dir.chdir('./exports')

Dir.chdir('./linux')
options['copy_paths'].each { |asset_path| FileUtils.cp_r(File.join('/app/game/', asset_path), '.') }
sh "zip -r #{options['name']}-linux-#{options['version']}.zip *"
sh "zip -r \"#{options['name']}-linux-#{options['version']}.zip\" *"

Dir.chdir('../windows')
options['copy_paths'].each { |asset_path| FileUtils.cp_r(File.join('/app/game/', asset_path), '.') }
sh "zip -r #{options['name']}-windows-#{options['version']}.zip *"
sh "zip -r \"#{options['name']}-windows-#{options['version']}.zip\" *"

Dir.chdir('../osx')
app_path = File.join('.', "#{options['name']}.app", 'Contents', 'MacOS')
FileUtils.mkdir_p(app_path)
File.write(File.join(app_path, '..', 'PkgInfo'), 'APPL????APPL????')
options['copy_paths'].each { |asset_path| FileUtils.cp_r(File.join('/app/game/', asset_path), app_path) }
sh "zip -r #{options['name']}-osx-#{options['version']}.zip *"
sh "zip -r \"#{options['name']}-osx-#{options['version']}.zip\" *"

Dir.chdir('..')
sh "mv **/*.zip ./"
Expand Down

0 comments on commit 25e7dba

Please sign in to comment.