Skip to content

Commit

Permalink
feat: minimal Tebako configuration file 'tebafile'
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Aug 4, 2024
1 parent 6ccc632 commit 1fb9527
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 44 deletions.
4 changes: 3 additions & 1 deletion .tebako.yml
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
prefix: PWD
options:
prefix: PWD
Ruby: 3.2.4
69 changes: 53 additions & 16 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ with debug information unstripped. You can opt to run 'strip -S' manually, it mo

| 2.7.8 | Linux, macOS
| 3.0.7 | Linux, macOS
| 3.1.{4,5,6} | Linux, macOS, Windows
| 3.2.{3,4} | Linux, macOS, Windows
| 3.1.6 | Linux, macOS, Windows
| 3.2.4 | Linux, macOS, Windows
| 3.3.{3,4} | Linux, macOS, Windows

|===
Expand Down Expand Up @@ -232,8 +232,6 @@ Displays the Tebako version.
Displays the help message.




== Usage

=== General
Expand Down Expand Up @@ -291,9 +289,6 @@ docker run -v <application_folder>:/mnt/w \
tebako {command} {parameters}
----




==== Packaging from outside the container

To package your application from outside the container, just run a single Docker
Expand Down Expand Up @@ -625,7 +620,8 @@ tebako press \
[-R|--Ruby=<ruby-version>] \
[-o|--output=<packaged-file-name>] \
[-l|--log-level=<error|warn|debug|trace>] \
[-D|--devmode]
[-D|--devmode] \
[-t|--tebafile=<path-to-tebafile>]
----

Where:
Expand All @@ -634,7 +630,7 @@ Where:
the Tebako root folder (see details in the Tebako Root Folder Selection section)

`Ruby`::
This parameter defines Ruby version that will be packaged (optional, defaults to
this parameter defines Ruby version that will be packaged (optional, defaults to
`3.1.6`)

`<project-root>`::
Expand All @@ -651,11 +647,16 @@ the output file name (optional, defaults to `<current folder>/<entry point base
logging level for the Tebako built-in memory filesystem driver
(optional, defaults to `error`)

`tebafile`::
the tebako configuration file (optional, defaults to `$PWD/.tebako.yml`).
Please refer to the separate section below for tebafile description.

`devmode`:: flag that activates development mode, in which Tebako's cache and
packaging consistency checks are relaxed.
+
NOTE: Development mode is *not intended for production use* and should only be
used during development.
NOTES:
* Development mode is *not intended for production use* and should only be used during development.
* `entry-point` and `project-root-folder` are required parameters and may be provided either via command-line or in `tebafile`.

[example]
====
Expand Down Expand Up @@ -690,16 +691,21 @@ based on `tebako press` may create inconsistent environment upon restore.
$ tebako setup \
[-p|--prefix=<tebako-root-folder>] \
[-R|--Ruby=<ruby-version>] \
[-D|--devmode]
[-D|--devmode] \
[-t|--tebafile=<path-to-tebafile>]
----

Where:

`<tebako-root-folder>`:: the Tebako root folder (see details in the Tebako Root Folder Selection section)

`Ruby` parameter defines Ruby version that will be packaged (optional, defaults to 3.1.6)
`Ruby`:: parameter defines Ruby version that will be packaged (optional, defaults to 3.1.6)

`tebafile`::
the tebako configuration file (optional, defaults to `$PWD/.tebako.yml`).
Please refer to the separate section below for tebafile description.

`devmode` flag activates development mode, in which Tebako's cache and packaging consistency checks are relaxed.
`devmode`:: flag activates development mode, in which Tebako's cache and packaging consistency checks are relaxed.
Please note that this mode is not intended for production use and should only be used during development.

==== Clean
Expand All @@ -712,13 +718,18 @@ Normally you do not need to do it since tebako packager optimizes artifacts life
[source,sh]
----
$ tebako clean \
[-p|--prefix=<tebako-root-folder>]
[-p|--prefix=<tebako-root-folder>] \
[-t|--tebafile=<path-to-tebafile>]
----

Where:

`<tebako-root-folder>`:: the Tebako root folder (see details in the Tebako Root Folder Selection section)

`tebafile`::
the tebako configuration file (optional, defaults to `$PWD/.tebako.yml`).
Please refer to the separate section below for tebafile description.

[example]
====
[source,sh]
Expand All @@ -743,7 +754,9 @@ NOTE: Compiled DwarFS libraries are not cleaned.
----
$ tebako clean_ruby
[-p|--prefix=<tebako-root-folder>] \
[-R|--Ruby=<ruby-version>]
[-R|--Ruby=<ruby-version>] \
[-t|--tebafile=<path-to-tebafile>]
----

Where:
Expand All @@ -754,6 +767,10 @@ the Tebako setup folder (optional, defaults to current folder)
`Ruby`::
defines Ruby version that will cleaned (optional, cleans all versions by default)

`tebafile`::
the tebako configuration file (optional, defaults to `$PWD/.tebako.yml`).
Please refer to the separate section below for tebafile description.

[example]
====
[source,sh]
Expand All @@ -772,6 +789,26 @@ as a cache key in CI/CD pipelines.
$ tebako hash
----

=== Tebako configuration file

It is possible to provide all or some options for the `tebako setup/press/clean/clean_ruby` commands via Tebako configuration file ('tebafile').
Tebafile is a YAML file with a single section 'options'. The options are the same as long names for the command line. For, example for the prefix option

[source]
----
-p|--prefix=<tebako-root-folder>
----
the key in the YAML file would be 'prefix'.

Below is an example tebafile that sets values for prefix and Ruby options
[source,yaml]
----
options:
prefix: /tmp/tebako
Ruby: 3.2.4
----

Please note that the options provided on the command line have preference over tebafile settings.

=== Image extraction

Expand Down
39 changes: 12 additions & 27 deletions lib/tebako/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,16 @@
# Tebako - an executable packager
# Implementation of tebako command-line interface
module Tebako
OPTIONS_FILE = ".tebako.yml"
DEFAULT_TEBAFILE = ".tebako.yml"
# Tebako packager front-end
class Cli < Thor
package_name "Tebako"
class_option :prefix, type: :string, aliases: "-p", required: false,
desc: "A path to tebako packaging environment, '~/.tebako' ('$HOME/.tebako') by default"
class_option :devmode, type: :boolean, aliases: "-D", required: false,
desc: "Developer mode, please do not use if unsure"

class_option :tebafile, type: :string, aliases: "-t", required: false,
desc: "tebako configuration file 'tebafile', '$PWD/.tebako.yml' by default"
desc "clean", "Clean tebako packaging environment"
def clean
clean_cache
Expand Down Expand Up @@ -123,35 +124,19 @@ def initialize(*args)

def options
original_options = super

return original_options unless File.exist?(OPTIONS_FILE)

defaults = ::YAML.load_file(OPTIONS_FILE) || {}
Thor::CoreExt::HashWithIndifferentAccess.new(defaults.merge(original_options))
tebafile = original_options["tebafile"].nil? ? DEFAULT_TEBAFILE : original_options["tebafile"]
if File.exist?(tebafile)
Thor::CoreExt::HashWithIndifferentAccess.new(options_from_tebafile(tebafile).merge(original_options))
else
puts "Warning: Tebako configuration file '#{tebafile}' not found." unless original_options["tebafile"].nil?
original_options
end
end
end

private

no_commands do
def do_press
cfg_cmd = "cmake -DSETUP_MODE:BOOLEAN=OFF #{cfg_options} #{press_options}"
build_cmd = "cmake --build #{output} --target tebako --parallel #{Etc.nprocessors}"
merged_env = ENV.to_h.merge(b_env)
Tebako.packaging_error(103) unless system(merged_env, cfg_cmd)
Tebako.packaging_error(104) unless system(merged_env, build_cmd)
end

def do_setup
cfg_cmd = "cmake -DSETUP_MODE:BOOLEAN=ON #{cfg_options}"
build_cmd = "cmake --build \"#{output}\" --target setup --parallel #{Etc.nprocessors}"
merged_env = ENV.to_h.merge(b_env)
Tebako.packaging_error(101) unless system(merged_env, cfg_cmd)
Tebako.packaging_error(102) unless system(merged_env, build_cmd)
end
include Tebako::CliHelpers
include Tebako::CliRubies
end

include Tebako::CliHelpers
include Tebako::CliRubies
end
end
28 changes: 28 additions & 0 deletions lib/tebako/cli_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,22 @@ def deps
@deps ||= File.join(prefix, "deps")
end

def do_press
cfg_cmd = "cmake -DSETUP_MODE:BOOLEAN=OFF #{cfg_options} #{press_options}"
build_cmd = "cmake --build #{output} --target tebako --parallel #{Etc.nprocessors}"
merged_env = ENV.to_h.merge(b_env)
Tebako.packaging_error(103) unless system(merged_env, cfg_cmd)
Tebako.packaging_error(104) unless system(merged_env, build_cmd)
end

def do_setup
cfg_cmd = "cmake -DSETUP_MODE:BOOLEAN=ON #{cfg_options}"
build_cmd = "cmake --build \"#{output}\" --target setup --parallel #{Etc.nprocessors}"
merged_env = ENV.to_h.merge(b_env)
Tebako.packaging_error(101) unless system(merged_env, cfg_cmd)
Tebako.packaging_error(102) unless system(merged_env, build_cmd)
end

def ensure_version_file
version_file_path = File.join(deps, E_VERSION_FILE)

Expand Down Expand Up @@ -128,6 +144,18 @@ def m_files
end
# rubocop:enable Metrics/MethodLength

def options_from_tebafile(tebafile)
::YAML.load_file(tebafile)["options"] || {}
rescue Psych::SyntaxError => e
puts "Warning: The tebafile '#{tebafile}' contains invalid YAML syntax."
puts e.message
{}
rescue StandardError => e
puts "An unexpected error occurred while loading the tebafile '#{tebafile}'."
puts e.message
{}
end

def output
@output ||= File.join(prefix, "o")
end
Expand Down
2 changes: 2 additions & 0 deletions src/tebako-main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ extern "C" int tebako_main(int* argc, char*** argv) {
// Nested error, no recovery :(
}
}

// tebako_chdir("/__tebako_memfs__/local");
}
return ret;
}
Expand Down

0 comments on commit 1fb9527

Please sign in to comment.