From 4eb9439a51b708fdc96a160e59af745c6d52dc94 Mon Sep 17 00:00:00 2001 From: noppoman Date: Wed, 11 Oct 2017 04:03:57 +0900 Subject: [PATCH 1/3] pass the executable name to the deploy command instead of target name --- Sources/Hexaville/main.swift | 10 +++++----- Sources/HexavilleCore/Launcher/Launcher.swift | 10 +++++----- .../launcherProvider/AWSLauncherProvider.swift | 14 +++++++------- .../DockerBuildEnvironmentProvider.swift | 6 +++--- .../SwiftBuildEnvironmentProvider.swift | 2 +- .../HexavilleCore/SwiftBuilder/SwiftBuilder.swift | 4 ++-- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/Sources/Hexaville/main.swift b/Sources/Hexaville/main.swift index a737fbf..b466202 100644 --- a/Sources/Hexaville/main.swift +++ b/Sources/Hexaville/main.swift @@ -38,12 +38,12 @@ class GenerateProject: Command { let name = "generate" let shortDescription = "Generate initial project" let projectName = Parameter() - let swiftToolVersion = Key("--swift-tools-version", description: "Major Swift Tool Version for this project. default is 3.1") + let swiftToolVersion = Key("--swift-tools-version", description: "Major Swift Tool Version for this project. default is 4.0") let dest = Key("-o", "--dest", description: "Destination for the project") private func resolveSwiftVersion() throws -> SwiftVersionContainer { guard let version = swiftToolVersion.value else { - // default is 3.1 + // default is 4.0 return Configuration.SwiftConfiguration.defaultVersion } @@ -144,7 +144,7 @@ class RoutesCommand: Command { let launcher = Launcher( hexavilleApplicationPath: cwd, - executableTarget: "\(cwd)".components(separatedBy: "/").last ?? "", + executable: "\(cwd)".components(separatedBy: "/").last ?? "", configuration: config, deploymentStage: deploymentStage ) @@ -159,7 +159,7 @@ class RoutesCommand: Command { class Deploy: Command { let name = "deploy" let shortDescription = "Deploy your application to the specified cloud provider" - let target = Parameter() + let executableName = Parameter() let hexavillefilePath = Key("-c", "--hexavillefile", description: "Path for the Hexavillefile.yml") let stage = Key("--stage", description: "Deployment Stage. default is staging") @@ -192,7 +192,7 @@ class Deploy: Command { let launcher = Launcher( hexavilleApplicationPath: hexavileApplicationPath, - executableTarget: target.value, + executable: executableName.value, configuration: config, deploymentStage: deploymentStage ) diff --git a/Sources/HexavilleCore/Launcher/Launcher.swift b/Sources/HexavilleCore/Launcher/Launcher.swift index e7b9d04..2aa0cc6 100644 --- a/Sources/HexavilleCore/Launcher/Launcher.swift +++ b/Sources/HexavilleCore/Launcher/Launcher.swift @@ -73,16 +73,16 @@ public class Launcher { let hexavilleApplicationPath: String - let executableTarget: String + let executable: String let deploymentStage: DeploymentStage let configuration: Configuration - public init(hexavilleApplicationPath: String, executableTarget: String, configuration: Configuration, deploymentStage: DeploymentStage = .staging) { + public init(hexavilleApplicationPath: String, executable: String, configuration: Configuration, deploymentStage: DeploymentStage = .staging) { self.provider = configuration.createProvider() self.hexavilleApplicationPath = hexavilleApplicationPath - self.executableTarget = executableTarget + self.executable = executable self.configuration = configuration self.deploymentStage = deploymentStage } @@ -120,7 +120,7 @@ public class Launcher { return try builder.build( config: configuration, hexavilleApplicationPath: hexavilleApplicationPath, - executableTarget: executableTarget + executable: executable ) } @@ -133,7 +133,7 @@ public class Launcher { deploymentStage: deploymentStage, buildResult: result, hexavilleApplicationPath: hexavilleApplicationPath, - executableTarget: executableTarget + executable: executable ) print("######################################################") diff --git a/Sources/HexavilleCore/Launcher/launcherProvider/AWSLauncherProvider.swift b/Sources/HexavilleCore/Launcher/launcherProvider/AWSLauncherProvider.swift index d855788..c6d83ae 100644 --- a/Sources/HexavilleCore/Launcher/launcherProvider/AWSLauncherProvider.swift +++ b/Sources/HexavilleCore/Launcher/launcherProvider/AWSLauncherProvider.swift @@ -111,14 +111,14 @@ extension AWSLauncherProvider { return content } - fileprivate func zipPackage(buildResult: BuildResult, hexavilleApplicationPath: String, executableTarget: String) throws -> Data { + fileprivate func zipPackage(buildResult: BuildResult, hexavilleApplicationPath: String, executable: String) throws -> Data { let nodejsTemplatePath = try Finder.findTemplatePath(for: "/lambda/node.js") let pkgFileName = "\(hexavilleApplicationPath)/lambda-package.zip" try String(contentsOfFile: "\(nodejsTemplatePath)/index.js", encoding: .utf8) - .replacingOccurrences(of: "{{executablePath}}", with: executableTarget) + .replacingOccurrences(of: "{{executablePath}}", with: executable) .write(toFile: buildResult.destination+"/index.js", atomically: true, encoding: .utf8) try String(contentsOfFile: "\(nodejsTemplatePath)/byline.js", encoding: .utf8) @@ -132,7 +132,7 @@ extension AWSLauncherProvider { let shellPath = "/tmp/build-lambda-package.sh" let shellContent = lambdaPackageShellContent() try shellContent.write(toFile: shellPath, atomically: true, encoding: .utf8) - let proc = Proc("/bin/sh", [shellPath, pkgFileName, buildResult.destination, executableTarget]) + let proc = Proc("/bin/sh", [shellPath, pkgFileName, buildResult.destination, executable]) if proc.terminationStatus > 0 { throw AWSLauncherProviderError.couldNotZipPackage @@ -500,13 +500,13 @@ extension AWSLauncherProvider { _ = try s3.createBucket(input) } - fileprivate func uploadCodeToS3(buildResult: BuildResult, hexavilleApplicationPath: String, executableTarget: String) throws -> Lambda.FunctionCode { + fileprivate func uploadCodeToS3(buildResult: BuildResult, hexavilleApplicationPath: String, executable: String) throws -> Lambda.FunctionCode { print("Starting zip package........") let zipData = try zipPackage( buildResult: buildResult, hexavilleApplicationPath: hexavilleApplicationPath, - executableTarget: executableTarget + executable: executable ) print("Zip package done.") @@ -621,8 +621,8 @@ extension AWSLauncherProvider { return Routes(endpoint: endpoint(restApiId: api.id!, deploymentStage: deploymentStage), routes: routes) } - func deploy(deploymentStage: DeploymentStage, buildResult: BuildResult, hexavilleApplicationPath: String, executableTarget: String) throws -> DeployResult { - let code = try uploadCodeToS3(buildResult: buildResult, hexavilleApplicationPath: hexavilleApplicationPath, executableTarget: executableTarget) + func deploy(deploymentStage: DeploymentStage, buildResult: BuildResult, hexavilleApplicationPath: String, executable: String) throws -> DeployResult { + let code = try uploadCodeToS3(buildResult: buildResult, hexavilleApplicationPath: hexavilleApplicationPath, executable: executable) let lambdaConfiguration = try updateFunctionCode(code: code) diff --git a/Sources/HexavilleCore/SwiftBuilder/SwiftBuildEnvironmentProvider/DockerBuildEnvironmentProvider.swift b/Sources/HexavilleCore/SwiftBuilder/SwiftBuildEnvironmentProvider/DockerBuildEnvironmentProvider.swift index 0e7b5e6..8d4c7ab 100644 --- a/Sources/HexavilleCore/SwiftBuilder/SwiftBuildEnvironmentProvider/DockerBuildEnvironmentProvider.swift +++ b/Sources/HexavilleCore/SwiftBuilder/SwiftBuildEnvironmentProvider/DockerBuildEnvironmentProvider.swift @@ -20,7 +20,7 @@ struct DockerBuildEnvironmentProvider: SwiftBuildEnvironmentProvider { return ProcessInfo.processInfo.environment["DOCKER_PATH"] ?? "docker" } - func build(config: Configuration, hexavilleApplicationPath: String, executableTarget: String) throws -> BuildResult { + func build(config: Configuration, hexavilleApplicationPath: String, executable: String) throws -> BuildResult { let templatePath = try Finder.findTemplatePath() let buildSwiftShellPath = try Finder.findScriptPath(for: "build-swift.sh") @@ -37,7 +37,7 @@ struct DockerBuildEnvironmentProvider: SwiftBuildEnvironmentProvider { try String(contentsOfFile: templatePath+"/Dockerfile", encoding: .utf8) .replacingOccurrences(of: "{{SWIFT_DOWNLOAD_URL}}", with: config.forSwift.version.downloadURLString) .replacingOccurrences(of: "{{SWIFTFILE}}", with: config.forSwift.version.fileName) - .replacingOccurrences(of: "{{EXECUTABLE_NAME}}", with: executableTarget) + .replacingOccurrences(of: "{{EXECUTABLE_NAME}}", with: executable) .replacingOccurrences(of: "{{DEST}}", with: dest) .write( toFile: hexavilleApplicationPath+"/Dockerfile", @@ -52,7 +52,7 @@ struct DockerBuildEnvironmentProvider: SwiftBuildEnvironmentProvider { encoding: .utf8 ) - let tag = executableTarget.lowercased() + let tag = executable.lowercased() var opts = ["build", "-t", tag, "-f", "\(hexavilleApplicationPath)/Dockerfile", hexavilleApplicationPath] if config.forBuild.noCache { diff --git a/Sources/HexavilleCore/SwiftBuilder/SwiftBuildEnvironmentProvider/SwiftBuildEnvironmentProvider.swift b/Sources/HexavilleCore/SwiftBuilder/SwiftBuildEnvironmentProvider/SwiftBuildEnvironmentProvider.swift index 8c3f968..b9608f3 100644 --- a/Sources/HexavilleCore/SwiftBuilder/SwiftBuildEnvironmentProvider/SwiftBuildEnvironmentProvider.swift +++ b/Sources/HexavilleCore/SwiftBuilder/SwiftBuildEnvironmentProvider/SwiftBuildEnvironmentProvider.swift @@ -17,5 +17,5 @@ struct BuildResult { } protocol SwiftBuildEnvironmentProvider { - func build(config: Configuration, hexavilleApplicationPath: String, executableTarget: String) throws -> BuildResult + func build(config: Configuration, hexavilleApplicationPath: String, executable: String) throws -> BuildResult } diff --git a/Sources/HexavilleCore/SwiftBuilder/SwiftBuilder.swift b/Sources/HexavilleCore/SwiftBuilder/SwiftBuilder.swift index c943021..ecd4c15 100644 --- a/Sources/HexavilleCore/SwiftBuilder/SwiftBuilder.swift +++ b/Sources/HexavilleCore/SwiftBuilder/SwiftBuilder.swift @@ -19,12 +19,12 @@ class SwiftBuilder { self.version = version } - func build(with defaultProvider: SwiftBuildEnvironmentProvider? = nil, config: Configuration, hexavilleApplicationPath: String, executableTarget: String) throws -> BuildResult { + func build(with defaultProvider: SwiftBuildEnvironmentProvider? = nil, config: Configuration, hexavilleApplicationPath: String, executable: String) throws -> BuildResult { let provider = DockerBuildEnvironmentProvider() return try provider.build( config: config, hexavilleApplicationPath: hexavilleApplicationPath, - executableTarget: executableTarget + executable: executable ) } } From a0af5d48d84ac8ff8cac56c53488b1650f54e22a Mon Sep 17 00:00:00 2001 From: noppoman Date: Wed, 11 Oct 2017 04:04:08 +0900 Subject: [PATCH 2/3] small fix --- Scripts/zip.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Scripts/zip.sh b/Scripts/zip.sh index 7db99d7..ad58f47 100755 --- a/Scripts/zip.sh +++ b/Scripts/zip.sh @@ -3,7 +3,7 @@ set -e SWIFTFILE=../${SWIFTFILE} -DEST=.build/release +DEST=.build/${BUILD_CONFIGURATION} swift package update swift build -c ${BUILD_CONFIGURATION} cp -r /${SWIFTFILE}/usr/lib/swift/linux/*.so $DEST From 507b7a804f7d150159d9d310083438bfbcb41673 Mon Sep 17 00:00:00 2001 From: noppoman Date: Wed, 11 Oct 2017 04:04:12 +0900 Subject: [PATCH 3/3] add explanation of executableName --- README.md | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 833d047..e0ca8b8 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,7 @@ if `service` is `aws` ### Deploy a Project -`Usage: hexaville deploy ` +`Usage: hexaville deploy ` Use this when you have made changes to your Functions, Events or Resources. This operation take a while. @@ -157,7 +157,23 @@ cd /path/to/your/app hexaville deploy Hello ``` -Got `bucketAlreadyExists` Error? +#### Troubleshooting + +**1. What is executableName?** + +`` is a name that specified in `products(name: 'executableName')` on Package.swift. In following case, it's a `my-app` not `MyApp`. + +```swift +let package = Package( + name: "MyApp", + products: [ + .executable(name: "my-app", targets: ["MyApp"]) + ], + .... +) +``` + +**2. Got `bucketAlreadyExists` Error?** If you got **bucketAlreadyExists("The requested bucket name is not available. The bucket namespace is shared by all users of the system. Please select a different name and try again.")**, Change the bucket name for lambda in the Hexavillfile.yml