diff --git a/CHANGELOG.md b/CHANGELOG.md index e149715f..38fd850a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/cli-tool/app/commands/export.rb b/cli-tool/app/commands/export.rb index 34cfba0a..62423ad5 100644 --- a/cli-tool/app/commands/export.rb +++ b/cli-tool/app/commands/export.rb @@ -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 @@ -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! @@ -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] diff --git a/cli-tool/test/commands/export.rb b/cli-tool/test/commands/export.rb index dbf0e955..567e3625 100644 --- a/cli-tool/test/commands/export.rb +++ b/cli-tool/test/commands/export.rb @@ -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 diff --git a/scripts/export/Dockerfile.template b/scripts/export/Dockerfile.template index dad1beb8..3c677c98 100644 --- a/scripts/export/Dockerfile.template +++ b/scripts/export/Dockerfile.template @@ -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 diff --git a/scripts/export/Rakefile b/scripts/export/Rakefile index 39e86253..8626e034 100644 --- a/scripts/export/Rakefile +++ b/scripts/export/Rakefile @@ -29,7 +29,6 @@ end task :squash do Dir.chdir('../game') - puts `ls -l` Squasher.call(options) Dir.chdir('../export') end @@ -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', @@ -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 ./"