Skip to content

Commit

Permalink
Merge pull request #115 from noppoMan/adopt-serverless
Browse files Browse the repository at this point in the history
start to adopt serverless
  • Loading branch information
noppoMan authored Dec 27, 2018
2 parents 8e55d08 + 017c82b commit bb7ea20
Show file tree
Hide file tree
Showing 20 changed files with 199 additions and 1,538 deletions.
80 changes: 4 additions & 76 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,94 +1,22 @@
{
"object": {
"pins": [
{
"package": "AWSSDKSwift",
"repositoryURL": "https://github.com/swift-aws/aws-sdk-swift.git",
"state": {
"branch": null,
"revision": "b66a8ad7f949ef80a503069603ad1abd240e7f7d",
"version": "2.0.2"
}
},
{
"package": "AWSSDKSwiftCore",
"repositoryURL": "https://github.com/swift-aws/aws-sdk-swift-core.git",
"state": {
"branch": null,
"revision": "2cf186bb18742cb2869e2f08726372b5ac783f46",
"version": "2.0.0-rc.2"
}
},
{
"package": "HypertextApplicationLanguage",
"repositoryURL": "https://github.com/Yasumoto/HypertextApplicationLanguage.git",
"state": {
"branch": null,
"revision": "2302002502fe573494577cc6e8df686e385519f8",
"version": "1.1.0"
}
},
{
"package": "INIParser",
"repositoryURL": "https://github.com/PerfectlySoft/Perfect-INIParser.git",
"state": {
"branch": null,
"revision": "0952aac9ca54324ff25191569fd9c48eec424772",
"version": "3.0.2"
}
},
{
"package": "swift-nio",
"repositoryURL": "https://github.com/apple/swift-nio.git",
"state": {
"branch": null,
"revision": "a20e129c22ad00a51c902dca54a5456f90664780",
"version": "1.12.0"
}
},
{
"package": "swift-nio-ssl",
"repositoryURL": "https://github.com/apple/swift-nio-ssl.git",
"state": {
"branch": null,
"revision": "db16c3a90b101bb53b26a58867a344ad428072e0",
"version": "1.3.2"
}
},
{
"package": "swift-nio-ssl-support",
"repositoryURL": "https://github.com/apple/swift-nio-ssl-support.git",
"state": {
"branch": null,
"revision": "c02eec4e0e6d351cd092938cf44195a8e669f555",
"version": "1.0.0"
}
},
{
"package": "swift-nio-zlib-support",
"repositoryURL": "https://github.com/apple/swift-nio-zlib-support.git",
"state": {
"branch": null,
"revision": "37760e9a52030bb9011972c5213c3350fa9d41fd",
"version": "1.0.0"
}
},
{
"package": "SwiftCLI",
"repositoryURL": "https://github.com/jakeheis/SwiftCLI.git",
"state": {
"branch": null,
"revision": "fb076cba39c679da4e27813518d8860d8815a25b",
"version": "5.2.1"
"revision": "5318c37d3cacc8780f50b87a8840a6774320ebdf",
"version": "5.2.2"
}
},
{
"package": "SwiftyJSON",
"repositoryURL": "https://github.com/IBM-Swift/SwiftyJSON.git",
"state": {
"branch": null,
"revision": "693d2d28fe2f91aedf02c3754baade625fd97c46",
"version": "17.0.2"
"revision": "f2612ea3ac29996ae9601bdcb00cc1c29e26f104",
"version": "17.0.4"
}
},
{
Expand Down
5 changes: 0 additions & 5 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,12 @@ let package = Package(
.executable(name: "hexaville", targets: ["Hexaville"])
],
dependencies: [
.package(url: "https://github.com/swift-aws/aws-sdk-swift.git", .upToNextMajor(from: "2.0.2")),
.package(url: "https://github.com/IBM-Swift/SwiftyJSON.git", .upToNextMajor(from: "17.0.1")),
.package(url: "https://github.com/jakeheis/SwiftCLI.git", .upToNextMajor(from: "5.0.0")),
.package(url: "https://github.com/jpsim/Yams.git", .upToNextMajor(from: "1.0.1"))
],
targets: [
.target(name: "HexavilleCore", dependencies: [
"S3",
"Lambda",
"IAM",
"APIGateway",
"SwiftyJSON",
"SwiftCLI",
"Yams"
Expand Down
163 changes: 44 additions & 119 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ Build applications comprised of microservices that run in response to events, au
It's the greatest motivation to help many Swift and mobile application developers with rapid server side development and low cost operation.

### Supported Cloud Servises
* AWS Lambda(Node.js 8.1 Runtime) + APIGateway
* [x] AWS Lambda(Node.js 8.1 Runtime) + APIGateway
* [ ] Google Cloud Function

### Swift Build Environments
### Pre-Required

Ubuntu 14.04 in Docker
* [Docker](https://www.docker.com/): using for builiding swift application
* [serverless](https://serverless.com/): using for deployment

### Deployment Engine

* 0.x: fullscratch deployment with (aws-sdk-swift)[https://github.com/swift-aws/aws-sdk-swift]
* 1.x or later: [serverless framework](https://serverless.com/)

## Plugins
* [HexavilleAuth](https://github.com/Hexaville): A pluggable framework for providing various authentication methods(OAuth, simple password based etc.)
Expand All @@ -30,12 +37,12 @@ Ubuntu 14.04 in Docker
* Data persistence with DynamoDB
* Dynamic HTML Rendering

## Quick Start
# Quick Start

### Install Docker for mac
## Install Docker for mac
Install Docker for mac from [here](https://docs.docker.com/docker-for-mac/install/), If you haven't installed yet.

### Install Hexaville from Script(Highly recommended)
## Install Hexaville from Script(Highly recommended)

```
curl -L https://rawgit.com/noppoMan/Hexaville/master/install.sh | bash
Expand All @@ -53,23 +60,23 @@ source ~/.bashrc
hexaville
```

### Install Hexaville from Source
## Install Hexaville from Source
```sh
git clone https://github.com/noppoMan/Hexaville.git
cd Hexaville
swift build
```
and then, should link Hexaville executable path to /usr/local/bin or something like that.

### Create a Project
## Create a Project

`Usage: hexaville generate <projectName>`

```sh
hexaville generate Hello --dest /path/to/your/app
```

#### swift-tools-version
### swift-tools-version
You can specify swift-tools-version for the new project with `--swift-tools-version` option.
Current default tool version is `4.0`

Expand All @@ -87,7 +94,7 @@ hexaville generate Hello --swift-tools-version 3.1
hexaville generate Hello --swift-tools-version swift-4.0-DEVELOPMENT-SNAPSHOT-2017-08-04-a
```

### Open your project with Xcode
## Open your project with Xcode

```
swift package generate-xcodeproj
Expand Down Expand Up @@ -118,55 +125,34 @@ app.use(router)
try app.run()
```

### Edit Hexavillefile.yml
## Deploy Your Project

Fill `access_key_id`, `secret_access_key`, `region`.
Hexaville depends on [serverless](https://serverless.com/) at deployment.

```yml
appName: hello
executableTarget: hello
See Install Guide: https://serverless.com/framework/docs/getting-started/

swift:
version: 4.2
buildOptions:
configuration: release
### Packaging hexaville application

provider:
aws:
credential:
accessKeyId: xxxxxxxxxxxxxxx
secretAccessKey: xxxxxxxxxxxxxxx
region: us-east-1
lambda:
s3Bucket: xxxxxxxxx # here is generated automatically
role: xxxxxxxxx # should be a `arn:aws:iam::{accountId}:role/{roleName}`
timeout: 10
memory: 256
```
`hexaville package` command does the following.

#### Required Properties
* build a swift application on the docker(Ubuntu14.04) to create the ELF that is executed on servrless environment.
* zip ELF, swift standard libraries, runtime program and assets

* appName
* executableTarget
if `provider` is `aws`

* provider
* aws.lambda.s3Bucket

### Deploy a Project

`Usage: hexaville deploy`
```sh
cd /path/to/your/app
hexaville package
```

Use this when you have made changes to your Functions, Events or Resources.
This operation take a while.
### Deploying to the cloud

```sh
cd /path/to/your/app
hexaville deploy
serverless deploy --stage staging
```

#### Troubleshooting
Default serverless.yml that is created by `hexaville generate` has only staging and production environment.
If you'd like to add other environments, please edit severless.yml manually.

### Troubleshooting

**1. What is executableTarget in Hexavillefile.yml?**

Expand All @@ -182,37 +168,13 @@ let package = Package(
)
```

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

```yml
lambda:
s3Bucket: unique-bucket-name-here
```

### Show Your Endpoint

show endpoint and routes to run `routes` command at your Project root.

```sh
cd /path/to/your/app
hexaville routes
```

Output is like following.
```
Endpoint: https://xxxxxx.execute-api.ap-northeast-1.amazonaws.com/staging
Routes:
ANY /
ANY /{proxy+}
```
### Access to your resources
## Access to your api resources
```
curl https://xxxxxx.execute-api.ap-northeast-1.amazonaws.com/staging/
```

or access the endpoint from Browser.

## Binary Media Types

Currenty Hexaville supports following binary media types
Expand All @@ -222,7 +184,7 @@ Currenty Hexaville supports following binary media types
* application/x-protobuf
* application/x-google-protobuf

### Here is an example for getting image/jpeg
### How to get binary content?

Threr are two rules to respond to the binary content in the routing handler.
* RowBinaryData should be encoded as Base64
Expand Down Expand Up @@ -268,50 +230,11 @@ You can debug your application with the HexavilleFramework's builtin web server

## Environment Variables

You can pass environment variables to the lambda function with using `.env`.
The `.env` file should be put at your root directory of the HexavilleFramework Application.

**The contents in .env is...**
```
SWIFT_ENV=production
FACEBOOK_APP_ID=xxxxxxx
FACEBOOK_APP_SECRET=xxxxxxx
```

## Extending Basic Settings
See: https://serverless.com/framework/docs/providers/aws/guide/variables/

You can extend followings settings at `lambda` property in `Hexavillefile.yml`
## VPC and Security Groups

* `Timeout`: Default is 10. Timeout limit is described at `Integration Timeout` section in [API Gateway's developer guide](http://docs.aws.amazon.com/apigateway/latest/developerguide/limits.html#api-gateway-limits).
* `Memory`: Default is 128(MB). Memory allocation range is described at `Memory allocation range` section in [Lambda's developer guide](http://docs.aws.amazon.com/lambda/latest/dg/limits.html).

**e.g.**
```yaml
provider:
aws:
lambda:
timeout: 20
memory: 1024
```
## VPC
You can add VPC configuration to the lambda function in Hexavillefile.yml by adding a vpc object property in the lambda configuration section. This object should contain the securityGroupIds and subnetIds array properties needed to construct VPC for this function.
Here's an example.
```yaml
provider:
aws:
lambda:
vpc:
subnetIds:
- subnet-1234
- subnet-56789
securityGroupIds:
- sg-1234
- sg-56789
```
See: https://serverless.com/framework/docs/providers/aws/guide/functions#vpc-configuration

## Swift Versioning and Build Configuration

Expand Down Expand Up @@ -366,7 +289,9 @@ See the detail to see [README](https://github.com/Hexaville/hexaville-tcp-proxy-

## Cold Start

Not implemented yet.
There are several third parties's libraries to againt cold start on github.

The major one is [serverless-plugin-warmup](https://github.com/FidelLimited/serverless-plugin-warmup)

## How to update Hexaville CLI Version?

Expand Down
Loading

0 comments on commit bb7ea20

Please sign in to comment.