Skip to content

Commit

Permalink
chore(manifest refactor) (#128)
Browse files Browse the repository at this point in the history
* basic orchestration in place for appengine

* end to end orchestration, with support for mysql

* minor adjustments

* CLI refactor (manifest vs spec) mostly complete

* Rolling in manifest/spec/state changes, CLI works, WebUI in progress.

* End to end web ui and cli UI with new manifest and state working.

* Continued to iron out issues with appEngine installer.

* Implemented support for the 'tag' property on provisioners, for upgrades, etc.

* Skipping welcome screen. Support release tag, imagePullPolicy.

* Updated branch with develop
  • Loading branch information
Rob Chartier committed Dec 9, 2020
1 parent 218976c commit 55a8c6e
Show file tree
Hide file tree
Showing 75 changed files with 1,113 additions and 507 deletions.
6 changes: 4 additions & 2 deletions packages/adminer/c6o.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ keywords:
- SimpleDB
- Elasticsearch
- MongoDB
- robc

repo: https://github.com/vrana/adminer/
license: https://www.apache.org/licenses/LICENSE-2.0.html
Expand All @@ -43,7 +44,7 @@ editions:
provisioner:
package: '@provisioner/appengine'
name: adminer
image: 'adminer:latest'
image: adminer
port: 8080
automated: true
tag-prefix: appengine
Expand All @@ -63,7 +64,8 @@ editions:
provisioner:
package: '@provisioner/appengine'
name: adminer
image: 'adminer:latest'
tag: latest
image: adminer
port:
- port: 8080
name: http
Expand Down
3 changes: 2 additions & 1 deletion packages/akaunting/c6o.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ editions:
package: '@provisioner/appengine'
automated: true
tag-prefix: appengine
tag: 1.3.9
name: akaunting
image: 'sameersbn/akaunting:1.3.9'
image: sameersbn/akaunting
port: 80

volume:
Expand Down
3 changes: 2 additions & 1 deletion packages/alertmanager/c6o.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ editions:
tag-prefix: appengine
package: '@provisioner/appengine'
name: alertmanager
image: 'prom/alertmanager:latest'
tag: latest
image: prom/alertmanager
port: 9093
automated: true
marina:
Expand Down
2 changes: 1 addition & 1 deletion packages/appengine/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@
"parcel-bundler": "^1.12.4",
"tslib": "^1.11.1"
},
"gitHead": "76270c0e55c21dd5e02cd24c03c84567f77af028"
"gitHead": "d24a33960e0efd45fd795d1c34112fe8174fa19c"
}
202 changes: 202 additions & 0 deletions packages/appengine/src/appObject.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
import { LabelsMetadata } from "./parsing"
import * as fs from 'fs'
import createDebug from 'debug'
const debug = createDebug('@appengine:timing')

export class TimingReporter implements TimingReporter {
report(state: AppEngineState) {
debug('TimingReporter:', state)
return true
}
}

export interface TimingReporter {
report(state: AppEngineState)
}

export class AppEngineState {
timing: Array<AppProvisionerTimer>
labels: LabelsMetadata
args: any
payload: any
parsed: boolean
platform: string
timestamp: Date

timerChangedAction

onTimerChanged(action) {
this.timerChangedAction = action
}

startTimer(name: string) {
let existing = this.timing.find(e => e.name === name)
if (existing === undefined) {
existing = new AppProvisionerTimer()
existing.name = name
this.timing.push(existing)
}
existing.start = (new Date()).getTime()
if(this.timerChangedAction) this.timerChangedAction({action: 'startTimer', name, state: this})
return existing
}

endTimer(name?: string) {
let existing = this.timing.find(e => e.name === name)
if (existing === undefined) {
existing = new AppProvisionerTimer()
existing.name = name
existing.start = (new Date()).getTime()
this.timing.push(existing)
}
existing.end = (new Date()).getTime()
existing.duration = existing.end - existing.start
if(this.timerChangedAction) this.timerChangedAction({action: 'endTimer', name, state: this})

}

constructor(labels: LabelsMetadata, args?: any, payload?: any) {
this.timing = new Array<AppProvisionerTimer>()
this.labels = labels
this.parsed = false
this.timestamp = new Date()
this.platform = 'Web'

if (this.labels.instanceId === undefined) {
const helper = new Helper()
this.labels.instanceId = helper.makeRandom(5)
}
if (args === undefined)
this.args = {}
else
this.args = args

if (payload === undefined)
this.payload = {}
else
this.payload = payload
}
}
export class AppProvisionerTimer {
name: string
start: number
end: number
duration: number
}

export interface AppManifest {
readonly document: any
readonly edition: string
readonly description: string
readonly displayName: string
readonly iconUrl: string
readonly appId: string
readonly namespace: string
readonly provisioner: any
readonly routes: string
readonly name: string
readonly spec: string
hasCustomConfigFields(): boolean
hasCustomSecretFields(): boolean
customConfigFields()
customSecretFields()
}


export class AppObject implements AppManifest {

constructor(public document) { }

private fieldTypes = ['text', 'password', 'checkbox', 'timezone', 'combobox']

hasCustomConfigFields(): boolean {
return this.customConfigFields().length > 0
}
hasCustomSecretFields(): boolean {
return this.customSecretFields().length > 0
}
customConfigFields() {
return this.provisioner.configs.filter(e=> this.fieldTypes.includes(e.fieldType?.toLowerCase()))
}
customSecretFields() {
return this.provisioner.secrets.filter(e=> this.fieldTypes.includes(e.fieldType?.toLowerCase()))
}


getAppEdition() {
return this.document.metadata.labels?.['system.codezero.io/edition'] || 'latest'
}

getAppName() {
return this.document.metadata.name
}

getAppNamespace() {
return this.document.metadata.namespace
}


//Required for appEngine provisioner
get edition() {
return this.getAppEdition()
}
get description() {
return this.document.metadata.annotations?.['system.codezero.io/description'] || this.appId
}
get displayName() {
return this.document.metadata.annotations?.['system.codezero.io/display'] || this.appId
}
get iconUrl() {
return this.document.metadata.annotations?.['system.codezero.io/iconUrl']
}

//Provisioner appId itself and NOT the database identifier
get appId() {
return this.document.metadata.name
}

get namespace() {
return this.getAppNamespace()
}

get spec() {
return this.document.spec
}

get provisioner() {
return this.document.spec.provisioner
}

get routes() {
return this.document.spec.routes
}

get name() {
return this.getAppName()
}

}

export class Helper {

makeRandom(len) {
let text = ''
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'

for (let i = 0; i < len; i++)
text += possible.charAt(Math.floor(Math.random() * possible.length))

return text
}

emitFile = true
PrettyPrintJsonFile(json: any, file = 'debug.json') {
if (!this.emitFile) return
if (!file) file = 'debug.json'
file = `${__dirname}/${file}`
if(!file.endsWith('.json')) file = `${file}.json`
fs.writeFileSync(file, JSON.stringify(json, null, 2))
debug(file, json)
return file
}
}
1 change: 0 additions & 1 deletion packages/appengine/src/applying/appliers/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
export * from './string'
export * from './object'
Loading

0 comments on commit 55a8c6e

Please sign in to comment.