Skip to content
This repository has been archived by the owner on Feb 28, 2020. It is now read-only.

Commit

Permalink
feat: intial kubernetes support
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Compton committed Aug 10, 2017
1 parent 64a5919 commit b6a259c
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 14 deletions.
21 changes: 11 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,29 @@
"generator"
],
"dependencies": {
"@arf/generator-cloud-enablement": "0.0.25",
"bluebird": "^3.5.0",
"chalk": "^1.1.0",
"debug": "^2.2.0",
"js-yaml": "^3.4.2",
"yeoman-generator": "^1.1.1",
"handlebars": "^4.0.5",
"bluebird": "^3.5.0",
"js-yaml": "^3.9.1",
"request": "^2.81.0",
"swagger-parser": "^3.4.1",
"swagger-schema-official": "^2.0.0-",
"swaggerize-routes": "^1.0.0",
"rimraf": "^2.5.2",
"unzip2": "^0.2.5"
"swagger-parser": "^3.4.2",
"swagger-schema-official": "^2.0.0-d79c205",
"swaggerize-routes": "^1.0.0",
"unzip2": "^0.2.5",
"yeoman-generator": "^1.1.1"
},
"devDependencies": {
"codecov": "^2.1.0",
"codecov": "^2.3.0",
"istanbul": "^0.4.5",
"mem-fs": "^1.1.3",
"mem-fs-editor": "^3.0.2",
"mocha": "^3.2.0",
"mocha": "^3.5.0",
"nock": "^9.0.13",
"nyc": "^10.1.2",
"standard": "^10.0.2",
"standard": "^10.0.3",
"standard-version": "^4.2.0",
"yeoman-assert": "^3.0.0",
"yeoman-test": "^1.6.0"
Expand Down
14 changes: 13 additions & 1 deletion refresh/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,9 @@ module.exports = Generator.extend({
if (typeof (this.spec.bluemix.instances) === 'number') {
this.bluemix.instances = this.spec.bluemix.instances
}
if (typeof (this.spec.bluemix.namespace) === 'string') {
this.bluemix.namespace = this.spec.bluemix.namespace
}
}

// Clean app name (for containers and other uses)
Expand Down Expand Up @@ -1257,7 +1260,8 @@ module.exports = Generator.extend({
services: this.services,
capabilities: this.capabilities,
hostSwagger: this.hostSwagger,
bluemix: this.bluemix }
bluemix: this.bluemix
}
)
})

Expand Down Expand Up @@ -1286,6 +1290,14 @@ module.exports = Generator.extend({
})
},

writeKubernetesFiles: function () {
if (!this.docker) return

var server = (this.bluemix.domain && this.bluemix.namespace) ? {domain: this.bluemix.domain, namespace: this.bluemix.namespace } : undefined;
this.composeWith(require.resolve('@arf/generator-cloud-enablement/generators/kubernetes'), {force: this.force, bluemix: { backendPlatform: "SWIFT", name: this.cleanAppName, server: server }} )

},

writePackageSwift: function () {
// Check if there is a Package.swift, create one if there isn't
this._ifNotExistsInProject('Package.swift', (filepath) => {
Expand Down
1 change: 1 addition & 0 deletions refresh/templates/docker/cli-config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ container-path-run : "/swift-project"
container-path-tools : "/swift-project"
container-port-map : "8080:8080"
container-port-map-debug : "2048:1024,2049:1025"
chart-path : "helm/<%- cleanAppName.toLowerCase() %>"
68 changes: 65 additions & 3 deletions test/unit/refresh.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ var expectedBluemixFiles = ['manifest.yml',
'.bluemix/toolchain.yml',
'.bluemix/deploy.json']

var expectedDockerFiles = ['cli-config.yml',
'.dockerignore',
'Dockerfile',
'Dockerfile-tools']

var expectedKubernetesFiles = [`helm/${appName}/Chart.yaml`,
`helm/${appName}/values.yaml`,
`helm/${appName}/templates/deployment.yaml`,
`helm/${appName}/templates/service.yaml`]

describe('swiftserver:refresh', function () {
before('set sdkgen status check delay to 1ms', function () {
// alter delay between status checks to speed up unit tests
Expand Down Expand Up @@ -939,6 +949,14 @@ describe('swiftserver:refresh', function () {
assert.noFile(expectedBluemixFiles)
})

it('does not generate the docker files', function () {
assert.noFile(expectedDockerFiles)
})

it('does not generate the kubernetes files', function () {
assert.noFile(expectedKubernetesFiles)
})

it('does not generate any capabilities', function () {
assert.noFileContent(`Sources/${applicationModule}/Application.swift`, 'import SwiftMetrics')
assert.noFileContent(`Sources/${applicationModule}/Application.swift`, 'import SwiftMetricsDash')
Expand Down Expand Up @@ -1076,6 +1094,7 @@ describe('swiftserver:refresh', function () {
logger: 'helium',
port: 4567
},
docker: true,
'models': [
{
'name': modelName,
Expand Down Expand Up @@ -1129,6 +1148,14 @@ describe('swiftserver:refresh', function () {
assert.file(expectedBluemixFiles)
})

it('generates the docker files', function () {
assert.file(expectedDockerFiles)
})

it('generates the expected kubernetes files', function () {
assert.file(expectedKubernetesFiles)
})

it('defines OPENAPI_SPEC environment variable', function () {
assert.fileContent('manifest.yml', 'OPENAPI_SPEC: "/swagger/api"')
})
Expand Down Expand Up @@ -1452,12 +1479,14 @@ describe('swiftserver:refresh', function () {
bluemix: {
'name': 'test',
'host': 'myhost',
'domain': 'mydomain.net'
'domain': 'mydomain.net',
'namespace': 'mynamespace'
},
config: {
logger: 'helium',
port: 4567
}
},
docker: true
}
runContext = helpers.run(path.join(__dirname, '../../refresh'))
.withOptions({
Expand Down Expand Up @@ -1513,11 +1542,27 @@ describe('swiftserver:refresh', function () {
it('produces the correct disk quota in the manifest', function () {
assert.fileContent('manifest.yml', 'disk_quota: 1024M')
})

it('adds the proper chart-path in cli-config.yml', function () {
assert.fileContent('cli-config.yml', 'chart-path : "helm/test"')
})

it('populates the correct name in Chart.yaml', function () {
assert.fileContent('helm/test/Chart.yaml', 'name: test')
})

it('populates the correct values in values.yaml', function () {
assert.fileContent('helm/test/values.yaml', 'name: test')
assert.fileContent('helm/test/values.yaml', 'repository: registry.mydomain.net/mynamespace/')
})

})

describe('Generate skeleton web application for bluemix with incorrect custom options', function () {
var runContext

//CHRISTIAN ToDo: Add testcases for cloud-enablement with these incorrect options

before(function () {
// Set up the spec file which should create all the necessary files for a server
var spec = {
Expand Down Expand Up @@ -1601,6 +1646,14 @@ describe('swiftserver:refresh', function () {
it('does not generate the bluemix files', function () {
assert.noFile(expectedBluemixFiles)
})

it('does not generate the docker files', function () {
assert.noFile(expectedDockerFiles)
})

it('does not generate the kubernetes files', function () {
assert.noFile(expectedKubernetesFiles)
})
})

describe('Generate a web application with capabilities', function () {
Expand Down Expand Up @@ -2262,7 +2315,8 @@ describe('swiftserver:refresh', function () {
config: {
logger: 'helium',
port: 4567
}
},
docker: true
}
runContext = helpers.run(path.join(__dirname, '../../refresh'))
.withOptions({
Expand Down Expand Up @@ -2296,6 +2350,14 @@ describe('swiftserver:refresh', function () {
assert.file(expectedBluemixFiles)
})

it('generates the docker files', function () {
assert.file(expectedDockerFiles)
})

it('generates the kubernetes files with expected values', function () {
assert.file(expectedKubernetesFiles)
})

it('defines example endpoints', function () {
var productsRoutesFile = `Sources/${applicationModule}/Routes/ProductsRoutes.swift`
assert.file(productsRoutesFile)
Expand Down

0 comments on commit b6a259c

Please sign in to comment.