-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathcopy_scripts.ps1
More file actions
86 lines (70 loc) · 2.88 KB
/
copy_scripts.ps1
File metadata and controls
86 lines (70 loc) · 2.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# Define the source directory
$sourceDir = "./scripts/"
# Define the container
$containerName = "kolo_container"
# Check if the source directory exists
if (-Not (Test-Path $sourceDir)) {
Write-Host "Error: Source directory does not exist: $sourceDir" -ForegroundColor Red
exit 1
}
# Function to remove a file inside the container
function Remove-ContainerFile($container, $destinationPath) {
docker exec $container rm -f $destinationPath | Out-Null
}
# Function to remove a folder inside the container
function Remove-ContainerFolder($container, $destinationPath) {
docker exec $container rm -rf $destinationPath | Out-Null
}
# Copy files from the source directory
$files = Get-ChildItem -Path $sourceDir -File
if ($files.Count -gt 0) {
foreach ($file in $files) {
$filePath = $file.FullName
$destinationPath = "/app/$($file.Name)"
Write-Host "Removing any existing file at $destinationPath in container $containerName..."
Remove-ContainerFile -container $containerName -destinationPath $destinationPath
Write-Host "Copying file $filePath to container $containerName at $destinationPath..."
try {
docker cp "$filePath" "$containerName`:$destinationPath"
if ($?) {
Write-Host "Successfully copied $($file.Name)" -ForegroundColor Green
}
else {
Write-Host "Failed to copy $($file.Name)" -ForegroundColor Red
}
}
catch {
Write-Host "An error occurred while copying $($file.Name): $_" -ForegroundColor Red
}
}
}
else {
Write-Host "No files found in $sourceDir" -ForegroundColor Yellow
}
# Copy directories from the source directory
$folders = Get-ChildItem -Path $sourceDir -Directory
if ($folders.Count -gt 0) {
foreach ($folder in $folders) {
$folderPath = $folder.FullName
$destinationPath = "/app/$($folder.Name)"
Write-Host "Removing any existing folder at $destinationPath in container $containerName..."
Remove-ContainerFolder -container $containerName -destinationPath $destinationPath
Write-Host "Copying folder $folderPath to container $containerName at $destinationPath..."
try {
docker cp "$folderPath" "$containerName`:$destinationPath"
if ($?) {
Write-Host "Successfully copied folder $($folder.Name)" -ForegroundColor Green
}
else {
Write-Host "Failed to copy folder $($folder.Name)" -ForegroundColor Red
}
}
catch {
Write-Host "An error occurred while copying folder $($folder.Name): $_" -ForegroundColor Red
}
}
}
else {
Write-Host "No folders found in $sourceDir" -ForegroundColor Yellow
}
Write-Host "All files and folders processed." -ForegroundColor Cyan