Skip to content

Commit

Permalink
yo swiftserver
Browse files Browse the repository at this point in the history
  • Loading branch information
rmg committed Apr 20, 2017
1 parent 3a762e4 commit 21e837b
Show file tree
Hide file tree
Showing 25 changed files with 372 additions and 0 deletions.
71 changes: 71 additions & 0 deletions swift-blog/.bluemix/deploy.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Sample Deploy Stage",
"longDescription": "The Delivery Pipeline automates continuous deployment.",
"type": "object",
"properties": {
"dev-region": {
"description": "The bluemix region",
"type": "string"
},
"dev-organization": {
"description": "The bluemix org",
"type": "string"
},
"dev-space": {
"description": "The bluemix space",
"type": "string"
},
"app-name": {
"description": "app name",
"type": "string"
}
},
"required": ["dev-region",
"dev-organization",
"dev-space",
"app-name"],
"form": [{
"type": "validator",
"url": "/devops/setup/bm-helper/helper.html"
},
{
"type": "text",
"readonly": false,
"title": "App Name",
"key": "app-name"
},
{
"type": "table",
"columnCount": 3,
"widths": ["28%",
"28%",
"28%"],
"items": [{
"type": "label",
"title": "Region"
},
{
"type": "label",
"title": "Organization"
},
{
"type": "label",
"title": "Space"
},
{
"type": "select",
"key": "dev-region"
},
{
"type": "select",
"key": "dev-organization"
},
{
"type": "select",
"key": "dev-space",
"readonly": false
}]
}]
}

29 changes: 29 additions & 0 deletions swift-blog/.bluemix/pipeline.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
stages:
- name: Build Stage
inputs:
- type: git
branch: master
service: ${REPO}
jobs:
- name: Build
type: builder
artifact_dir: ''
- name: Deploy Stage
inputs:
- type: job
stage: Build Stage
job: Build
triggers:
- type: stage
jobs:
- name: Deploy
type: deployer
target:
region_id: ${CF_REGION_ID}
organization: ${CF_ORGANIZATION}
space: ${CF_SPACE}
application: ${CF_APP}
script: |-
#!/bin/bash
cf push "${CF_APP}"
# cf logs "${CF_APP}" --recent
47 changes: 47 additions & 0 deletions swift-blog/.bluemix/toolchain.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Continuous Delivery Toolchain
description: "This toolchain includes tools to develop and deploy your app. Depending on your app, when you create the toolchain, the GitHub repository will either be empty or will contain source code from your app.\n\nThis toolchain uses tools that are part of the Continuous Delivery service. If an instance of that service isn't already in your organization, when you click **Create**, it is automatically added at no cost to you. For more information and terms, see the [Bluemix catalog](/catalog/services/continuous-delivery/).\n\nTo get started, click **Create**."
version: 0.2
required:
- deploy
- repo

toolchain:
name: swift-blog

# Github repos
repo:
service_id: githubpublic
parameters:
repo_url: "{{repository}}"
type: link
has_issues: true

# Pipelines
build:
service_id: pipeline
parameters:
name: "{{name}}"
ui-pipeline: true
configuration:
content: $file(pipeline.yml)
env:
REPO: "repo"
CF_APP: "{{deploy.parameters.app-name}}"
CF_SPACE: "{{deploy.parameters.dev-space}}"
CF_ORGANIZATION: "{{deploy.parameters.dev-organization}}"
CF_REGION_ID: "{{deploy.parameters.dev-region}}"
execute: true
services: ["repo"]
hidden: ["form"]

#Web IDE
webide:
service_id: orion

#Deployment
deploy:
schema:
$ref: deploy.json
service-category: pipeline
parameters:
app-name: swift-blog
2 changes: 2 additions & 0 deletions swift-blog/.cfignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.build/*
Packages/*
2 changes: 2 additions & 0 deletions swift-blog/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Dockerfile
Dockerfile-tools
6 changes: 6 additions & 0 deletions swift-blog/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.DS_Store
/.build
/Packages
/*.xcodeproj
/config.json
/spec.json
1 change: 1 addition & 0 deletions swift-blog/.swift-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.0.2
Empty file.
5 changes: 5 additions & 0 deletions swift-blog/.yo-rc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"generator-swiftserver": {
"version": "2.0.2"
}
}
15 changes: 15 additions & 0 deletions swift-blog/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM ibmcom/swift-ubuntu-runtime:3.0.2
MAINTAINER IBM Swift Engineering at IBM Cloud
LABEL Description="Template Dockerfile that extends the ibmcom/swift-ubuntu-runtime image."

# We can replace this port with what the user wants
# EXPOSE {{PORT}}
EXPOSE 8080

# Linux OS utils
RUN apt-get update

ADD https://raw.githubusercontent.com/IBM-Swift/swift-ubuntu-docker/master/utils/run-utils.sh /root/utils/run-utils.sh
RUN chmod +x /root/utils/run-utils.sh
ADD https://raw.githubusercontent.com/IBM-Swift/swift-ubuntu-docker/master/utils/common-utils.sh /root/utils/common-utils.sh
RUN chmod +x /root/utils/common-utils.sh
15 changes: 15 additions & 0 deletions swift-blog/Dockerfile-tools
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
FROM ibmcom/swift-ubuntu:3.0.2
MAINTAINER IBM Swift Engineering at IBM Cloud
LABEL Description="Template Dockerfile that extends the ibmcom/swift-ubuntu image."

# We can replace this port with what the user wants
# EXPOSE {{PORT}}
EXPOSE 8080 1024

# Linux OS utils
RUN apt-get update

ADD https://raw.githubusercontent.com/IBM-Swift/swift-ubuntu-docker/master/utils/tools-utils.sh /root/utils/tools-utils.sh
RUN chmod +x /root/utils/tools-utils.sh
ADD https://raw.githubusercontent.com/IBM-Swift/swift-ubuntu-docker/master/utils/common-utils.sh /root/utils/common-utils.sh
RUN chmod +x /root/utils/common-utils.sh
23 changes: 23 additions & 0 deletions swift-blog/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Copyright (c) 2017 IBM Corp.

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE.

17 changes: 17 additions & 0 deletions swift-blog/Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import PackageDescription

let package = Package(
name: "swift-blog",
targets: [
Target(name: "Application", dependencies: [ .Target(name: "Generated") ]),
Target(name: "swift-blog", dependencies: [ .Target(name: "Application") ])
],
dependencies: [
.Package(url: "https://github.com/IBM-Swift/Kitura.git", majorVersion: 1, minor: 6),
.Package(url: "https://github.com/IBM-Swift/HeliumLogger.git", majorVersion: 1, minor: 6),
.Package(url: "https://github.com/IBM-Swift/CloudConfiguration.git", majorVersion: 1),
.Package(url: "https://github.com/RuntimeTools/SwiftMetrics.git", majorVersion: 1),

],
exclude: ["src"]
)
1 change: 1 addition & 0 deletions swift-blog/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[![Create Toolchain](https://console.ng.bluemix.net/devops/graphics/create_toolchain_button.png)](https://console.ng.bluemix.net/devops/setup/deploy/)
33 changes: 33 additions & 0 deletions swift-blog/Sources/Application/Application.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import Foundation
import Kitura
import LoggerAPI
import Configuration
import Generated
import CloudFoundryConfig
import SwiftMetrics
import SwiftMetricsDash

public let router = Router()
public let manager = ConfigurationManager()
public var port: Int = 8080

public func initialize() throws {

manager.load(file: "config.json", relativeFrom: .project)
.load(.environmentVariables)

port = manager.port

let sm = try SwiftMetrics()
let _ = try SwiftMetricsDash(swiftMetricsInstance : sm, endpoint: router)

router.all("/*", middleware: BodyParser())

try initializeCRUDResources(manager: manager, router: router)
initializeSwaggerRoute(path: ConfigurationManager.BasePath.project.path + "/definitions/swift-blog.yaml")
}

public func run() throws {
Kitura.addHTTPServer(onPort: port, with: router)
Kitura.run()
}
12 changes: 12 additions & 0 deletions swift-blog/Sources/Application/Routes/SwaggerRoute.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import LoggerAPI

func initializeSwaggerRoute(path swaggerPath: String) {
// Host swagger definition
router.get("/swagger/api") { request, response, next in
do {
try response.send(fileName: swaggerPath).end()
} catch {
Log.error("Failed to serve OpenAPI Swagger definition from \(swaggerPath)")
}
}
}
7 changes: 7 additions & 0 deletions swift-blog/Sources/Generated/AdapterError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public enum AdapterError: Error {
case invalidId(String?)
case notFound(String)
case idConflict(String)
case unavailable(String)
case internalError(String)
}
13 changes: 13 additions & 0 deletions swift-blog/Sources/Generated/AdapterFactory.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import Foundation
import Configuration
import CloudFoundryConfig

public class AdapterFactory {
let manager: ConfigurationManager

init(manager: ConfigurationManager) {
self.manager = manager
}


}
5 changes: 5 additions & 0 deletions swift-blog/Sources/Generated/CRUDResources.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Kitura
import Configuration

public func initializeCRUDResources(manager: ConfigurationManager, router: Router) throws {
}
14 changes: 14 additions & 0 deletions swift-blog/Sources/Generated/ModelError.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
public enum ModelError: Error {
case requiredPropertyMissing(name: String)
case extraneousProperty(name: String)
case propertyTypeMismatch(name: String, type: String, value: String, valueType: String)
func defaultMessage() -> String {
switch self {
case let .requiredPropertyMissing(name): return "Required property \(name) not provided"
case let .extraneousProperty(name): return "Property \(name) not found"
case let .propertyTypeMismatch(name, type, value, valueType):
return "Provided value (\(value)) for property '\(name)' has type (\(valueType))" +
" which is not compatible with the property type (\(type))"
}
}
}
15 changes: 15 additions & 0 deletions swift-blog/Sources/swift-blog/main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Kitura
import LoggerAPI
import HeliumLogger
import Application

do {

HeliumLogger.use(LoggerMessageType.info)

try initialize()
try run()

} catch let error {
Log.error(error.localizedDescription)
}
15 changes: 15 additions & 0 deletions swift-blog/cli-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
container-name-run : "swiftblog-swift-run"
container-name-tools : "swiftblog-swift-tools"
image-name-run : "swiftblog-swiftrun"
image-name-tools: "swiftblog-swifttools"
dockerfile-tools: "Dockerfile-tools"
dockerfile-run: "Dockerfile"
build-cmd-debug : "/root/utils/tools-utils.sh build debug"
debug-cmd : "/root/utils/tools-utils.sh debug swift-blog 1024"
build-cmd-run : "/root/utils/tools-utils.sh build release"
run-cmd : "/root/utils/run-utils.sh run swift-blog"
test-cmd : "/root/utils/tools-utils.sh test"
container-path-run : "/root/project"
container-path-tools : "/root/project"
container-port-map : "8080:8080"
container-port-map-debug : "1024:1024"
13 changes: 13 additions & 0 deletions swift-blog/definitions/swift-blog.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
swagger: '2.0'
info:
version: 1.0.0
title: swift-blog
schemes:
- http
basePath: /api
consumes:
- application/json
produces:
- application/json
paths: {}
definitions: {}
11 changes: 11 additions & 0 deletions swift-blog/manifest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
applications:
- name: swiftblog
random-route: true
memory: 128M
instances: 1
disk_quota: 1024M
buildpack: swift_buildpack
command: swift-blog --bind 0.0.0.0:$PORT
env:
OPENAPI_SPEC: "/swagger/api"
timeout: 180
Empty file added swift-blog/models/.keep
Empty file.

0 comments on commit 21e837b

Please sign in to comment.