testcontainers-core 0.1.3 → 0.2.0

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: cd1ecb046574448907ac650c801eda4e7dad34055c6a61fa06a0f066067e2b97
4
- data.tar.gz: f9c49b86765f2166cf2460bef0899ba40a1b822bdf23451bbe1a3e68531606e4
3
+ metadata.gz: a5422789f7d26555fc9198f71b189ec3f75beba0dbaed0b66f541ef5513a9819
4
+ data.tar.gz: abd82854569df36e3581edc1eb6460af76f2cb3b570ec711131f24f351568f56
5
5
  SHA512:
6
- metadata.gz: e6dfd296c157b51d3429f0c470e5ee1a46d15de6c47b1d417045260c55fed5482e8562a6bc8ac689254fc80a835dff36a0b2af26d6a5f11e75e162f546d15233
7
- data.tar.gz: 77ed8e5fe3cc9df35744fdeccebb9cef54a3a359aa36afe90e0f9dcbd3375a16411db5132590746084c89c3f091b42eb021b033e9d4dce184a12de9499563b4f
6
+ metadata.gz: 7eebf9df18f1599e5a13928f163a5269b5b0e78297447ff04396db804bfe7f0ff2515b16da13180e504905bf81d533d9528d76bae8f52d2d55d4823d69aed209
7
+ data.tar.gz: 97461a668a41d5efb9c3c88cac46d2f4f308a5975bff34042bb78a7edf41b66a2f2a3426ffa8a39baa0efe6b70bc8949306e8372d40dc35a80e4ecd12b2e0574
data/CHANGELOG.md CHANGED
@@ -1,3 +1,11 @@
1
+ ## [0.2.0] - 2024-02-08
2
+
3
+ ### Added
4
+
5
+ - DockerContainer#new now accepts optional keyword argument `image_create_options` which accepts a hash. Passes the options to `Docker::Image.create`. See the [Docker ImageCreate api](https://docs.docker.com/engine/api/v1.43/#tag/Image/operation/ImageCreate) for available parameters.
6
+
7
+ - DockerContainer#remove now accepts an optional options hash. See the [Docker ContainerDelete api](https://docs.docker.com/engine/api/v1.43/#tag/Container/operation/ContainerDelete) for available parameters.
8
+
1
9
  ## [0.1.3] - 2023-06-10
2
10
 
3
11
  ### Added
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- testcontainers-core (0.1.3)
4
+ testcontainers-core (0.2.0)
5
5
  docker-api (~> 2.2)
6
6
 
7
7
  GEM
@@ -57,6 +57,7 @@ GEM
57
57
 
58
58
  PLATFORMS
59
59
  arm64-darwin-21
60
+ ruby
60
61
  x86_64-linux
61
62
 
62
63
  DEPENDENCIES
@@ -30,6 +30,7 @@ module Testcontainers
30
30
  # @param command [Array<String>, nil] the command to run in the container
31
31
  # @param name [String, nil] the container's name
32
32
  # @param exposed_ports [Hash, Array<String>, nil] a hash or an array of exposed container ports
33
+ # @param image_create_options [Hash] a hash of options to pass to Docker::Image.create.
33
34
  # @param port_bindings [Hash, Array<String>, nil] a hash or an array of container ports to host port bindings
34
35
  # @param volumes [Hash, Array<String>, nil] a hash or an array of volume paths in the container
35
36
  # @param filesystem_binds [Array<String>, Hash, nil] an array of strings or a hash representing bind mounts from the host to the container
@@ -37,7 +38,7 @@ module Testcontainers
37
38
  # @param labels [Hash, nil] a hash of labels to be applied to the container
38
39
  # @param working_dir [String, nil] the working directory for the container
39
40
  # @param logger [Logger] a logger instance for the container
40
- def initialize(image, name: nil, command: nil, entrypoint: nil, exposed_ports: nil, port_bindings: nil, volumes: nil, filesystem_binds: nil,
41
+ def initialize(image, name: nil, command: nil, entrypoint: nil, exposed_ports: nil, image_create_options: {}, port_bindings: nil, volumes: nil, filesystem_binds: nil,
41
42
  env: nil, labels: nil, working_dir: nil, healthcheck: nil, wait_for: nil, logger: Testcontainers.logger)
42
43
 
43
44
  @image = image
@@ -45,6 +46,7 @@ module Testcontainers
45
46
  @command = command
46
47
  @entrypoint = entrypoint
47
48
  @exposed_ports = add_exposed_ports(exposed_ports) if exposed_ports
49
+ @image_create_options = image_create_options
48
50
  @port_bindings = add_fixed_exposed_ports(port_bindings) if port_bindings
49
51
  @volumes = add_volumes(volumes) if volumes
50
52
  @env = add_env(env) if env
@@ -468,8 +470,9 @@ module Testcontainers
468
470
  #
469
471
  # @return [DockerContainer] The DockerContainer instance.
470
472
  # @raise [ConnectionError] If the connection to the Docker daemon fails.
473
+ # @raise [NotFoundError] If Docker is unable to find the image.
471
474
  def start
472
- Docker::Image.create("fromImage" => @image)
475
+ Docker::Image.create({"fromImage" => @image}.merge(@image_create_options))
473
476
 
474
477
  @_container ||= Docker::Container.create(_container_create_options)
475
478
  @_container.start
@@ -482,6 +485,8 @@ module Testcontainers
482
485
  @wait_for&.call(self)
483
486
 
484
487
  self
488
+ rescue Docker::Error::NotFoundError => e
489
+ raise NotFoundError, e.message
485
490
  rescue Excon::Error::Socket => e
486
491
  raise ConnectionError, e.message
487
492
  end
@@ -530,11 +535,12 @@ module Testcontainers
530
535
 
531
536
  # Removes the container.
532
537
  #
538
+ # @param options [Hash] Additional options to send to the container remove command.
533
539
  # @return [DockerContainer] The DockerContainer instance.
534
540
  # @return [nil] If the container does not exist.
535
541
  # @raise [ConnectionError] If the connection to the Docker daemon fails.
536
- def remove
537
- @_container&.remove
542
+ def remove(options = {})
543
+ @_container&.remove(options)
538
544
  @_container = nil
539
545
  self
540
546
  rescue Excon::Error::Socket => e
@@ -732,6 +738,24 @@ module Testcontainers
732
738
  container_ports.map { |port| mapped_port(port) }.first
733
739
  end
734
740
 
741
+ # Returns the container's mounts.
742
+ #
743
+ # @return [Array<Hash>] An array of the container's mounts.
744
+ # @raise [ConnectionError] If the connection to the Docker daemon fails.
745
+ # @raise [ContainerNotStartedError] If the container has not been started.
746
+ def mounts
747
+ info["Mounts"]
748
+ end
749
+
750
+ # Returns the container's mount names.
751
+ #
752
+ # @return [Array<String>] The container's mount names.
753
+ # @raise [ConnectionError] If the connection to the Docker daemon fails.
754
+ # @raise [ContainerNotStartedError] If the container has not been started.
755
+ def mount_names
756
+ mounts.map { |mount| mount["Name"] }
757
+ end
758
+
735
759
  # Returns the value for the given environment variable.
736
760
  #
737
761
  # @param key [String] The environment variable's key.
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Testcontainers
4
- VERSION = "0.1.3"
4
+ VERSION = "0.2.0"
5
5
  end
@@ -12,6 +12,8 @@ module Testcontainers
12
12
 
13
13
  class ConnectionError < Error; end
14
14
 
15
+ class NotFoundError < Error; end
16
+
15
17
  class TimeoutError < Error; end
16
18
 
17
19
  class ContainerNotStartedError < Error; end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: testcontainers-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillermo Iguaran
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-06-10 00:00:00.000000000 Z
11
+ date: 2024-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docker-api
@@ -120,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
120
120
  - !ruby/object:Gem::Version
121
121
  version: '0'
122
122
  requirements: []
123
- rubygems_version: 3.4.1
123
+ rubygems_version: 3.4.14
124
124
  signing_key:
125
125
  specification_version: 4
126
126
  summary: Testcontainers for Ruby.