<commit_before>$ErrorActionPreference = 'Stop'

function addRegistryToDaemonJson() {
  Write-Host "Adding registry"
  $daemonJson = "$env:ProgramData\docker\config\daemon.json"
  $config = @{}
  if (Test-Path $daemonJson) {
    $config = (Get-Content $daemonJson) -join "`n" | ConvertFrom-Json
  }
  $config = $config | Add-Member(@{ `
    'insecure-registries' = @("myregistry:5000"); `
  }) -Force -PassThru
  $config | ConvertTo-Json | Set-Content $daemonJson -Encoding Ascii
}

function addHosts() {
  $ip = $(docker inspect -f '{{ .NetworkSettings.Networks.nat.IPAddress }}' registry)
  Write-Host "$ip myregistry" | Out-File -Encoding Ascii -Append C:\Windows\system32\drivers\etc\hosts
}

function runRegistry() {
  if (!(Test-Path C:\registry)) { mkdir C:\registry }
  docker run -d -p 5000:5000 --restart=always --name registry -v C:\registry:C:\registry registry:2.6.2
}


addRegistryToDaemonJson
restart-service docker
runRegistry
addHosts

Write-Host Pushing an image to local registry
docker tag registry:2.6.2 myregistry:5000/registry:2.6.2
docker push myregistry:5000/registry:2.6.2

Write-Host Checking if local registry files are stored on host
dir C:\registry\docker\registry\v2\repositories\registry\<commit_msg>Fix writing ip to etc/hosts<commit_after>$ErrorActionPreference = 'Stop'

function addRegistryToDaemonJson() {
  Write-Host "Adding registry"
  $daemonJson = "$env:ProgramData\docker\config\daemon.json"
  $config = @{}
  if (Test-Path $daemonJson) {
    $config = (Get-Content $daemonJson) -join "`n" | ConvertFrom-Json
  }
  $config = $config | Add-Member(@{ `
    'insecure-registries' = @("myregistry:5000"); `
  }) -Force -PassThru
  $config | ConvertTo-Json | Set-Content $daemonJson -Encoding Ascii
}

function addHosts() {
  $ip = $(docker inspect -f '{{ .NetworkSettings.Networks.nat.IPAddress }}' registry)
  "" | Out-File -Encoding Ascii -Append C:\Windows\system32\drivers\etc\hosts
  "$ip myregistry" | Out-File -Encoding Ascii -Append C:\Windows\system32\drivers\etc\hosts
}

function runRegistry() {
  if (!(Test-Path C:\registry)) { mkdir C:\registry }
  docker run -d -p 5000:5000 --restart=always --name registry -v C:\registry:C:\registry registry:2.6.2
}


addRegistryToDaemonJson
restart-service docker
runRegistry
addHosts

Write-Host Pushing an image to local registry
docker tag registry:2.6.2 myregistry:5000/registry:2.6.2
docker push myregistry:5000/registry:2.6.2

Write-Host Checking if local registry files are stored on host
dir C:\registry\docker\registry\v2\repositories\registry\
{'fraction_non_alphanumeric': 0.13841918993314983, 'fraction_numerical': 0.028313016122689737, 'mean_word_length': 4.401273885350318, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2594323', 'n_tokens_mistral': 906, 'n_tokens_neox': 839, 'n_words': 201}