Skip to content

Commit f02c0c2

Browse files
committed
Update Docker test suite
1 parent 4062cb8 commit f02c0c2

File tree

4 files changed

+41
-53
lines changed

4 files changed

+41
-53
lines changed

Rakefile

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ Terminalwire::Project.all.each do |project|
1313
sh "gem uninstall #{project.name} --force --executables"
1414
end
1515

16+
desc "Clean #{project.name}"
17+
task :clean do
18+
sh "rm -rf #{File.join project.dir, "pkg/*.gem"}"
19+
end
20+
1621
desc "Test #{project.name}"
1722
task :spec do
1823
project.chdir do
@@ -57,7 +62,7 @@ end
5762

5863
namespace :gem do
5964
# Define global tasks for all gems
60-
%i[build install install:local release uninstall].each do |task|
65+
%i[build clean install install:local release uninstall].each do |task|
6166
desc "#{task.capitalize} all gems"
6267
task task do
6368
Terminalwire::Project.all.each do |project|
@@ -68,7 +73,7 @@ namespace :gem do
6873
end
6974

7075
desc "Build gems"
71-
task :gem, %i[gem:build]
76+
task gem: %i[gem:clean gem:build]
7277

7378
namespace :spec do
7479
desc "Run isolated specs"
@@ -79,7 +84,7 @@ namespace :spec do
7984
end
8085

8186
desc "Run integration specs"
82-
task :integration do
87+
task integration: :gem do
8388
sh "bundle exec rspec spec"
8489
end
8590
end
@@ -158,5 +163,5 @@ task tebako: %i[tebako:build tebako:ubuntu:build tebako:package]
158163
desc "Run specs"
159164
task spec: %i[spec:isolate spec:integration]
160165

161-
# Run tests and build everything.
162-
task default: %i[spec gem tebako]
166+
# Run : Lgemntests and build everything.
167+
task default: %i[spec tebako]

containers/rails/Dockerfile

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ FROM ruby:${RUBY_VERSION} AS base
44
WORKDIR /rails
55

66
RUN gem install rails && \
7-
rails new . --minimal --name terminalwire-integration
7+
rails new . --minimal --name terminalwire-integration
88

99
FROM base AS local
1010

11+
# Ensure our local gem executables are on the PATH.
1112
COPY ./containers/rails/app/models /rails/app/models
12-
COPY ./gem /gem
13+
COPY ./gem/*/pkg/*.gem /gem/
14+
RUN gem install /gem/terminalwire*.gem
1315

14-
RUN bundle config local.terminalwire-core /gem/terminalwire-core && \
15-
bundle config local.terminalwire-server /gem/terminalwire-server && \
16-
bundle config local.terminalwire-rails /gem/terminalwire-rails && \
17-
bundle config local.terminalwire /gem/terminalwire
16+
# Remove the remote source from the Gemfile so that nothing is fetched remotely.
17+
RUN sed -i '/^source/d' Gemfile
1818

19-
RUN bundle add terminalwire
19+
# This will add the local terminalwire-raisl gem.
20+
RUN bundle add terminalwire-rails
2021

2122
RUN bin/rails generate terminalwire:install hello
2223

23-
EXPOSE 3000
2424
CMD ["bin/rails", "server", "--port", "3000", "--binding", "0.0.0.0"]

gem/terminalwire-rails/lib/terminalwire/rails.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,9 @@ def handle(adapter:, env:)
9696
cli.default_url_options = { host: env["HTTP_HOST"] }
9797
end
9898
context.exit
99+
# rescue Thor::InvocationError => e
100+
# context.stdin.puts e.message
101+
# context.exit(1)
99102
rescue StandardError => e
100103
# Log the error
101104
handler_error_message = <<~_

spec/integration/rails_spec.rb

Lines changed: 20 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,74 +7,54 @@
77
require "io/wait"
88

99
RSpec.describe "Terminalwire Install", type: :system do
10-
let(:binary_name) { "hello" }
11-
let(:gem_path) { File.expand_path('../../../gem/terminalwire', __FILE__) }
12-
let(:exe_path) { File.join(gem_path, "exe") }
13-
14-
PORT = 3000
10+
DOCKER_IMAGE = "terminalwire-rails-server"
11+
BINARY_NAME = "bin/hello"
12+
PORT = 3000
1513

1614
before(:all) do
17-
`docker buildx -t terminalwire-rails-server -f containers/rails/Dockerfile .`
18-
@docker_id = `docker run -p 3000:#{PORT} -d terminalwire-rails-server`.chomp
19-
wait_for_server("0.0.0.0", PORT)
20-
21-
@path = Pathname.new(Dir.mktmpdir)
22-
@bin_path = @path.join("bin").tap(&:mkdir)
15+
build_command = "docker build -t #{DOCKER_IMAGE} -f containers/rails/Dockerfile ."
16+
system(build_command) or raise "Docker build failed: #{build_command}"
2317

24-
Terminalwire::Binary.write(
25-
url: "http://localhost:#{PORT}/terminal",
26-
to: @bin_path.join("hello")
27-
)
18+
# Run the container without external port binding and capture the container ID.
19+
@docker_id = `docker run --rm -d #{DOCKER_IMAGE}`.chomp
20+
raise "Docker run failed" if @docker_id.empty?
2821

29-
ENV["PATH"] = "#{@bin_path.to_s}:#{ENV["PATH"]}"
30-
31-
Dir.chdir(@path) do
32-
Bundler.with_unbundled_env do
33-
`bundle install --path #{@path} --binstubs=#{@bin_path} --quiet`
34-
end
35-
end
22+
wait_for_server_in_container(timeout: 15)
3623
end
3724

3825
after(:all) do
39-
`docker stop #{@docker_id}` if @docker_id
26+
system("docker stop #{@docker_id}") if @docker_id
4027
end
4128

4229
it "runs Terminalwire client against server" do
43-
# Run the binary and capture output
44-
output, status = Open3.capture2e("#{binary_name} hello World")
30+
command = "docker exec #{@docker_id} #{BINARY_NAME} hello World"
31+
output, status = Open3.capture2e(command)
4532
expect(output.strip).to eql "Hello World"
4633
expect(status).to be_success
4734
end
4835

4936
it "logs in successfully" do
50-
PTY.spawn("#{binary_name} login") do |stdout, stdin, pid|
51-
# stdout.readpartial("Email: ".size)
52-
# Simulate entering email and password
37+
command = "docker exec -i #{@docker_id} #{BINARY_NAME} login"
38+
PTY.spawn(command) do |stdout, stdin, pid|
39+
sleep 0.5
5340
stdin.puts "[email protected]"
54-
55-
# stdout.readpartial("Password: ".size)
41+
sleep 0.5
5642
stdin.puts "password123"
57-
5843
output = stdout.read
5944
expect(output).to include("Successfully logged in as [email protected].")
60-
61-
# Ensure the process was successful
6245
Process.wait(pid)
6346
expect($?.success?).to be_truthy
6447
end
6548
end
6649

6750
private
6851

69-
def wait_for_server(host, port, timeout: 5)
52+
def wait_for_server_in_container(timeout:)
7053
start_time = Time.now
7154
until Time.now - start_time > timeout
72-
begin
73-
TCPSocket.new(host, port).close
74-
return true
75-
rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
76-
sleep 0.1
77-
end
55+
response = `docker exec #{@docker_id} curl -s http://localhost:3000/health`
56+
return if !response.strip.empty?
57+
sleep 0.5
7858
end
7959
raise "Server did not start within #{timeout} seconds"
8060
end

0 commit comments

Comments
 (0)