<commit_before>container_path = '/var/lib/container/swarm'

discovery = node['docker-simple']['swarm']['discovery']
worker_addr = node['docker-simple']['swarm']['worker']['addr']
manager_strategy = node['docker-simple']['swarm']['manager']['strategy']
certs_path = node['docker-simple']['swarm']['tls']['certs_path']

compose = {
  'version' => '2',
  'services' => {
    'worker' => {
      'image' => 'swarm',
      'command' => "join --advertise=#{worker_addr}:2376 #{discovery}"
    },
    'manager' => {
      'image' => 'swarm',
      'command' => [
        'manage',
        '--host 0.0.0.0:3376',
        "--strategy=#{manager_strategy}",
        '--tls',
        '--tlscacert=/certs/ca.pem',
        '--tlscert=/certs/cert.pem',
        '--tlskey=/certs/key.pem',
        discovery].join(' '),
      'volumes' => [
        "#{certs_path}:/certs:ro"
      ],
      'ports' => ["#{worker_addr}:3376:3376"],
      'environment' => {
        'SERVICE_3376_NAME' => 'swarm'
      }
    }
  }
}

directory container_path do
  owner 'root'
  group 'docker'
  mode '0644'
  recursive true
  action :create
end

chef_gem 'psych'
require 'psych'

file "#{container_path}/docker-compose.yml" do<commit_msg>Sets 'unless-stopped' restart policy for  swarm worker/manager<commit_after>container_path = '/var/lib/container/swarm'

discovery = node['docker-simple']['swarm']['discovery']
worker_addr = node['docker-simple']['swarm']['worker']['addr']
manager_strategy = node['docker-simple']['swarm']['manager']['strategy']
certs_path = node['docker-simple']['swarm']['tls']['certs_path']

compose = {
  'version' => '2',
  'services' => {
    'worker' => {
      'image' => 'swarm',
      'command' => "join --advertise=#{worker_addr}:2376 #{discovery}"
      'restart' => 'unless-stopped'
    },
    'manager' => {
      'image' => 'swarm',
      'command' => [
        'manage',
        '--host 0.0.0.0:3376',
        "--strategy=#{manager_strategy}",
        '--tls',
        '--tlscacert=/certs/ca.pem',
        '--tlscert=/certs/cert.pem',
        '--tlskey=/certs/key.pem',
        discovery].join(' '),
      'volumes' => [
        "#{certs_path}:/certs:ro"
      ],
      'ports' => ["#{worker_addr}:3376:3376"],
      'environment' => {
        'SERVICE_3376_NAME' => 'swarm'
      },
      'restart' => 'unless-stopped'
    }
  }
}

directory container_path do
  owner 'root'
  group 'docker'
  mode '0644'
  recursive true
  action :create
end

chef_gem 'psych'
require 'psych'

file "#{container_path}/docker-compose.yml" do
{'fraction_non_alphanumeric': 0.21462450592885376, 'fraction_numerical': 0.02292490118577075, 'mean_word_length': 2.979559748427673, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '4691988', 'n_tokens_mistral': 957, 'n_tokens_neox': 907, 'n_words': 133}