rascal 0.5.0 → 0.5.1

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: 34585fe95d0385f9a425567f13cb986e0412640f6e84fa412780aefb44e97122
4
+ data.tar.gz: f869ba37ed03971430efa2888df0453c3c328fbed81e722bf8408e1c5f8d3851
5
5
  SHA512:
6
- metadata.gz: 18e64ccdc952397b8036e90ca053fc118d3416cb94622ab60440edfda1374d5a756d2e700fa8129b6c68058b4df906d810382c60b456f09f91b19a874e1c5214
7
- data.tar.gz: f90cd9a5c12b4da475c2cef16d6f8f4b6c471fd1b268ba83d0d474b2698f11c5ecfc38893612e1f8145a6bd5b1d25580641b9ed941ce00683f58d61e430325af
6
+ metadata.gz: aa819fdefaee9cf7608c32ed7b58d6807d3ad5525496a7550d1b0802e2024af45c20a149882a39c70b4049bcb324a577b64d886bd4fc92c019f32f7e676d0ded
7
+ data.tar.gz: 4474c7ff3853fccb0b75a90c3a038abebcb96ddf1fb8aa05f3b7f8d1638b0a0572e657ac8a053686473d06be394a690d912074c7fc572db8dc8b78f79e014ae7
data/CHANGELOG.md CHANGED
@@ -4,6 +4,15 @@ 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.1 (2026-11-20)
8
+
9
+ - Fix services that were unreachable by their alias after rascal restarted their stopped container
10
+ (with current Docker versions). rascal now connects such containers to the network again, also
11
+ ones that an earlier version left running without a network. It recreates service containers
12
+ whose network was removed, like by `docker network prune`, also when they have no network
13
+ endpoints or still run.
14
+
15
+
7
16
  ## 0.5.0 (2026-11-20)
8
17
 
9
18
  ### Breaking changes
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.1)
5
5
  thor (>= 1.0.0)
6
6
 
7
7
  GEM
@@ -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.1"
3
3
  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.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Kraze