now handles docker registries the right way

This commit is contained in:
2017-08-28 02:24:06 +02:00
parent 3b3a303c55
commit dca4010f97
15 changed files with 59 additions and 209 deletions

View File

@@ -11,10 +11,10 @@ export let handleCli = async (argvArg) => {
let action: string = argvArg._[1]
switch (action) {
default:
plugins.beautylog.error(`>>npmci node ...<< action >>${action}<< not supported`)
plugins.beautylog.error(`>>npmci cloudflare ...<< action >>${action}<< not supported`)
}
} else {
plugins.beautylog.log(`>>npmci node ...<< cli arguments invalid... Please read the documentation.`)
plugins.beautylog.log(`>>npmci cloudflare ...<< cli arguments invalid... Please read the documentation.`)
}
}

View File

@@ -1,6 +1,5 @@
import * as plugins from './mod.plugins'
import * as paths from '../npmci.paths'
import * as NpmciEnv from '../npmci.env'
import { bash } from '../npmci.bash'
import * as helpers from './mod.helpers'
@@ -32,8 +31,8 @@ export let handleCli = async (argvArg) => {
case 'build':
await build()
break
case 'prepare':
await prepare()
case 'login':
await login()
break
case 'test':
await test()
@@ -45,10 +44,10 @@ export let handleCli = async (argvArg) => {
await pull(argvArg)
break
default:
plugins.beautylog.error(`>>npmci node ...<< action >>${action}<< not supported`)
plugins.beautylog.error(`>>npmci docker ...<< action >>${action}<< not supported`)
}
} else {
plugins.beautylog.log(`>>npmci node ...<< cli arguments invalid... Please read the documentation.`)
plugins.beautylog.log(`>>npmci docker ...<< cli arguments invalid... Please read the documentation.`)
}
}
@@ -56,6 +55,7 @@ export let handleCli = async (argvArg) => {
* builds a cwd of Dockerfiles by triggering a promisechain
*/
export let build = async () => {
await prepare()
plugins.beautylog.log('now building Dockerfiles...')
await helpers.readDockerfiles()
.then(helpers.sortDockerfiles)
@@ -63,12 +63,18 @@ export let build = async () => {
.then(helpers.buildDockerfiles)
}
/**
* login to the DockerRegistries
*/
export let login = async () => {
await prepare()
await npmciRegistryStorage.loginAll()
}
/**
* logs in docker
*/
export let prepare = async () => {
NpmciEnv.setDockerRegistry('docker.io') // TODO: checkup why we set this here
// Always login to GitLab Registry
if (!process.env.CI_BUILD_TOKEN || process.env.CI_BUILD_TOKEN === '') {
plugins.beautylog.error('No registry token specified by gitlab!')
@@ -85,12 +91,12 @@ export let prepare = async () => {
npmciRegistryStorage.addRegistry(
DockerRegistry.fromEnvString(envString)
)
await npmciRegistryStorage.loginAll()
})
return
}
export let push = async (argvArg) => {
await prepare()
let registryUrlArg = argvArg._[ 2 ]
let suffix = null
if (argvArg._.length >= 4) {
@@ -100,12 +106,17 @@ export let push = async (argvArg) => {
.then(helpers.sortDockerfiles)
.then(helpers.mapDockerfiles)
let localDockerRegistry = npmciRegistryStorage.getRegistryByUrl(registryUrlArg)
if (!localDockerRegistry) {
plugins.beautylog.error(`Cannot push to registry ${registryUrlArg}, because it was not found in the authenticated registry list.`)
process.exit(1)
}
for (let dockerfile of dockerfileArray) {
dockerfile.push(localDockerRegistry, suffix)
}
}
export let pull = async (argvArg) => {
await prepare()
let registryUrlArg = argvArg._[ 2 ]
let suffix = null
if (argvArg._.length >= 4) {
@@ -121,6 +132,7 @@ export let pull = async (argvArg) => {
}
export let test = async () => {
await prepare()
return await helpers.readDockerfiles()
.then(helpers.testDockerfiles)
}

View File

@@ -42,7 +42,6 @@ export class Dockerfile {
plugins.beautylog.info('now building Dockerfile for ' + this.cleanTag)
let buildCommand = `docker build -t ${this.buildTag} -f ${this.filePath} .`
await bash(buildCommand)
NpmciEnv.dockerFilesBuilt.push(this)
return
}

View File

@@ -25,10 +25,10 @@ export let handleCli = async (argvArg) => {
await test()
break
default:
plugins.beautylog.error(`>>npmci node ...<< action >>${action}<< not supported`)
plugins.beautylog.error(`>>npmci npm ...<< action >>${action}<< not supported`)
}
} else {
plugins.beautylog.log(`>>npmci node ...<< cli arguments invalid... Please read the documentation.`)
plugins.beautylog.log(`>>npmci npm ...<< cli arguments invalid... Please read the documentation.`)
}
}

View File

@@ -15,7 +15,6 @@ smartcli.addCommand('clean')
.then(async (argv) => {
let modClean = await npmciMods.modClean.load()
await modClean.clean()
await NpmciEnv.configStore()
}).catch(err => {
console.log(err)
process.exit(1)
@@ -26,7 +25,6 @@ smartcli.addCommand('cloudflare')
.then(async (argvArg) => {
let modPurge = await npmciMods.modCloudflare.load()
await modPurge.handleCli(argvArg)
await NpmciEnv.configStore()
}).catch(err => {
console.log(err)
})
@@ -36,7 +34,6 @@ smartcli.addCommand('command')
.then(async (argv) => {
let modCommand = await npmciMods.modCommand.load()
await modCommand.command()
await NpmciEnv.configStore()
}).catch(err => {
console.log(err)
process.exit(1)
@@ -47,7 +44,6 @@ smartcli.addCommand('docker')
.then(async argvArg => {
let modDocker = await npmciMods.modDocker.load()
await modDocker.handleCli(argvArg)
NpmciEnv.configStore()
}).catch(err => {
console.log(err)
process.exit(1)
@@ -58,7 +54,6 @@ smartcli.addCommand('node')
.then(async (argvArg) => {
let modNode = await npmciMods.modNode.load()
await modNode.handleCli(argvArg)
await NpmciEnv.configStore()
}).catch(err => {
console.log(err)
})
@@ -68,7 +63,6 @@ smartcli.addCommand('npm')
.then(async (argvArg) => {
let modNpm = await npmciMods.modNpm.load()
await modNpm.handleCli(argvArg)
await NpmciEnv.configStore()
}).catch(err => {
console.log(err)
})
@@ -78,7 +72,6 @@ smartcli.addCommand('ssh')
.then(async (argvArg) => {
let modSsh = await npmciMods.modSsh.load()
await modSsh.handleCli(argvArg)
await NpmciEnv.configStore()
}).catch(err => {
console.log(err)
process.exit(1)
@@ -89,7 +82,6 @@ smartcli.addCommand('trigger')
.then(async (argv) => {
let modTrigger = await npmciMods.modTrigger.load()
await modTrigger.trigger()
await NpmciEnv.configStore()
}).catch(err => {
console.log(err)
process.exit(1)

View File

@@ -10,65 +10,3 @@ export let repo: GitRepo
if (process.env.CI_REPOSITORY_URL) {
repo = new GitRepo(process.env.CI_REPOSITORY_URL)
}
/**
* the build stage
*/
export let buildStage: string = process.env.CI_BUILD_STAGE
// handling config between commands
export let dockerRegistry: string // will be set by npmci.prepare
export let setDockerRegistry = (dockerRegistryArg: string) => {
dockerRegistry = dockerRegistryArg
}
export let dockerFilesBuilt: Dockerfile[] = []
export let dockerFiles: Dockerfile[] = []
/**
* the config
*/
export let config = {
dockerRegistry: undefined, // this will be set later on store
dockerFilesBuilt: dockerFilesBuilt,
dockerFiles: dockerFiles,
project: undefined
}
/**
* the configuration store
*/
export let configStore = async () => {
config.dockerRegistry = dockerRegistry
plugins.smartfile.memory.toFsSync(
JSON.stringify(config),
paths.NpmciPackageConfig
)
}
/**
* load the config in case a previous run has stored it
*/
let configLoad = () => {
// internal config to transfer information in between npmci shell calls
try {
plugins.lodash.assign(config, plugins.smartfile.fs.toObjectSync(paths.NpmciPackageConfig, 'json'))
} catch (err) {
configStore()
plugins.beautylog.log('config initialized!')
}
// project config
try {
if (!config.project) {
config.project = plugins.smartfile.fs.toObjectSync(paths.NpmciProjectDir, 'npmci.json')
plugins.beautylog.ok('project config found!')
}
} catch (err) {
config.project = {}
plugins.beautylog.log('no project config found, so proceeding with default behaviour!')
}
config.dockerRegistry ? dockerRegistry = config.dockerRegistry : void (0)
config.dockerFilesBuilt ? dockerFilesBuilt = config.dockerFilesBuilt : void (0)
}
configLoad()