Sha256: ac6871da5799ef660b053b87db0719ed6082b13f60e26b7ed891708cbe415bc2

Contents?: true

Size: 1.2 KB

Versions: 9

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

# takelage docker container clean
module DockerContainerClean
  # Backend method for docker container clean.
  def docker_container_clean
    log.debug 'Removing all docker containers'

    return false unless docker_check_running

    return false if _docker_container_clean_harakiri?

    networks = _docker_container_clean_kill_existing_containers
    _docker_container_lib_remove_networks networks
  end

  private

  # Check if we are running tau clean inside a takelage container
  def _docker_container_clean_harakiri?
    hostname = ENV['HOSTNAME'] || ''
    return false unless hostname.start_with? "#{@docker_repo}_"

    log.error "Please run \"tau clean\" outside of #{@docker_repo} containers"
    log.info "Run \"tau prune\" to remove orphaned #{@docker_repo} containers"
    true
  end

  # Kill all docker containers and return list of networks
  def _docker_container_clean_kill_existing_containers
    networks = []
    _docker_container_lib_get_containers.each do |container|
      name = _docker_container_lib_get_container_name_by_id container
      _docker_container_lib_stop_container container
      networks << name unless networks.include? name
    end
    networks
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
takelage-0.19.2 lib/takelage/docker/container/clean.rb
takelage-0.19.1 lib/takelage/docker/container/clean.rb
takelage-0.19.0 lib/takelage/docker/container/clean.rb
takelage-0.18.1 lib/takelage/docker/container/clean.rb
takelage-0.18.0 lib/takelage/docker/container/clean.rb
takelage-0.17.1 lib/takelage/docker/container/clean.rb
takelage-0.17.0 lib/takelage/docker/container/clean.rb
takelage-0.16.0 lib/takelage/docker/container/clean.rb
takelage-0.15.1 lib/takelage/docker/container/clean.rb