Skip to content

Commit d325cf1

Browse files
authored
Merge pull request #84 from noppoMan/enhancement-around-docker
enhancement around docker
2 parents 6c46e28 + dc5f173 commit d325cf1

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

Sources/HexavilleCore/SwiftBuilder/SwiftBuildEnvironmentProvider/DockerBuildEnvironmentProvider.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,46 @@ import Foundation
1010

1111

1212
enum DockerBuildEnvironmentProviderError: Error {
13+
case dockerIsNotFound
1314
case dockerBuildFailed
1415
case couldNotMakeSharedDir
1516
}
1617

18+
extension DockerBuildEnvironmentProviderError: CustomStringConvertible {
19+
var description: String {
20+
switch self {
21+
case .dockerIsNotFound:
22+
return """
23+
[DockerBuildEnvironmentProviderError] Could not find 'docker' in your machine. Please install docker.
24+
25+
See Official installation guides with 'open https://docs.docker.com/engine/installation'
26+
27+
28+
"""
29+
30+
case .dockerBuildFailed:
31+
return "[DockerBuildEnvironmentProviderError] docker build is failed with the above reason."
32+
33+
case .couldNotMakeSharedDir:
34+
return "[DockerBuildEnvironmentProviderError] Could not make shared directory between Host machine and Docker. Please make sure permission of your working directory."
35+
}
36+
}
37+
}
38+
1739
struct DockerBuildEnvironmentProvider: SwiftBuildEnvironmentProvider {
1840

1941
var dockerExecutablePath: String {
2042
return ProcessInfo.processInfo.environment["DOCKER_PATH"] ?? "docker"
2143
}
2244

2345
func build(config: Configuration, hexavilleApplicationPath: String, executable: String) throws -> BuildResult {
46+
47+
print("\nDocker version")
48+
let dockerVersionResult = Process.exec("docker", ["version"])
49+
if dockerVersionResult.terminationStatus != 0 {
50+
throw DockerBuildEnvironmentProviderError.dockerIsNotFound
51+
}
52+
2453
let templatePath = try Finder.findTemplatePath()
2554
let buildSwiftShellPath = try Finder.findScriptPath(for: "build-swift.sh")
2655

0 commit comments

Comments
 (0)