-
-
Notifications
You must be signed in to change notification settings - Fork 292
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed an issue where subdirectories were not added to the Dockerfile …
- Loading branch information
1 parent
5cbe737
commit 1816910
Showing
6 changed files
with
118 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
namespace DotNet.Testcontainers.Core | ||
{ | ||
using System; | ||
using System.IO; | ||
using System.Linq; | ||
using ICSharpCode.SharpZipLib.Tar; | ||
|
||
public class DockerfileArchive : ITarArchive | ||
{ | ||
private static readonly DateTime DisableModTime = new DateTime(1970, 1, 1, 0, 0, 0, 0); | ||
|
||
public DockerfileArchive(string baseDirectory) : this(new DirectoryInfo(baseDirectory)) | ||
{ | ||
} | ||
|
||
public DockerfileArchive(DirectoryInfo baseDirectory) | ||
{ | ||
this.BaseDirectory = baseDirectory; | ||
|
||
this.DockerfileArchiveFile = new FileInfo($"{Path.GetTempPath()}/Dockerfile.tar"); | ||
|
||
if (!this.BaseDirectory.Exists) | ||
{ | ||
throw new ArgumentException($"Directory '{this.BaseDirectory.FullName}' does not exist."); | ||
} | ||
|
||
if (!this.BaseDirectory.GetFiles().Any(file => "Dockerfile".Equals(file.Name))) | ||
{ | ||
throw new ArgumentException($"Dockerfile does not exist in '{this.BaseDirectory.FullName}'."); | ||
} | ||
} | ||
|
||
public DirectoryInfo BaseDirectory { get; } | ||
|
||
public FileInfo DockerfileArchiveFile { get; } | ||
|
||
public string Tar() | ||
{ | ||
using (var dockerfileArchiveStream = File.Create(this.DockerfileArchiveFile.FullName)) | ||
{ | ||
using (var dockerfileArchive = TarArchive.CreateOutputTarArchive(dockerfileArchiveStream)) | ||
{ | ||
dockerfileArchive.RootPath = this.BaseDirectory.FullName; | ||
|
||
void Tar(string baseDirectory) | ||
{ | ||
void WriteEntry(string entry) | ||
{ | ||
var tarEntry = TarEntry.CreateEntryFromFile(entry); | ||
tarEntry.Name = entry.Replace(dockerfileArchive.RootPath, string.Empty); | ||
tarEntry.ModTime = DisableModTime; | ||
dockerfileArchive.WriteEntry(tarEntry, File.Exists(entry)); | ||
} | ||
|
||
if (!dockerfileArchive.RootPath.Equals(baseDirectory)) | ||
{ | ||
WriteEntry(baseDirectory); | ||
} | ||
|
||
Directory.GetFiles(baseDirectory).ToList().ForEach(WriteEntry); | ||
|
||
Directory.GetDirectories(baseDirectory).ToList().ForEach(Tar); | ||
} | ||
|
||
Tar(this.BaseDirectory.FullName); | ||
} | ||
} | ||
|
||
return this.DockerfileArchiveFile.FullName; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace DotNet.Testcontainers.Core | ||
{ | ||
public interface ITarArchive | ||
{ | ||
string Tar(); | ||
} | ||
} |