<commit_before>/* @flow */

import os from 'os'
import path from 'path'
import yaml from 'js-yaml'
import fs from './util/fs'
import {execAsync} from './util/exec-async'
import {log} from './driver-logging'
import {getLaunchedNavyNames} from './navy'

async function updateComposeConfig(navies: Array<string>) {
  const networkIds = (await execAsync('docker', ['network', 'ls', '-q']))
  .split('\n')
  .map(net => net.trim())
  .filter(net => !!net)

  // example networks from navies
  // dev_default
  // myothernavy_default

  const networks = JSON.parse(await execAsync('docker', ['network', 'inspect', ...networkIds]))
  .filter(net => net.Name.indexOf('_') !== -1) // is docker-compose network?
  .filter(net => {
    for (const navy of navies) {
      if (net.Name.indexOf(navy + '_') === 0) {
        return true
      }
    }

    return false
  })

  const networksConfig = {}

  networks.forEach(net => networksConfig[net.Name] = {
    external: true,
  })

  const config = {
    version: '2',

    services: {
      'nginx-proxy': {
        image: 'jwilder/nginx-proxy:0.4.0',
        ports: [
          '80:80',
        ],
        networks: networks.map(net => net.Name),
        volumes: [
          '/var/run/docker.sock:/tmp/docker.sock:ro',
        ],
      },
    },

    networks: networksConfig,
  }

  await fs.writeFileAsync(path.join(os.tmpdir(), 'navyinternaldockercompose.yml'), yaml.dump(config))
}

export async function reconfigureHTTPProxy(opts: Object = {}) {
  if (!opts.navies) opts.navies = await getLaunchedNavyNames()

  await updateComposeConfig(opts.navies)
<commit_msg>Ensure HTTP proxy container always restarts<commit_after>/* @flow */

import os from 'os'
import path from 'path'
import yaml from 'js-yaml'
import fs from './util/fs'
import {execAsync} from './util/exec-async'
import {log} from './driver-logging'
import {getLaunchedNavyNames} from './navy'

async function updateComposeConfig(navies: Array<string>) {
  const networkIds = (await execAsync('docker', ['network', 'ls', '-q']))
  .split('\n')
  .map(net => net.trim())
  .filter(net => !!net)

  // example networks from navies
  // dev_default
  // myothernavy_default

  const networks = JSON.parse(await execAsync('docker', ['network', 'inspect', ...networkIds]))
  .filter(net => net.Name.indexOf('_') !== -1) // is docker-compose network?
  .filter(net => {
    for (const navy of navies) {
      if (net.Name.indexOf(navy + '_') === 0) {
        return true
      }
    }

    return false
  })

  const networksConfig = {}

  networks.forEach(net => networksConfig[net.Name] = {
    external: true,
  })

  const config = {
    version: '2',

    services: {
      'nginx-proxy': {
        image: 'jwilder/nginx-proxy:0.4.0',
        ports: [
          '80:80',
        ],
        networks: networks.map(net => net.Name),
        volumes: [
          '/var/run/docker.sock:/tmp/docker.sock:ro',
        ],
        restart: 'always',
      },
    },

    networks: networksConfig,
  }

  await fs.writeFileAsync(path.join(os.tmpdir(), 'navyinternaldockercompose.yml'), yaml.dump(config))
}

export async function reconfigureHTTPProxy(opts: Object = {}) {
  if (!opts.navies) opts.navies = await getLaunchedNavyNames()

  await updateComposeConfig(opts.navies)

{'fraction_non_alphanumeric': 0.16610687022900764, 'fraction_numerical': 0.0061068702290076335, 'mean_word_length': 2.9186602870813396, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '6415245', 'n_tokens_mistral': 1109, 'n_tokens_neox': 1082, 'n_words': 241}