<commit_before># Author:: <NAME> <<EMAIL>>
# Cookbook:: teracy-dev
# Recipe:: docker_registry
# Login into the Docker registries

docker_conf = node['docker']

docker_registry_conf = node['docker_registry']

if docker_conf['enabled'] == true
    execute 'rm ~/.docker/config.json' do
        command "rm /home/vagrant/.docker/config.json || true"
        only_if {
            docker_registry_conf['force'] == true and
            File.exist?('/home/vagrant/.docker/config.json')
        }
    end

    docker_registry_conf['entries'].each.with_index do |entry, index|
        # private registry login

        username = entry['username'] ? entry['username'] : ""

        password = entry['password'] ? entry['password'] : ""

        if not username.empty? and not password.empty?
            opt = [
                "-u #{username}",
                "-p #{password}"
            ].join(' ');

            execute 'docker login' do
                command "docker login #{entry['host']} #{opt}"
                # because we need root to execute docker-compose, not 'vagrant'
                only_if {
                    docker_registry_conf['force'] == true or
                    not File.exist?('/root/.docker/config.json')
                }
            end
        end
    end

    execute 'copy /root/.docker/config.json to ~/.docker/config.json' do
        command "cp /root/.docker/config.json /home/vagrant/.docker/config.json"
        only_if {
            File.exist?('/root/.docker/config.json') and (
                docker_registry_conf['force'] == true or
                not File.exist?('/home/vagrant/.docker/config.json')
            )<commit_msg>@#295 | fix tests<commit_after># Author:: <NAME> <<EMAIL>>
# Cookbook:: teracy-dev
# Recipe:: docker_registry
# Login into the Docker registries

docker_conf = node['docker']

docker_registry_conf = node['docker_registry']

if docker_conf['enabled'] == true
    execute 'rm ~/.docker/config.json' do
        command 'rm /home/vagrant/.docker/config.json || true'
        only_if {
            docker_registry_conf['force'] == true and
            File.exist?('/home/vagrant/.docker/config.json')
        }
    end

    docker_registry_conf['entries'].each.with_index do |entry, index|
        # private registry login

        username = entry['username'] ? entry['username'] : ''

        password = entry['password'] ? entry['password'] : ''

        if not username.empty? and not password.empty?
            opt = [
                "-u #{username}",
                "-p #{password}"
            ].join(' ');

            execute 'docker login' do
                command "docker login #{entry['host']} #{opt}"
                # because we need root to execute docker-compose, not 'vagrant'
                only_if {
                    docker_registry_conf['force'] == true or
                    not File.exist?('/root/.docker/config.json')
                }
            end
        end
    end

    execute 'copy /root/.docker/config.json to ~/.docker/config.json' do
        command 'cp /root/.docker/config.json /home/vagrant/.docker/config.json'
        only_if {
            File.exist?('/root/.docker/config.json') and (
                docker_registry_conf['force'] == true or
                not File.exist?('/home/vagrant/.docker/config.json')
            )
{'fraction_non_alphanumeric': 0.13870581186339126, 'fraction_numerical': 0.0008987417615338526, 'mean_word_length': 1.9136125654450262, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6715086', 'n_tokens_mistral': 991, 'n_tokens_neox': 906, 'n_words': 210}