Skip to content

Commit b29a2a4

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 (on Windows) to root the files so that source can be cloned properly. - This removes the need for cleaning up existing hardcoded dirs from prior test runs, but we still make a best effort in the Azure job to do cleanup - For now this will continue to default to `.` in Travis, given hosts are ephemeral. On Windows hosts, this will be in the temp dir for the given user. docker-compose understands Windows paths on the left hand side of the volume mapping, so no conversions are necessary. This was not always the case per: docker/compose#4303 (comment) - Stuff the temp dir in an Azure variable so it can be used in a later cleanup stage - Set the temp dir to give Users group full control to prevent the containers from running into permissions issues - Additional code will be added to perform cleanup from tests
1 parent 2d0ada9 commit b29a2a4

4 files changed

+21
-13
lines changed

commercial/azure-pipelines.yml

+15-7
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,9 @@ 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
63+
# set an Azure variable for temp volumes root
64+
$tempVolumeRoot = Join-Path -Path $ENV:TEMP -ChildPath ([System.IO.Path]::GetRandomFileName())
65+
Write-Host "##vso[task.setvariable variable=TempVolumeRoot]$tempVolumeRoot"
7066
displayName: Prepare Test Environment
7167
name: test_prepare
7268

@@ -77,10 +73,20 @@ steps:
7773
Write-Host 'Writing compose config to disk'
7874
$content = @"
7975
AZURE_DOMAIN=$domain
76+
VOLUME_ROOT=$ENV:TempVolumeRoot
8077
"@
8178
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False
8279
[System.IO.File]::WriteAllLines(".env", $content, $Utf8NoBomEncoding)
8380
Get-Content -Path '.env'
81+
Write-Host "Creating volumes directory structure in $ENV:TempVolumeRoot"
82+
New-Item $ENV:TempVolumeRoot -Type Directory
83+
Push-Location $ENV:TempVolumeRoot
84+
New-Item 'volumes' -Type Directory
85+
'volumes\code', 'volumes\puppet', 'volumes\serverdata', 'volumes\puppetdb\ssl', 'volumes\puppetdb-postgres\data' |
86+
% { New-Item $_ -Type Directory }
87+
Pop-Location
88+
# Hack: grant all users access to this temp dir for the sake of Docker daemon
89+
icacls $ENV:TempVolumeRoot /grant Users:"(OI)(CI)F" /T
8490
Write-Host 'Executing Pupperware specs'
8591
bundle exec rspec --version
8692
bundle exec rspec spec --fail-fast
@@ -100,6 +106,8 @@ steps:
100106
docker container prune --force
101107
Write-Host 'Pruning images'
102108
docker image prune --filter "dangling=true" --force
109+
Write-Host "Cleaning up temporary volume: $ENV:TempVolumeRoot"
110+
Remove-Item $ENV:TempVolumeRoot -Force -Recurse -ErrorAction Continue
103111
displayName: Container Cleanup
104112
timeoutInMinutes: 3
105113
condition: always()

commercial/docker-compose.override.yml

+1-1
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/
7+
- ${VOLUME_ROOT:-.}/volumes/puppetdb-postgres/data:/var/lib/postgresql/data/
88
- ./postgres-custom:/docker-entrypoint-initdb.d

commercial/docker-compose.windows.yml

+1-1
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
15+
- ${VOLUME_ROOT:-.}/volumes/puppetdb-postgres/data:c:\data
1616
- ./postgres-custom:c:\docker-entrypoint-initdb.d

commercial/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)