Skip to content

Commit 130de1a

Browse files
committed
(maint) Allow configurable volumes root
- With long-running hosts, rooting the volumes inside of the git cloned source directory is problematic. When tests are cancelled and containers remain running, files can be locked, preventing subsequent runs from proceeding correctly. Instead, generate a temporary directory in Azure to root the files so that source can be cloned properly. - This removes the need for cleaning up existing hardcoded dirs in Azure from prior test runs - For now this will continue to default to `.` in Travis, given hosts are ephemeral - Additional code will be added to perform cleanup from tests - The Azure specific PowerShell code converts a Windows path like: c:\foo\bar\tmp.foo To something compose understands like: //c/foo/bar/tmp.foo See docker/compose#4303 (comment)
1 parent 4edd39c commit 130de1a

4 files changed

+18
-15
lines changed

azure-pipelines.yml

+10-7
Original file line numberDiff line numberDiff line change
@@ -60,27 +60,30 @@ steps:
6060
bundle install --with test --path '.bundle/gems'
6161
# make sure windows yml slots in as the default override
6262
Copy-Item ./docker-compose.windows.yml ./docker-compose.override.yml -Force
63-
Write-Host 'Forcibly removing previous cluster config / data'
64-
Remove-Item 'volumes' -Force -Recurse -ErrorAction SilentlyContinue;
65-
New-Item 'volumes' -Type Directory
66-
Push-Location 'volumes'
67-
'code', 'puppet', 'serverdata', 'puppetdb\ssl', 'puppetdb-postgres\data' |
68-
% { New-Item $_ -Type Directory }
69-
Pop-Location
7063
displayName: Prepare Test Environment
7164
name: test_prepare
7265

7366
- powershell: |
7467
$domain = Get-WmiObject -Class Win32_NetworkAdapterConfiguration |
7568
Select -ExpandProperty DNSDomain |
7669
Select -First 1
70+
$tempVolumeRoot = Join-Path -Path $ENV:TEMP -ChildPath ([System.IO.Path]::GetRandomFileName())
71+
# Make sure to convert Windows style c:\ to compose friendly //c/
7772
Write-Host 'Writing compose config to disk'
7873
$content = @"
7974
AZURE_DOMAIN=$domain
75+
VOLUME_ROOT=$(($tempVolumeRoot.ToLower() -replace '\\', '/') -replace '^([a-z]):', '//$1')
8076
"@
8177
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
8278
[System.IO.File]::WriteAllLines(".env", $content, $Utf8NoBomEncoding)
8379
Get-Content -Path '.env'
80+
Write-Host "Creating volumes directory structure in $tempVolumeRoot"
81+
New-Item $tempVolumeRoot -Type Directory
82+
Push-Location $tempVolumeRoot
83+
New-Item 'volumes' -Type Directory
84+
'volumes\code', 'volumes\puppet', 'volumes\serverdata', 'volumes\puppetdb\ssl', 'volumes\puppetdb-postgres\data' |
85+
% { New-Item $_ -Type Directory }
86+
Pop-Location
8487
Write-Host 'Executing Pupperware specs'
8588
bundle exec rspec --version
8689
bundle exec rspec spec --fail-fast

docker-compose.override.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ services:
44
postgres:
55
image: postgres:9.6
66
volumes:
7-
- ./volumes/puppetdb-postgres/data:/var/lib/postgresql/data/
8-
- ./postgres-custom:/docker-entrypoint-initdb.d
7+
- ${VOLUME_ROOT:-.}/volumes/puppetdb-postgres/data:/var/lib/postgresql/data/
8+
- ${VOLUME_ROOT:-.}/postgres-custom:/docker-entrypoint-initdb.d

docker-compose.windows.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ services:
1212
environment:
1313
- PGDATA=c:\data
1414
volumes:
15-
- ./volumes/puppetdb-postgres/data:c:\data
16-
- ./postgres-custom:c:\docker-entrypoint-initdb.d
15+
- ${VOLUME_ROOT:-.}/volumes/puppetdb-postgres/data:c:\data
16+
- ${VOLUME_ROOT:-.}/postgres-custom:c:\docker-entrypoint-initdb.d

docker-compose.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ services:
1414
- DNS_ALT_NAMES=puppet,${DNS_ALT_NAMES:-}
1515
- PUPPETDB_SERVER_URLS=https://puppetdb:8081
1616
volumes:
17-
- ./volumes/code:/etc/puppetlabs/code/
18-
- ./volumes/puppet:/etc/puppetlabs/puppet/
19-
- ./volumes/serverdata:/opt/puppetlabs/server/data/puppetserver/
17+
- ${VOLUME_ROOT:-.}/volumes/code:/etc/puppetlabs/code/
18+
- ${VOLUME_ROOT:-.}/volumes/puppet:/etc/puppetlabs/puppet/
19+
- ${VOLUME_ROOT:-.}/volumes/serverdata:/opt/puppetlabs/server/data/puppetserver/
2020

2121
postgres:
2222
environment:
@@ -43,7 +43,7 @@ services:
4343
- postgres
4444
- puppet
4545
volumes:
46-
- ./volumes/puppetdb/ssl:/etc/puppetlabs/puppet/ssl/
46+
- ${VOLUME_ROOT:-.}/volumes/puppetdb/ssl:/etc/puppetlabs/puppet/ssl/
4747

4848
networks:
4949
default:

0 commit comments

Comments
 (0)