Skip to content

Commit

Permalink
Lesson2 [11]
Browse files Browse the repository at this point in the history
  • Loading branch information
maxirmx committed Jan 11, 2025
1 parent 6d4351f commit 68c9681
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 38 deletions.
22 changes: 17 additions & 5 deletions .github/workflows/tutorial.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:

- name: Package 1_hello_world
run: |
tebako press --root=tutorial/1_hello_world/sample --entry=hello_world.rb
tebako press --root=tutorial/1_hello_world/hellow_world.sample --entry=hello_world.rb
- name: Run packaged 1_hello_world application
run: |
Expand All @@ -40,7 +40,7 @@ jobs:
- name: Package 1_hello_world with a difefrent name
run: |
tebako press --root=tutorial/1_hello_world/sample --entry=hello_world.rb --output=lesson-1
tebako press --root=tutorial/1_hello_world/hellow_world.sample --entry=hello_world.rb --output=lesson-1
- name: Run packaged 1_hello_world application with a different name
run: |
Expand All @@ -52,6 +52,14 @@ jobs:
# Cannot run this sample since GH Actions does not allow such websocket connection to the outside world

- name: Package 2_scenarios gemspec and gemfile sample
run: |
tebako press -r tutorial/2_scenarios/gemspec_and_gemfile.sample -e tebako-table-cli -o table.tebako
- name: Run packaged 2_scenarios gemspec and gemfile sample
run: |
./table.tebako
- name: Package 2_scenarios gemspec sample
run: |
tebako press -r tutorial/2_scenarios/gemspec.sample -e tebako-table-cli -o table.tebako
Expand All @@ -60,10 +68,14 @@ jobs:
run: |
./table.tebako
- name: Package 2_scenarios gemspec and gemfile sample
- name: Package 2_scenarios gem sample
run: |
tebako press -r tutorial/2_scenarios/gemspec_and_gemfile.sample -e tebako-table-cli -o table.tebako
mkdir -p tutorial/2_scenarios/gem.sample
pushd tutorial/2_scenarios/gemspec.sample
gem build tebako-table.gemspec -o ../gem.sample/tebako-test-0.0.2.gem
popd
tebako press -r tutorial/2_scenarios/gem.sample -e tebako-table-cli -o table.tebako
- name: Run packaged 2_scenarios gemspec and gemfile sample
- name: Run packaged 2_scenarios gems sample
run: |
./table.tebako
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ log
# Tutorila
hello_world
source_filesystem/
*.tebako
*.tebako
gem.sample/
4 changes: 2 additions & 2 deletions tutorial/1_hello_world/Lesson-1.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ Now we can package it with Tebako:

[source,sh]
----
tebako press --root=sample --entry=hello_world.rb
tebako press --root=hellow_world.sample --entry=hello_world.rb
----

This command uses two mandatory parameters: `--root` and `--entry`.
Expand Down Expand Up @@ -103,7 +103,7 @@ We can use `--output` to specify the name of the package:

[source,sh]
----
tebako press --root=sample --entry=hello_world.rb --output=lesson-1
tebako press --root=hellow_world.sample --entry=hello_world.rb --output=lesson-1
----

This command creates an executable file `lesson-1` that contains the runtime, the Ruby library files, and the application.
Expand Down
93 changes: 63 additions & 30 deletions tutorial/2_scenarios/Lesson-2.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,6 @@ We will use the following gem specification (`gemfile.sample/tebako-table.gemsp

[source,Ruby]
----
# frozen_string_literal: true
require_relative "lib/version"
Gem::Specification.new do |s|
Expand All @@ -103,26 +101,31 @@ Gem::Specification.new do |s|
end
----

trivial Gemfile

[source,Ruby]
----
source "https://rubygems.org"
gemspec
----

and three source files

1. `gemfile.sample/exe/tebako-table-cli`
1. `gemspec_and_gemfile.sample/exe/tebako-table-cli`

[source,Ruby]
----
# frozen_string_literal: true
$LOAD_PATH.unshift File.expand_path("../lib", __dir__)
require "tebako-table"
instance = Test::TebakoTable.new
instance.run
----

2. `gemfile.sample/lib/tebako-table.rb`
2. `gemspec_and_gemfile.sample/lib/tebako-table.rb`

[source,Ruby]
----
# frozen_string_literal: true
require "text-table"
require_relative "version"
Expand All @@ -148,60 +151,90 @@ module Test
end
----

3. `gemfile.sample/lib/version.rb`
3. `gemspec_and_gemfile.sample/lib/version.rb`

[source,Ruby]
----
# frozen_string_literal: true
module Test
VERSION = "0.0.2"
end
----

Press command is the same:
Press command does not change:

[source,sh]
----
tebako press -r gemspec.sample -e tebako-table-cli -o table.tebako
tebako press -r gemspec_and_gemfile.sample -e tebako-table-cli -o table.tebako
----

but deployment scenario is different:
[source,sh]
but now Tebako recognizes that it packages a gem and applies diffent deployment scenario:

[source]
----
-- Running init script
... creating packaging environment at /Users/runner/.tebako/o/s
-- Running deploy script
... installing tebako-runtime gem
... @ /Users/runner/.tebako/o/s/bin/gem install tebako-runtime --no-document --install-dir /Users/runner/.tebako/o/s/lib/ruby/gems/3.2.0
... Collecting gem from gemspec /Users/runner/work/tebako-samples/tebako-samples/tutorial/2_scenarios/gemspec.sample/tebako-table.gemspec
... @ /Users/runner/.tebako/o/s/bin/gem build /Users/runner/work/tebako-samples/tebako-samples/tutorial/2_scenarios/gemspec.sample/tebako-table.gemspec
... collecting gem from gemspec /Users/runner/work/tebako-samples/tebako-samples/tutorial/2_scenarios/gemspec_and_gemfile.sample/tebako-table.gemspec and Gemfile
... @ /Users/runner/.tebako/o/s/bin/bundle config set --local build.ffi --disable-system-libffi
... @ /Users/runner/.tebako/o/s/bin/bundle config set --local build.nokogiri --no-use-system-libraries
... @ /Users/runner/.tebako/o/s/bin/bundle config set --local force_ruby_platform false
*** It may take a long time for a big project. It takes REALLY long time on Windows ***
... @ /Users/runner/.tebako/o/s/bin/bundle install --jobs=3
... @ /Users/runner/.tebako/o/s/bin/bundle exec /Users/runner/.tebako/o/s/bin/gem build
/Users/runner/work/tebako-samples/tebako-samples/tutorial/2_scenarios/gemspec_and_gemfile.sample/tebako-table.gemspec
... installing /Users/runner/.tebako/o/r/tebako-test-0.0.2.gem
... @ /Users/runner/.tebako/o/s/bin/gem install /Users/runner/.tebako/o/r/tebako-test-0.0.2.gem --no-document --install-dir /Users/runner/.tebako/o/s/lib/ruby/gems/3.2.0 --bindir /Users/runner/.tebako/o/s/bin
... @ /Users/runner/.tebako/o/s/bin/gem install /Users/runner/.tebako/o/r/tebako-test-0.0.2.gem --no-document
--install-dir /Users/runner/.tebako/o/s/lib/ruby/gems/3.2.0 --bindir /Users/runner/.tebako/o/s/bin
... target entry point will be at /__tebako_memfs__/bin/tebako-table-cli
... stripping the output
----

Tebako now installs the gem to its Ruby environment and assumes that the entry point is the wrapper created by gem command in the `binary` directory.
Note that entrypoint script shall be explicitly specified as one of gem executables.

== Packaging a gem with gemfile dependencies
== Packaging a gem without bundle

Tebako also supports gems defined without Gemfile (not bundled). We can copy the previous example, specify dependencies in gemspec,
remove Gemfile and do tebako packaging

[source,sh]
----
tebako press -r gemspec.sample -e tebako-table-cli -o table.tebako
----

[source]
----
-- Running init script
... creating packaging environment at /home/maxirmx/.tebako/o/s
... creating packaging environment at /Users/runner/.tebako/o/s
-- Running deploy script
... installing tebako-runtime gem
... @ /home/maxirmx/.tebako/o/s/bin/gem install tebako-runtime --no-document --install-dir /home/maxirmx/.tebako/o/s/lib/ruby/gems/3.2.0
... collecting gem from gemspec /home/maxirmx/Projects/tebako-samples/tutorial/2_scenarios/gemspec_and_gemfile.sample/tebako-table.gemspec and Gemfile
... @ /home/maxirmx/.tebako/o/s/bin/bundle config set --local build.ffi --disable-system-libffi
... @ /home/maxirmx/.tebako/o/s/bin/bundle config set --local build.nokogiri --no-use-system-libraries
... @ /home/maxirmx/.tebako/o/s/bin/bundle config set --local force_ruby_platform false
*** It may take a long time for a big project. It takes REALLY long time on Windows ***
... @ /home/maxirmx/.tebako/o/s/bin/bundle install --jobs=16
... @ /home/maxirmx/.tebako/o/s/bin/bundle exec /home/maxirmx/.tebako/o/s/bin/gem build /home/maxirmx/Projects/tebako-samples/tutorial/2_scenarios/gemspec_and_gemfile.sample/tebako-table.gemspec
... installing /home/maxirmx/.tebako/o/r/tebako-test-0.0.2.gem
... @ /home/maxirmx/.tebako/o/s/bin/gem install /home/maxirmx/.tebako/o/r/tebako-test-0.0.2.gem --no-document --install-dir /home/maxirmx/.tebako/o/s/lib/ruby/gems/3.2.0 --bindir /home/maxirmx/.tebako/o/s/lib
... @ /Users/runner/.tebako/o/s/bin/gem install tebako-runtime --no-document --install-dir /Users/runner/.tebako/o/s/lib/ruby/gems/3.2.0
... collecting gem from gemspec /Users/runner/work/tebako-samples/tebako-samples/tutorial/2_scenarios/gemspec.sample/tebako-table.gemspec
... @ /Users/runner/.tebako/o/s/bin/gem build /Users/runner/work/tebako-samples/tebako-samples/tutorial/2_scenarios/gemspec.sample/tebako-table.gemspec
... installing /Users/runner/.tebako/o/r/tebako-test-0.0.2.gem
... @ /Users/runner/.tebako/o/s/bin/gem install /Users/runner/.tebako/o/r/tebako-test-0.0.2.gem --no-document
--install-dir /Users/runner/.tebako/o/s/lib/ruby/gems/3.2.0 --bindir /Users/runner/.tebako/o/s/bin
... target entry point will be at /__tebako_memfs__/bin/tebako-table-cli
... stripping the output
----

This approach is faster but may fail for gems with native extensions since Tebako won't have enough control to correctly configure them.
We primarily support it for backwords compatibility.

== Packaging built gem

Tebako can also package a gem or gems, i.e.: one or several `*.gem` files

[source,sh]
----
mkdir -p gem.sample
pushd gemspec.sample
gem build tebako-table.gemspec -o ../gem.sample/tebako-test-0.0.2.gem
popd
tebako press -r gem.sample -e tebako-table-cli -o table.tebako
----


== Live example

Expand Down
1 change: 1 addition & 0 deletions tutorial/2_scenarios/gemspec.sample/exe/tebako-table-cli
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/home/tebako/bin/ruby
# frozen_string_literal: true

# Tebako tutorial: Lesson 2
Expand Down
1 change: 1 addition & 0 deletions tutorial/2_scenarios/gemspec_and_gemfile.sample/exe/tebako-table-cli
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#!/home/tebako/bin/ruby
# frozen_string_literal: true

# Tebako tutorial: Lesson 2
Expand Down

0 comments on commit 68c9681

Please sign in to comment.