update
This commit is contained in:
parent
5ede124f56
commit
d9b8eb3bf0
@ -30,7 +30,6 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/lodash": "^4.14.52",
|
"@types/lodash": "^4.14.52",
|
||||||
"@types/node": "^7.0.5",
|
"@types/node": "^7.0.5",
|
||||||
"@types/q": "0.x.x",
|
|
||||||
"@types/request": "0.x.x",
|
"@types/request": "0.x.x",
|
||||||
"@types/shelljs": "^0.7.0",
|
"@types/shelljs": "^0.7.0",
|
||||||
"@types/through2": "^2.0.32",
|
"@types/through2": "^2.0.32",
|
||||||
@ -40,7 +39,6 @@
|
|||||||
"lodash": "^4.17.4",
|
"lodash": "^4.17.4",
|
||||||
"npmextra": "^2.0.3",
|
"npmextra": "^2.0.3",
|
||||||
"projectinfo": "^3.0.1",
|
"projectinfo": "^3.0.1",
|
||||||
"q": "^1.4.1",
|
|
||||||
"request": "^2.79.0",
|
"request": "^2.79.0",
|
||||||
"shelljs": "^0.7.6",
|
"shelljs": "^0.7.6",
|
||||||
"smartcli": "^2.0.1",
|
"smartcli": "^2.0.1",
|
||||||
|
@ -19,7 +19,8 @@ checkNvm()
|
|||||||
* @param commandArg - The command to execute
|
* @param commandArg - The command to execute
|
||||||
* @param retryArg - The retryArg: 0 to any positive number will retry, -1 will always succeed, -2 will return undefined
|
* @param retryArg - The retryArg: 0 to any positive number will retry, -1 will always succeed, -2 will return undefined
|
||||||
*/
|
*/
|
||||||
export let bash = (commandArg: string, retryArg: number = 2, bareArg: boolean = false): string => {
|
export let bash = (commandArg: string, retryArg: number = 2, bareArg: boolean = false): Promise<string> => {
|
||||||
|
let done = plugins.q.defer<string>()
|
||||||
let exitCode: number
|
let exitCode: number
|
||||||
let stdOut: string
|
let stdOut: string
|
||||||
let execResult
|
let execResult
|
||||||
@ -43,6 +44,7 @@ export let bash = (commandArg: string, retryArg: number = 2, bareArg: boolean =
|
|||||||
// determine how bash reacts to error and success
|
// determine how bash reacts to error and success
|
||||||
if (exitCode !== 0 && i === retryArg) { // something went wrong and retries are exhausted
|
if (exitCode !== 0 && i === retryArg) { // something went wrong and retries are exhausted
|
||||||
if (failOnError) {
|
if (failOnError) {
|
||||||
|
plugins.beautylog.error('something went wrong and retries are exhausted')
|
||||||
process.exit(1)
|
process.exit(1)
|
||||||
}
|
}
|
||||||
} else if (exitCode === 0) { // everything went fine, or no error wanted
|
} else if (exitCode === 0) { // everything went fine, or no error wanted
|
||||||
@ -55,19 +57,19 @@ export let bash = (commandArg: string, retryArg: number = 2, bareArg: boolean =
|
|||||||
} else {
|
} else {
|
||||||
plugins.beautylog.log('ShellExec would be: ' + commandArg)
|
plugins.beautylog.log('ShellExec would be: ' + commandArg)
|
||||||
}
|
}
|
||||||
return stdOut
|
return done.promise
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* bashBare allows usage of bash without sourcing any files like nvm
|
* bashBare allows usage of bash without sourcing any files like nvm
|
||||||
*/
|
*/
|
||||||
export let bashBare = (commandArg: string, retryArg: number = 2) => {
|
export let bashBare = (commandArg: string, retryArg: number = 2): Promise<string> => {
|
||||||
return bash(commandArg, retryArg, true)
|
return bash(commandArg, retryArg, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* bashNoError allows executing stuff without throwing an error
|
* bashNoError allows executing stuff without throwing an error
|
||||||
*/
|
*/
|
||||||
export let bashNoError = (commandArg: string): string => {
|
export let bashNoError = (commandArg: string): Promise<string> => {
|
||||||
return bash(commandArg, -1)
|
return bash(commandArg, -1)
|
||||||
}
|
}
|
||||||
|
@ -1,43 +1,38 @@
|
|||||||
import * as plugins from './npmci.plugins'
|
import * as plugins from './npmci.plugins'
|
||||||
import * as paths from './npmci.paths'
|
import * as paths from './npmci.paths'
|
||||||
import * as NpmciEnv from './npmci.env'
|
import * as NpmciEnv from './npmci.env'
|
||||||
import {bashBare} from './npmci.bash'
|
import { bashBare } from './npmci.bash'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* builds a cwd of Dockerfiles by triggering a promisechain
|
* builds a cwd of Dockerfiles by triggering a promisechain
|
||||||
*/
|
*/
|
||||||
export let build = function(){
|
export let build = async () => {
|
||||||
let done = plugins.q.defer()
|
await readDockerfiles()
|
||||||
readDockerfiles()
|
.then(sortDockerfiles)
|
||||||
.then(sortDockerfiles)
|
.then(mapDockerfiles)
|
||||||
.then(mapDockerfiles)
|
.then(buildDockerfiles)
|
||||||
.then(buildDockerfiles)
|
.then(pushDockerfiles)
|
||||||
.then(pushDockerfiles)
|
|
||||||
.then(() => {
|
|
||||||
done.resolve()
|
|
||||||
})
|
|
||||||
return done.promise
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* creates instance of class Dockerfile for all Dockerfiles in cwd
|
* creates instance of class Dockerfile for all Dockerfiles in cwd
|
||||||
* @returns Promise<Dockerfile[]>
|
* @returns Promise<Dockerfile[]>
|
||||||
*/
|
*/
|
||||||
export let readDockerfiles = function(): plugins.q.Promise<Dockerfile[]>{
|
export let readDockerfiles = async (): Promise<Dockerfile[]> => {
|
||||||
let done = plugins.q.defer<Dockerfile[]>()
|
let fileTree = await plugins.smartfile.fs.listFileTree(paths.cwd, './Dockerfile*')
|
||||||
let readDockerfilesArray: Dockerfile[] = []
|
|
||||||
plugins.gulp.src('./Dockerfile*')
|
// create the Dockerfile array
|
||||||
.pipe(plugins.through2.obj(function(file,enc,cb){
|
let readDockerfilesArray: Dockerfile[] = []
|
||||||
let myDockerfile = new Dockerfile({
|
for (let dockerfilePath of fileTree) {
|
||||||
filePath: file.path,
|
let myDockerfile = new Dockerfile({
|
||||||
read: true
|
filePath: dockerfilePath,
|
||||||
})
|
read: true
|
||||||
readDockerfilesArray.push(myDockerfile)
|
})
|
||||||
cb(null,file)
|
readDockerfilesArray.push(myDockerfile)
|
||||||
},function(){
|
}
|
||||||
done.resolve(readDockerfilesArray)
|
|
||||||
}))
|
return readDockerfilesArray
|
||||||
return done.promise
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,249 +40,235 @@ export let readDockerfiles = function(): plugins.q.Promise<Dockerfile[]>{
|
|||||||
* @param sortableArrayArg an array of instances of class Dockerfile
|
* @param sortableArrayArg an array of instances of class Dockerfile
|
||||||
* @returns Promise<Dockerfile[]>
|
* @returns Promise<Dockerfile[]>
|
||||||
*/
|
*/
|
||||||
export let sortDockerfiles = function(sortableArrayArg: Dockerfile[]): plugins.q.Promise<Dockerfile[]>{
|
export let sortDockerfiles = (sortableArrayArg: Dockerfile[]): plugins.q.Promise<Dockerfile[]> => {
|
||||||
let done = plugins.q.defer<Dockerfile[]>()
|
let done = plugins.q.defer<Dockerfile[]>()
|
||||||
let sortedArray: Dockerfile[] = []
|
let sortedArray: Dockerfile[] = []
|
||||||
let cleanTagsOriginal = cleanTagsArrayFunction(sortableArrayArg,sortedArray)
|
let cleanTagsOriginal = cleanTagsArrayFunction(sortableArrayArg, sortedArray)
|
||||||
let sorterFunctionCounter: number = 0
|
let sorterFunctionCounter: number = 0
|
||||||
let sorterFunction = function(){
|
let sorterFunction = function () {
|
||||||
sortableArrayArg.forEach((dockerfileArg) => {
|
sortableArrayArg.forEach((dockerfileArg) => {
|
||||||
let cleanTags = cleanTagsArrayFunction(sortableArrayArg,sortedArray)
|
let cleanTags = cleanTagsArrayFunction(sortableArrayArg, sortedArray)
|
||||||
if (cleanTags.indexOf(dockerfileArg.baseImage) === -1 && sortedArray.indexOf(dockerfileArg) === -1) {
|
if (cleanTags.indexOf(dockerfileArg.baseImage) === -1 && sortedArray.indexOf(dockerfileArg) === -1) {
|
||||||
sortedArray.push(dockerfileArg)
|
sortedArray.push(dockerfileArg)
|
||||||
};
|
};
|
||||||
if (cleanTagsOriginal.indexOf(dockerfileArg.baseImage) !== -1) {
|
if (cleanTagsOriginal.indexOf(dockerfileArg.baseImage) !== -1) {
|
||||||
dockerfileArg.localBaseImageDependent = true
|
dockerfileArg.localBaseImageDependent = true
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
if (sortableArrayArg.length === sortedArray.length) {
|
if (sortableArrayArg.length === sortedArray.length) {
|
||||||
done.resolve(sortedArray)
|
done.resolve(sortedArray)
|
||||||
} else if (sorterFunctionCounter < 10) {
|
} else if (sorterFunctionCounter < 10) {
|
||||||
sorterFunctionCounter++
|
sorterFunctionCounter++
|
||||||
sorterFunction()
|
sorterFunction()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
sorterFunction()
|
sorterFunction()
|
||||||
return done.promise
|
return done.promise
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* maps local Dockerfiles dependencies to the correspoding Dockerfile class instances
|
* maps local Dockerfiles dependencies to the correspoding Dockerfile class instances
|
||||||
*/
|
*/
|
||||||
export let mapDockerfiles = function(sortedArray: Dockerfile[]): plugins.q.Promise<Dockerfile[]>{
|
export let mapDockerfiles = async (sortedArray: Dockerfile[]): plugins.q.Promise<Dockerfile[]> => {
|
||||||
let done = plugins.q.defer<Dockerfile[]>()
|
sortedArray.forEach((dockerfileArg) => {
|
||||||
sortedArray.forEach((dockerfileArg) => {
|
if (dockerfileArg.localBaseImageDependent) {
|
||||||
if (dockerfileArg.localBaseImageDependent) {
|
sortedArray.forEach((dockfile2: Dockerfile) => {
|
||||||
sortedArray.forEach((dockfile2: Dockerfile) => {
|
if (dockfile2.cleanTag === dockerfileArg.baseImage) {
|
||||||
if (dockfile2.cleanTag === dockerfileArg.baseImage) {
|
dockerfileArg.localBaseDockerfile = dockfile2
|
||||||
dockerfileArg.localBaseDockerfile = dockfile2
|
}
|
||||||
}
|
})
|
||||||
})
|
};
|
||||||
};
|
})
|
||||||
})
|
return sortedArray
|
||||||
done.resolve(sortedArray)
|
|
||||||
return done.promise
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* builds the correspoding real docker image for each Dockerfile class instance
|
* builds the correspoding real docker image for each Dockerfile class instance
|
||||||
*/
|
*/
|
||||||
export let buildDockerfiles = (sortedArrayArg: Dockerfile[]) => {
|
export let buildDockerfiles = async (sortedArrayArg: Dockerfile[]) => {
|
||||||
let done = plugins.q.defer()
|
sortedArrayArg.forEach(async function (dockerfileArg) {
|
||||||
sortedArrayArg.forEach(function(dockerfileArg){
|
await dockerfileArg.build()
|
||||||
dockerfileArg.build()
|
})
|
||||||
})
|
return sortedArrayArg
|
||||||
done.resolve(sortedArrayArg)
|
|
||||||
return done.promise
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pushes the real Dockerfile images to a Docker registry
|
* pushes the real Dockerfile images to a Docker registry
|
||||||
*/
|
*/
|
||||||
export let pushDockerfiles = function(sortedArrayArg: Dockerfile[]){
|
export let pushDockerfiles = async (sortedArrayArg: Dockerfile[]) => {
|
||||||
let done = plugins.q.defer()
|
sortedArrayArg.forEach(async (dockerfileArg) => {
|
||||||
sortedArrayArg.forEach(function(dockerfileArg){
|
await dockerfileArg.push(NpmciEnv.buildStage)
|
||||||
dockerfileArg.push(NpmciEnv.buildStage)
|
})
|
||||||
})
|
return sortedArrayArg
|
||||||
done.resolve(sortedArrayArg)
|
|
||||||
return done.promise
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pulls corresponding real Docker images for instances of Dockerfile from a registry.
|
* pulls corresponding real Docker images for instances of Dockerfile from a registry.
|
||||||
* This is needed if building, testing, and publishing of Docker images is carried out in seperate CI stages.
|
* This is needed if building, testing, and publishing of Docker images is carried out in seperate CI stages.
|
||||||
*/
|
*/
|
||||||
export let pullDockerfileImages = (sortableArrayArg: Dockerfile[],registryArg = 'registry.gitlab.com') => {
|
export let pullDockerfileImages = async (sortableArrayArg: Dockerfile[], registryArg = 'registry.gitlab.com') => {
|
||||||
let done = plugins.q.defer()
|
sortableArrayArg.forEach(async (dockerfileArg) => {
|
||||||
sortableArrayArg.forEach((dockerfileArg) => {
|
await dockerfileArg.pull(registryArg)
|
||||||
dockerfileArg.pull(registryArg)
|
})
|
||||||
})
|
return sortableArrayArg
|
||||||
done.resolve(sortableArrayArg)
|
|
||||||
return done.promise
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* tests all Dockerfiles in by calling class Dockerfile.test();
|
* tests all Dockerfiles in by calling class Dockerfile.test();
|
||||||
* @param sortedArrayArg Dockerfile[] that contains all Dockerfiles in cwd
|
* @param sortedArrayArg Dockerfile[] that contains all Dockerfiles in cwd
|
||||||
*/
|
*/
|
||||||
export let testDockerfiles = (sortedArrayArg: Dockerfile[]) => {
|
export let testDockerfiles = async (sortedArrayArg: Dockerfile[]) => {
|
||||||
let done = plugins.q.defer()
|
sortedArrayArg.forEach(async (dockerfileArg) => {
|
||||||
sortedArrayArg.forEach(function(dockerfileArg){
|
await dockerfileArg.test()
|
||||||
dockerfileArg.test()
|
})
|
||||||
})
|
return sortedArrayArg
|
||||||
done.resolve(sortedArrayArg)
|
|
||||||
return done.promise
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* class Dockerfile represents a Dockerfile on disk in npmci
|
* class Dockerfile represents a Dockerfile on disk in npmci
|
||||||
*/
|
*/
|
||||||
export class Dockerfile {
|
export class Dockerfile {
|
||||||
filePath: string
|
filePath: string
|
||||||
repo: string
|
repo: string
|
||||||
version: string
|
version: string
|
||||||
cleanTag: string
|
cleanTag: string
|
||||||
buildTag: string
|
buildTag: string
|
||||||
testTag: string
|
testTag: string
|
||||||
releaseTag: string
|
releaseTag: string
|
||||||
containerName: string
|
containerName: string
|
||||||
content: string
|
content: string
|
||||||
baseImage: string
|
baseImage: string
|
||||||
localBaseImageDependent: boolean
|
localBaseImageDependent: boolean
|
||||||
localBaseDockerfile: Dockerfile
|
localBaseDockerfile: Dockerfile
|
||||||
constructor(options: {filePath?: string,fileContents?: string|Buffer,read?: boolean}) {
|
constructor(options: { filePath?: string, fileContents?: string | Buffer, read?: boolean }) {
|
||||||
this.filePath = options.filePath
|
this.filePath = options.filePath
|
||||||
this.repo = NpmciEnv.repo.user + '/' + NpmciEnv.repo.repo
|
this.repo = NpmciEnv.repo.user + '/' + NpmciEnv.repo.repo
|
||||||
this.version = dockerFileVersion(plugins.path.parse(options.filePath).base)
|
this.version = dockerFileVersion(plugins.path.parse(options.filePath).base)
|
||||||
this.cleanTag = this.repo + ':' + this.version
|
this.cleanTag = this.repo + ':' + this.version
|
||||||
this.buildTag = this.cleanTag
|
this.buildTag = this.cleanTag
|
||||||
this.testTag = dockerTag('registry.gitlab.com',this.repo,this.version,'test')
|
this.testTag = dockerTag('registry.gitlab.com', this.repo, this.version, 'test')
|
||||||
this.releaseTag = dockerTag(NpmciEnv.dockerRegistry,this.repo,this.version)
|
this.releaseTag = dockerTag(NpmciEnv.dockerRegistry, this.repo, this.version)
|
||||||
this.containerName = 'dockerfile-' + this.version
|
this.containerName = 'dockerfile-' + this.version
|
||||||
if (options.filePath && options.read) {
|
if (options.filePath && options.read) {
|
||||||
this.content = plugins.smartfile.fs.toStringSync(plugins.path.resolve(options.filePath))
|
this.content = plugins.smartfile.fs.toStringSync(plugins.path.resolve(options.filePath))
|
||||||
};
|
|
||||||
this.baseImage = dockerBaseImage(this.content)
|
|
||||||
this.localBaseImageDependent = false
|
|
||||||
};
|
};
|
||||||
|
this.baseImage = dockerBaseImage(this.content)
|
||||||
|
this.localBaseImageDependent = false
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* builds the Dockerfile
|
* builds the Dockerfile
|
||||||
*/
|
*/
|
||||||
build() {
|
async build() {
|
||||||
let done = plugins.q.defer()
|
plugins.beautylog.info('now building Dockerfile for ' + this.cleanTag)
|
||||||
plugins.beautylog.info('now building Dockerfile for ' + this.cleanTag)
|
await bashBare('docker build -t ' + this.buildTag + ' -f ' + this.filePath + ' .')
|
||||||
bashBare('docker build -t ' + this.buildTag + ' -f ' + this.filePath + ' .')
|
NpmciEnv.dockerFilesBuilt.push(this)
|
||||||
NpmciEnv.dockerFilesBuilt.push(this)
|
};
|
||||||
done.resolve()
|
|
||||||
return done.promise
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* pushes the Dockerfile to a registry
|
* pushes the Dockerfile to a registry
|
||||||
*/
|
*/
|
||||||
push(stageArg) {
|
async push(stageArg) {
|
||||||
let done = plugins.q.defer()
|
let pushTag
|
||||||
let pushTag
|
switch (stageArg) {
|
||||||
switch (stageArg) {
|
case 'release':
|
||||||
case 'release':
|
pushTag = this.releaseTag
|
||||||
pushTag = this.releaseTag
|
break
|
||||||
break
|
case 'test':
|
||||||
case 'test':
|
default:
|
||||||
default:
|
pushTag = this.testTag
|
||||||
pushTag = this.testTag
|
break
|
||||||
break
|
|
||||||
}
|
|
||||||
bashBare('docker tag ' + this.buildTag + ' ' + pushTag)
|
|
||||||
bashBare('docker push ' + pushTag)
|
|
||||||
done.resolve()
|
|
||||||
return done.promise
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* pulls the Dockerfile from a registry
|
|
||||||
*/
|
|
||||||
pull(registryArg: string) {
|
|
||||||
let pullTag = this.testTag
|
|
||||||
bashBare('docker pull ' + pullTag)
|
|
||||||
bashBare('docker tag ' + pullTag + ' ' + this.buildTag)
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* tests the Dockerfile;
|
|
||||||
*/
|
|
||||||
test() {
|
|
||||||
let testFile: string = plugins.path.join(paths.NpmciTestDir,'test_' + this.version + '.sh')
|
|
||||||
let testFileExists: boolean = plugins.smartfile.fs.fileExistsSync(testFile)
|
|
||||||
if (testFileExists) {
|
|
||||||
bashBare('docker run --name npmci_test_container ' + this.buildTag + ' mkdir /npmci_test')
|
|
||||||
bashBare('docker cp ' + testFile + ' npmci_test_container:/npmci_test/test.sh')
|
|
||||||
bashBare('docker commit npmci_test_container npmci_test_image')
|
|
||||||
bashBare('docker run npmci_test_image sh /npmci_test/test.sh')
|
|
||||||
bashBare('docker rm npmci_test_container')
|
|
||||||
bashBare('docker rmi --force npmci_test_image')
|
|
||||||
} else {
|
|
||||||
plugins.beautylog.warn('skipping tests for ' + this.cleanTag + ' because no testfile was found!')
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* gets the id of a Dockerfile
|
|
||||||
*/
|
|
||||||
getId() {
|
|
||||||
let containerId = bashBare('docker inspect --type=image --format=\"{{.Id}}\" ' + this.buildTag)
|
|
||||||
return containerId
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
export let dockerFileVersion = function(dockerfileNameArg: string): string{
|
|
||||||
let versionString: string
|
|
||||||
let versionRegex = /Dockerfile_([a-zA-Z0-9\.]*)$/
|
|
||||||
let regexResultArray = versionRegex.exec(dockerfileNameArg)
|
|
||||||
if (regexResultArray && regexResultArray.length === 2) {
|
|
||||||
versionString = regexResultArray[1]
|
|
||||||
} else {
|
|
||||||
versionString = 'latest'
|
|
||||||
}
|
}
|
||||||
return versionString
|
await bashBare('docker tag ' + this.buildTag + ' ' + pushTag)
|
||||||
|
await bashBare('docker push ' + pushTag)
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* pulls the Dockerfile from a registry
|
||||||
|
*/
|
||||||
|
async pull(registryArg: string) {
|
||||||
|
let pullTag = this.testTag
|
||||||
|
await bashBare('docker pull ' + pullTag)
|
||||||
|
await bashBare('docker tag ' + pullTag + ' ' + this.buildTag)
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* tests the Dockerfile;
|
||||||
|
*/
|
||||||
|
async test() {
|
||||||
|
let testFile: string = plugins.path.join(paths.NpmciTestDir, 'test_' + this.version + '.sh')
|
||||||
|
let testFileExists: boolean = plugins.smartfile.fs.fileExistsSync(testFile)
|
||||||
|
if (testFileExists) {
|
||||||
|
// run tests
|
||||||
|
await bashBare('docker run --name npmci_test_container ' + this.buildTag + ' mkdir /npmci_test')
|
||||||
|
await bashBare('docker cp ' + testFile + ' npmci_test_container:/npmci_test/test.sh')
|
||||||
|
await bashBare('docker commit npmci_test_container npmci_test_image')
|
||||||
|
await bashBare('docker run npmci_test_image sh /npmci_test/test.sh')
|
||||||
|
await bashBare('docker rm npmci_test_container')
|
||||||
|
await bashBare('docker rmi --force npmci_test_image')
|
||||||
|
} else {
|
||||||
|
plugins.beautylog.warn('skipping tests for ' + this.cleanTag + ' because no testfile was found!')
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets the id of a Dockerfile
|
||||||
|
*/
|
||||||
|
async getId() {
|
||||||
|
let containerId = await bashBare('docker inspect --type=image --format=\"{{.Id}}\" ' + this.buildTag)
|
||||||
|
return containerId
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* returns a version for a docker file
|
||||||
|
* @execution SYNC
|
||||||
|
*/
|
||||||
|
export let dockerFileVersion = (dockerfileNameArg: string): string => {
|
||||||
|
let versionString: string
|
||||||
|
let versionRegex = /Dockerfile_([a-zA-Z0-9\.]*)$/
|
||||||
|
let regexResultArray = versionRegex.exec(dockerfileNameArg)
|
||||||
|
if (regexResultArray && regexResultArray.length === 2) {
|
||||||
|
versionString = regexResultArray[1]
|
||||||
|
} else {
|
||||||
|
versionString = 'latest'
|
||||||
|
}
|
||||||
|
return versionString
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export let dockerBaseImage = function(dockerfileContentArg: string){
|
export let dockerBaseImage = function (dockerfileContentArg: string) {
|
||||||
let baseImageRegex = /FROM\s([a-zA-z0-9\/\-\:]*)\n?/
|
let baseImageRegex = /FROM\s([a-zA-z0-9\/\-\:]*)\n?/
|
||||||
let regexResultArray = baseImageRegex.exec(dockerfileContentArg)
|
let regexResultArray = baseImageRegex.exec(dockerfileContentArg)
|
||||||
return regexResultArray[1]
|
return regexResultArray[1]
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export let dockerTag = function(registryArg: string,repoArg: string,versionArg: string,suffixArg?: string): string{
|
export let dockerTag = function (registryArg: string, repoArg: string, versionArg: string, suffixArg?: string): string {
|
||||||
let tagString: string
|
let tagString: string
|
||||||
let registry = registryArg
|
let registry = registryArg
|
||||||
let repo = repoArg
|
let repo = repoArg
|
||||||
let version = versionArg
|
let version = versionArg
|
||||||
if (suffixArg) {
|
if (suffixArg) {
|
||||||
version = versionArg + '_' + suffixArg
|
version = versionArg + '_' + suffixArg
|
||||||
};
|
};
|
||||||
tagString = registry + '/' + repo + ':' + version
|
tagString = registry + '/' + repo + ':' + version
|
||||||
return tagString
|
return tagString
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
export let cleanTagsArrayFunction = function(dockerfileArrayArg: Dockerfile[],trackingArrayArg: Dockerfile[]): string[]{
|
export let cleanTagsArrayFunction = function (dockerfileArrayArg: Dockerfile[], trackingArrayArg: Dockerfile[]): string[] {
|
||||||
let cleanTagsArray: string[] = []
|
let cleanTagsArray: string[] = []
|
||||||
dockerfileArrayArg.forEach(function(dockerfileArg){
|
dockerfileArrayArg.forEach(function (dockerfileArg) {
|
||||||
if (trackingArrayArg.indexOf(dockerfileArg) === -1) {
|
if (trackingArrayArg.indexOf(dockerfileArg) === -1) {
|
||||||
cleanTagsArray.push(dockerfileArg.cleanTag)
|
cleanTagsArray.push(dockerfileArg.cleanTag)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
return cleanTagsArray
|
return cleanTagsArray
|
||||||
}
|
}
|
||||||
|
@ -1,22 +1,23 @@
|
|||||||
import * as plugins from './npmci.plugins'
|
import * as plugins from './npmci.plugins'
|
||||||
import {bash} from './npmci.bash'
|
import { bash } from './npmci.bash'
|
||||||
import * as env from './npmci.env'
|
import * as env from './npmci.env'
|
||||||
import * as buildDocker from './npmci.build.docker'
|
import * as buildDocker from './npmci.build.docker'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* defines possible build services
|
* defines possible build services
|
||||||
*/
|
*/
|
||||||
export type TBuildService = 'docker';
|
export type TBuildService = 'docker'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* builds for a specific service
|
* builds for a specific service
|
||||||
*/
|
*/
|
||||||
export let build = function(commandArg): plugins.q.Promise<any> {
|
export let build = async (commandArg): Promise<void> => {
|
||||||
switch (commandArg) {
|
switch (commandArg) {
|
||||||
case 'docker':
|
case 'docker':
|
||||||
return buildDocker.build()
|
await buildDocker.build()
|
||||||
default:
|
break
|
||||||
plugins.beautylog.log('build target ' + commandArg + ' not recognised!')
|
default:
|
||||||
};
|
plugins.beautylog.log('build target ' + commandArg + ' not recognised!')
|
||||||
return
|
};
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,7 @@ import * as paths from './npmci.paths'
|
|||||||
/**
|
/**
|
||||||
* cleans npmci config files
|
* cleans npmci config files
|
||||||
*/
|
*/
|
||||||
export let clean = () => {
|
export let clean = async (): Promise<void> => {
|
||||||
let done = plugins.q.defer()
|
plugins.smartfile.fs.removeSync(paths.NpmciPackageConfig)
|
||||||
plugins.smartfile.fs.removeSync(paths.NpmciPackageConfig)
|
return
|
||||||
done.resolve()
|
|
||||||
return done.promise
|
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,7 @@ export import lodash = require('lodash')
|
|||||||
export import npmextra = require('npmextra')
|
export import npmextra = require('npmextra')
|
||||||
export import path = require('path')
|
export import path = require('path')
|
||||||
export import projectinfo = require('projectinfo')
|
export import projectinfo = require('projectinfo')
|
||||||
export import q = require('q')
|
export import q = require('smartq')
|
||||||
export let request = require('request')
|
export let request = require('request')
|
||||||
export import shelljs = require('shelljs')
|
export import shelljs = require('shelljs')
|
||||||
export import smartcli = require('smartcli')
|
export import smartcli = require('smartcli')
|
||||||
|
@ -1676,7 +1676,7 @@ oauth-sign@~0.8.1:
|
|||||||
version "0.8.2"
|
version "0.8.2"
|
||||||
resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.8.2.tgz#46a6ab7f0aead8deae9ec0565780b7d4efeb9d43"
|
resolved "https://registry.yarnpkg.com/oauth-sign/-/oauth-sign-0.8.2.tgz#46a6ab7f0aead8deae9ec0565780b7d4efeb9d43"
|
||||||
|
|
||||||
object-assign@4.1.0:
|
object-assign@4.1.0, object-assign@^4.0.1:
|
||||||
version "4.1.0"
|
version "4.1.0"
|
||||||
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.0.tgz#7a3b3d0e98063d43f4c03f2e8ae6cd51a86883a0"
|
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.0.tgz#7a3b3d0e98063d43f4c03f2e8ae6cd51a86883a0"
|
||||||
|
|
||||||
@ -1684,10 +1684,6 @@ object-assign@^3.0.0:
|
|||||||
version "3.0.0"
|
version "3.0.0"
|
||||||
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-3.0.0.tgz#9bedd5ca0897949bca47e7ff408062d549f587f2"
|
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-3.0.0.tgz#9bedd5ca0897949bca47e7ff408062d549f587f2"
|
||||||
|
|
||||||
object-assign@^4.0.1:
|
|
||||||
version "4.1.1"
|
|
||||||
resolved "https://registry.yarnpkg.com/object-assign/-/object-assign-4.1.1.tgz#2109adc7965887cfc05cbbd442cac8bfbb360863"
|
|
||||||
|
|
||||||
object-component@0.0.3:
|
object-component@0.0.3:
|
||||||
version "0.0.3"
|
version "0.0.3"
|
||||||
resolved "https://registry.yarnpkg.com/object-component/-/object-component-0.0.3.tgz#f0c69aa50efc95b866c186f400a33769cb2f1291"
|
resolved "https://registry.yarnpkg.com/object-component/-/object-component-0.0.3.tgz#f0c69aa50efc95b866c186f400a33769cb2f1291"
|
||||||
|
Loading…
Reference in New Issue
Block a user