Skip to content

Commit

Permalink
Merge pull request #80 from noppoMan/executable-name
Browse files Browse the repository at this point in the history
Executable name
  • Loading branch information
noppoMan authored Oct 11, 2017
2 parents 6106f92 + 507b7a8 commit 3795c30
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 26 deletions.
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ if `service` is `aws`

### Deploy a Project

`Usage: hexaville deploy <target>`
`Usage: hexaville deploy <executableName>`

Use this when you have made changes to your Functions, Events or Resources.
This operation take a while.
Expand All @@ -157,7 +157,23 @@ cd /path/to/your/app
hexaville deploy Hello
```

Got `bucketAlreadyExists` Error?
#### Troubleshooting

**1. What is executableName?**

`<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

Expand Down
2 changes: 1 addition & 1 deletion Scripts/zip.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions Sources/Hexaville/main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ class GenerateProject: Command {
let name = "generate"
let shortDescription = "Generate initial project"
let projectName = Parameter()
let swiftToolVersion = Key<String>("--swift-tools-version", description: "Major Swift Tool Version for this project. default is 3.1")
let swiftToolVersion = Key<String>("--swift-tools-version", description: "Major Swift Tool Version for this project. default is 4.0")
let dest = Key<String>("-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
}

Expand Down Expand Up @@ -148,7 +148,7 @@ class RoutesCommand: Command {

let launcher = Launcher(
hexavilleApplicationPath: cwd,
executableTarget: "\(cwd)".components(separatedBy: "/").last ?? "",
executable: "\(cwd)".components(separatedBy: "/").last ?? "",
configuration: config,
deploymentStage: deploymentStage
)
Expand All @@ -163,7 +163,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<String>("-c", "--hexavillefile", description: "Path for the Hexavillefile.yml")
let stage = Key<String>("--stage", description: "Deployment Stage. default is staging")

Expand Down Expand Up @@ -197,7 +197,7 @@ class Deploy: Command {

let launcher = Launcher(
hexavilleApplicationPath: hexavileApplicationPath,
executableTarget: target.value,
executable: executableName.value,
configuration: config,
deploymentStage: deploymentStage
)
Expand Down
10 changes: 5 additions & 5 deletions Sources/HexavilleCore/Launcher/Launcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -120,7 +120,7 @@ public class Launcher {
return try builder.build(
config: configuration,
hexavilleApplicationPath: hexavilleApplicationPath,
executableTarget: executableTarget
executable: executable
)
}

Expand All @@ -133,7 +133,7 @@ public class Launcher {
deploymentStage: deploymentStage,
buildResult: result,
hexavilleApplicationPath: hexavilleApplicationPath,
executableTarget: executableTarget
executable: executable
)

print("######################################################")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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.")

Expand Down Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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",
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
4 changes: 2 additions & 2 deletions Sources/HexavilleCore/SwiftBuilder/SwiftBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
}
}

0 comments on commit 3795c30

Please sign in to comment.