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

feat: kubernetes & helm support #283

Merged
merged 12 commits into from
Aug 28, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": {
"generator-ibm-cloud-enablement": "0.0.54",
"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
13 changes: 12 additions & 1 deletion refresh/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,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 @@ -1260,7 +1263,8 @@ module.exports = Generator.extend({
services: this.services,
capabilities: this.capabilities,
hostSwagger: this.hostSwagger,
bluemix: this.bluemix }
bluemix: this.bluemix
}
)
})

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

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

var server = (this.bluemix && this.bluemix.domain && this.bluemix.namespace) ? { domain: this.bluemix.domain, namespace: this.bluemix.namespace } : undefined
this.composeWith(require.resolve('generator-ibm-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 : "chart/<%- cleanAppName.toLowerCase() %>"
18 changes: 18 additions & 0 deletions test/integration/app/prompted_nobuild.js
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,24 @@ describe('Prompt and no build integration tests for app generator', function ()
})
})

describe('Kubernetes files', function () {
it('created helm chart file', function () {
assert.file('chart/notes/Chart.yaml')
})

it('created helm deployment file', function () {
assert.file('chart/notes/templates/deployment.yaml')
})

it('created helm service file', function () {
assert.file('chart/notes/templates/service.yaml')
})

it('created helm values file', function () {
assert.file('chart/notes/values.yaml')
})
})

describe('Bluemix cloud deployment', function () {
it('created CloudFoundry manifest file', function () {
assert.file('manifest.yml')
Expand Down
64 changes: 61 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 = [`chart/${appName}/Chart.yaml`,
`chart/${appName}/values.yaml`,
`chart/${appName}/templates/deployment.yaml`,
`chart/${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 @@ -958,6 +968,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 @@ -1095,6 +1113,7 @@ describe('swiftserver:refresh', function () {
logger: 'helium',
port: 4567
},
docker: true,
'models': [
{
'name': modelName,
Expand Down Expand Up @@ -1148,6 +1167,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 @@ -1471,12 +1498,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 @@ -1532,6 +1561,18 @@ 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 : "chart/test"')
})

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

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

describe('Generate skeleton web application for bluemix with incorrect custom options', function () {
Expand Down Expand Up @@ -1620,6 +1661,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 @@ -2281,7 +2330,8 @@ describe('swiftserver:refresh', function () {
config: {
logger: 'helium',
port: 4567
}
},
docker: true
}
runContext = helpers.run(path.join(__dirname, '../../refresh'))
.withOptions({
Expand Down Expand Up @@ -2315,6 +2365,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