rascal 0.5.0 → 0.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b86e32f15a29579cd4db96a2b811995aedea25da03dccedcef016c004ad02a27
4
- data.tar.gz: 9c427e0a5729653c4addd075371cc2d0198180ff89c264bede269705ebc06612
3
+ metadata.gz: d3e2ff1803061e64df4ef54b6a97c97c444a19494625652e9f916061bf07fb8b
4
+ data.tar.gz: 967997b31aa2cb8eb63b618606d04077fee44d9d7da51c566bd901fc1fe11c92
5
5
  SHA512:
6
- metadata.gz: 18e64ccdc952397b8036e90ca053fc118d3416cb94622ab60440edfda1374d5a756d2e700fa8129b6c68058b4df906d810382c60b456f09f91b19a874e1c5214
7
- data.tar.gz: f90cd9a5c12b4da475c2cef16d6f8f4b6c471fd1b268ba83d0d474b2698f11c5ecfc38893612e1f8145a6bd5b1d25580641b9ed941ce00683f58d61e430325af
6
+ metadata.gz: 4f206f10d0ac9f023162de66be5de7bb7dcbf44f51b9a5dfc7f165dd730d479c8afee08f5c79c3f5424b7ecfacd75f9508ab2cda9a04bc5e2b2dec7df29ac7a6
7
+ data.tar.gz: c3b55f69c353a7235ed72552d913f21ce04191a3dbd84836b589a8a22176008a082d45732a8b313d046bb1e796243fb1f03e5268241ef6b18f1407387b9fc815
@@ -13,6 +13,10 @@ jobs:
13
13
  fail-fast: false
14
14
  matrix:
15
15
  include:
16
+ - ruby: '3.0'
17
+ gemfile: Gemfile
18
+ # The Bundler in Gemfile.lock needs Ruby 3.1, so use the one Ruby 3.0 comes with.
19
+ bundler: none
16
20
  - ruby: '3.3'
17
21
  gemfile: Gemfile
18
22
  - ruby: '3.4'
@@ -27,9 +31,8 @@ jobs:
27
31
  uses: ruby/setup-ruby@v1
28
32
  with:
29
33
  ruby-version: "${{ matrix.ruby }}"
34
+ bundler: "${{ matrix.bundler || 'Gemfile.lock' }}"
30
35
  - name: Bundle
31
- run: |
32
- gem install bundler:2.1.4
33
- bundle install --no-deployment
36
+ run: bundle install
34
37
  - name: Run tests
35
38
  run: bundle exec rake
data/CHANGELOG.md CHANGED
@@ -4,6 +4,21 @@ All notable changes to this project will be documented here.
4
4
 
5
5
  Rascal follows semantic versioning. This has little consequence pre 1.0, so expect breaking changes.
6
6
 
7
+ ## 0.5.2 (2026-11-20)
8
+
9
+ - Run on Ruby 3.0 or newer again. 0.5.0 and 0.5.1 required Ruby 3.3, which locked out projects that
10
+ pin an older Ruby, like Rails LTS checkouts with Ruby 3.1.
11
+
12
+
13
+ ## 0.5.1 (2026-11-20)
14
+
15
+ - Fix services that were unreachable by their alias after rascal restarted their stopped container
16
+ (with current Docker versions). rascal now connects such containers to the network again, also
17
+ ones that an earlier version left running without a network. It recreates service containers
18
+ whose network was removed, like by `docker network prune`, also when they have no network
19
+ endpoints or still run.
20
+
21
+
7
22
  ## 0.5.0 (2026-11-20)
8
23
 
9
24
  ### Breaking changes
data/CONTRIBUTING.md CHANGED
@@ -6,7 +6,8 @@ This guide is for people and AI agents who change rascal. For using rascal, see
6
6
 
7
7
  ## Setup
8
8
 
9
- You need Ruby 3.3 or newer and a running Docker daemon. Install the dependencies with
9
+ You need Ruby 3.0 or newer and a running Docker daemon. We develop with the Ruby from
10
+ `.ruby-version`, and CI also tests the oldest supported Ruby. Install the dependencies with
10
11
  `bundle install`.
11
12
 
12
13
  To try your working copy on a project, run its executable from the project directory, with the Ruby
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rascal (0.5.0)
4
+ rascal (0.5.2)
5
5
  thor (>= 1.0.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -56,7 +56,7 @@ when something is missing.
56
56
 
57
57
  Install rascal with a Ruby of your own, not into the project's bundle. rascal needs neither the
58
58
  project's Ruby nor its gems, so one installation works for all projects, old and new. It needs
59
- Ruby 3.3 or newer.
59
+ Ruby 3.0 or newer.
60
60
 
61
61
  Ruby version managers like mise or rbenv switch to the project's Ruby inside a project directory
62
62
  (from `.ruby-version`), and that Ruby usually does not have rascal. So pick one Ruby for rascal, and
@@ -46,6 +46,10 @@ module Rascal
46
46
  !!id
47
47
  end
48
48
 
49
+ def attached_to?(network)
50
+ attached_network_ids.include?(network.id)
51
+ end
52
+
49
53
  # Docker resolves a container's network by the id it recorded when the
50
54
  # container was created, and refuses to start it once that network is
51
55
  # gone:
@@ -58,10 +62,19 @@ module Rascal
58
62
  # help, since docker resolves the recorded id before it looks at the
59
63
  # container's current endpoints, so the container has to go. Nothing in a
60
64
  # service container is worth preserving; #start creates a new one.
65
+ #
66
+ # A container without network endpoints, like one that was never started
67
+ # or that an older rascal disconnected, still records its network in its
68
+ # network mode. Such a container may even be running, which Docker allows
69
+ # after its network was pruned, but it cannot be connected to another.
70
+ #
71
+ # Only removes the container if its network is really gone. Older rascal
72
+ # versions recorded networks by their short id, so compare by asking Docker.
61
73
  def remove_if_network_missing(network)
62
74
  return unless exists?
63
- attached = attached_network_ids
64
- return if attached.empty? || attached.include?(network.id)
75
+ recorded = attached_network_ids
76
+ recorded = [network_mode].compact if recorded.empty?
77
+ return if recorded.empty? || recorded.include?(network.id) || recorded.any? { |id_or_name| Network.exists?(id_or_name) }
65
78
 
66
79
  info "Removing container for #{@name}, its network no longer exists"
67
80
  remove_container
@@ -121,6 +134,12 @@ module Rascal
121
134
  Docker.interface.run('container', 'inspect', id, output: :json).first
122
135
  end
123
136
 
137
+ # The network the container was created with, if it is not one of Docker's own modes like `bridge`.
138
+ def network_mode
139
+ mode = inspection&.dig('HostConfig', 'NetworkMode').to_s
140
+ mode unless mode.empty? || %w[default bridge host none].include?(mode) || mode.start_with?('container:')
141
+ end
142
+
124
143
  # Ids of the networks the container is attached to. Empty for a container
125
144
  # that was created but never started.
126
145
  def attached_network_ids
@@ -129,9 +148,10 @@ module Rascal
129
148
  end
130
149
 
131
150
  # Also removes the container's anonymous volumes, like the data volume that
132
- # the postgres and redis images declare. Named volumes are kept.
151
+ # the postgres and redis images declare. Named volumes are kept. Removes a
152
+ # running container too.
133
153
  def remove_container
134
- Docker.interface.run('container', 'rm', '--volumes', id)
154
+ Docker.interface.run('container', 'rm', '--force', '--volumes', id)
135
155
  end
136
156
  end
137
157
  end
@@ -5,6 +5,11 @@ module Rascal
5
5
 
6
6
  attr_reader :prefixed_name
7
7
 
8
+ # Whether a network with this id (also a short one) or name exists.
9
+ def self.exists?(id_or_name)
10
+ !Docker.interface.run('network', 'inspect', '--format', '{{.Id}}', id_or_name, output: :text, allow_failure: true).to_s.empty?
11
+ end
12
+
8
13
  def initialize(name)
9
14
  @name = name
10
15
  @prefixed_name = "#{NAME_PREFIX}#{name}"
@@ -32,6 +37,16 @@ module Rascal
32
37
  raise unless e.message.include?('is not connected')
33
38
  end
34
39
 
40
+ def connect(container_id, aliases:)
41
+ Docker.interface.run(
42
+ 'network',
43
+ 'connect',
44
+ *aliases.flat_map { |network_alias| ['--alias', network_alias] },
45
+ id,
46
+ container_id,
47
+ )
48
+ end
49
+
35
50
  def exists?
36
51
  !!id
37
52
  end
@@ -30,13 +30,13 @@ module Rascal
30
30
 
31
31
  # Returns whether it started the service.
32
32
  def start_if_stopped(network:)
33
+ @container.remove_if_network_missing(network)
33
34
  if @container.running?
35
+ # Like after an earlier rascal disconnected it, see #reconnect.
36
+ reconnect(network) unless @container.attached_to?(network)
34
37
  false
35
38
  else
36
- @container.remove_if_network_missing(network)
37
- if (container_id = @container.id)
38
- network.disconnect(container_id)
39
- end
39
+ reconnect(network) if @container.exists?
40
40
  @container.start(network: network, network_aliases: @aliases, volumes: @volumes, env: @env_variables, command: @command)
41
41
  true
42
42
  end
@@ -46,6 +46,15 @@ module Rascal
46
46
  @container.running?
47
47
  end
48
48
 
49
+ # Connects the service's container to the network again, under its aliases. Disconnecting
50
+ # first clears an endpoint Docker may have kept ("endpoint ... already exists in network").
51
+ # Docker forgets the network of a stopped container that is disconnected, so without
52
+ # connecting again, the service would start without a network and be unreachable.
53
+ def reconnect(network)
54
+ network.disconnect(@container.id)
55
+ network.connect(@container.id, aliases: @aliases)
56
+ end
57
+
49
58
  # Whether the service is running, but started so recently that it may not be ready yet.
50
59
  def starting?(seconds)
51
60
  started_at = @container.started_at
@@ -1,3 +1,3 @@
1
1
  module Rascal
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.2"
3
3
  end
data/rascal.gemspec CHANGED
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
33
33
  spec.bindir = "exe"
34
34
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
35
35
  spec.require_paths = ["lib"]
36
- spec.required_ruby_version = ">= 3.3"
36
+ spec.required_ruby_version = ">= 3.0"
37
37
 
38
38
  spec.add_dependency "thor", ">= 1.0.0"
39
39
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rascal
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Kraze
@@ -99,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - ">="
101
101
  - !ruby/object:Gem::Version
102
- version: '3.3'
102
+ version: '3.0'
103
103
  required_rubygems_version: !ruby/object:Gem::Requirement
104
104
  requirements:
105
105
  - - ">="