update to support more detailed docker publishing
This commit is contained in:
@@ -11,14 +11,15 @@ export type TBuildService = 'docker'
|
||||
/**
|
||||
* builds for a specific service
|
||||
*/
|
||||
export let build = async (commandArg): Promise<void> => {
|
||||
switch (commandArg) {
|
||||
export let build = async (argvArg): Promise<void> => {
|
||||
let whatToPublish: string = argvArg._[1]
|
||||
switch (whatToPublish) {
|
||||
case 'docker':
|
||||
let modDocker = await npmciMods.modDocker.load()
|
||||
await modDocker.build()
|
||||
await modDocker.build(argvArg)
|
||||
break
|
||||
default:
|
||||
plugins.beautylog.log('build target ' + commandArg + ' not recognised!')
|
||||
plugins.beautylog.log('build target ' + whatToPublish + ' not recognised!')
|
||||
};
|
||||
return
|
||||
}
|
||||
|
@@ -3,10 +3,13 @@ import * as paths from '../npmci.paths'
|
||||
import * as NpmciEnv from '../npmci.env'
|
||||
import { bash } from '../npmci.bash'
|
||||
|
||||
let modArgvArg // will be set through the build command
|
||||
|
||||
/**
|
||||
* builds a cwd of Dockerfiles by triggering a promisechain
|
||||
*/
|
||||
export let build = async () => {
|
||||
export let build = async (argvArg: any) => {
|
||||
modArgvArg = argvArg
|
||||
plugins.beautylog.log('now building Dockerfiles...')
|
||||
await readDockerfiles()
|
||||
.then(sortDockerfiles)
|
||||
@@ -105,8 +108,15 @@ export let buildDockerfiles = async (sortedArrayArg: Dockerfile[]) => {
|
||||
* pushes the real Dockerfile images to a Docker registry
|
||||
*/
|
||||
export let pushDockerfiles = async (sortedArrayArg: Dockerfile[]) => {
|
||||
let stageArg = (function () {
|
||||
if (modArgvArg._ && modArgvArg._.length >= 3) {
|
||||
return modArgvArg._[2]
|
||||
} else {
|
||||
return NpmciEnv.buildStage
|
||||
}
|
||||
})()
|
||||
for (let dockerfileArg of sortedArrayArg) {
|
||||
await dockerfileArg.push(NpmciEnv.buildStage)
|
||||
await dockerfileArg.push(stageArg)
|
||||
}
|
||||
return sortedArrayArg
|
||||
}
|
||||
@@ -150,7 +160,7 @@ export class Dockerfile {
|
||||
baseImage: string
|
||||
localBaseImageDependent: boolean
|
||||
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.repo = NpmciEnv.repo.user + '/' + NpmciEnv.repo.repo
|
||||
this.version = dockerFileVersion(plugins.path.parse(options.filePath).base)
|
||||
@@ -181,7 +191,7 @@ export class Dockerfile {
|
||||
/**
|
||||
* pushes the Dockerfile to a registry
|
||||
*/
|
||||
async push(stageArg) {
|
||||
async push (stageArg) {
|
||||
switch (stageArg) {
|
||||
case 'release':
|
||||
await bash(`docker tag ${this.buildTag} ${this.releaseTag}`)
|
||||
@@ -204,7 +214,7 @@ export class Dockerfile {
|
||||
/**
|
||||
* pulls the Dockerfile from a registry
|
||||
*/
|
||||
async pull(registryArg: string) {
|
||||
async pull (registryArg: string) {
|
||||
let pullTag = this.gitlabTestTag
|
||||
await bash('docker pull ' + pullTag)
|
||||
await bash('docker tag ' + pullTag + ' ' + this.buildTag)
|
||||
@@ -213,7 +223,7 @@ export class Dockerfile {
|
||||
/**
|
||||
* tests the Dockerfile;
|
||||
*/
|
||||
async test() {
|
||||
async test () {
|
||||
let testFile: string = plugins.path.join(paths.NpmciTestDir, 'test_' + this.version + '.sh')
|
||||
let testFileExists: boolean = plugins.smartfile.fs.fileExistsSync(testFile)
|
||||
if (testFileExists) {
|
||||
@@ -232,7 +242,7 @@ export class Dockerfile {
|
||||
/**
|
||||
* gets the id of a Dockerfile
|
||||
*/
|
||||
async getId() {
|
||||
async getId () {
|
||||
let containerId = await bash('docker inspect --type=image --format=\"{{.Id}}\" ' + this.buildTag)
|
||||
return containerId
|
||||
};
|
||||
@@ -247,7 +257,7 @@ export let dockerFileVersion = (dockerfileNameArg: string): string => {
|
||||
let versionRegex = /Dockerfile_([a-zA-Z0-9\.]*)$/
|
||||
let regexResultArray = versionRegex.exec(dockerfileNameArg)
|
||||
if (regexResultArray && regexResultArray.length === 2) {
|
||||
versionString = regexResultArray[ 1 ]
|
||||
versionString = regexResultArray[1]
|
||||
} else {
|
||||
versionString = 'latest'
|
||||
}
|
||||
@@ -260,7 +270,7 @@ export let dockerFileVersion = (dockerfileNameArg: string): string => {
|
||||
export let dockerBaseImage = function (dockerfileContentArg: string) {
|
||||
let baseImageRegex = /FROM\s([a-zA-z0-9\/\-\:]*)\n?/
|
||||
let regexResultArray = baseImageRegex.exec(dockerfileContentArg)
|
||||
return regexResultArray[ 1 ]
|
||||
return regexResultArray[1]
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -31,17 +31,22 @@ let npm = async () => {
|
||||
* logs in docker
|
||||
*/
|
||||
let docker = async () => {
|
||||
env.setDockerRegistry('docker.io')
|
||||
env.setDockerRegistry('docker.io') // TODO: checkup why we set this here
|
||||
let dockerRegex = /^([a-zA-Z0-9\.]*)\|([a-zA-Z0-9\.]*)/
|
||||
|
||||
// Login external reigstry
|
||||
if (!process.env.NPMCI_LOGIN_DOCKER) {
|
||||
plugins.beautylog.error('You have to specify Login Data to the Docker Registry')
|
||||
process.exit(1)
|
||||
plugins.beautylog.warn('You have to specify Login Data to an external Docker Registry')
|
||||
plugins.beautylog.warn('|- As a result only the gitlab registry is availble for this build.')
|
||||
} else {
|
||||
let dockerRegexResultArray = dockerRegex.exec(process.env.NPMCI_LOGIN_DOCKER)
|
||||
let username = dockerRegexResultArray[1]
|
||||
let password = dockerRegexResultArray[2]
|
||||
await bash('docker login -u ' + username + ' -p ' + password)
|
||||
}
|
||||
plugins.shelljs.exec('docker login -u gitlab-ci-token -p ' + process.env.CI_BUILD_TOKEN + ' ' + 'registry.gitlab.com') // Always also login to GitLab Registry
|
||||
let dockerRegexResultArray = dockerRegex.exec(process.env.NPMCI_LOGIN_DOCKER)
|
||||
let username = dockerRegexResultArray[1]
|
||||
let password = dockerRegexResultArray[2]
|
||||
await bash('docker login -u ' + username + ' -p ' + password)
|
||||
|
||||
// Always login to GitLab Registry
|
||||
plugins.shelljs.exec('docker login -u gitlab-ci-token -p ' + process.env.CI_BUILD_TOKEN + ' ' + 'registry.gitlab.com')
|
||||
return
|
||||
}
|
||||
|
||||
|
@@ -76,9 +76,9 @@ smartcli.addCommand('prepare')
|
||||
|
||||
// publish
|
||||
smartcli.addCommand('publish')
|
||||
.then(async (argv) => {
|
||||
.then(async (argvArg) => {
|
||||
let modPublish = await npmciMods.modPublish.load()
|
||||
await modPublish.publish(argv._[1])
|
||||
await modPublish.publish(argvArg)
|
||||
await NpmciEnv.configStore()
|
||||
|
||||
}).catch(err => {
|
||||
|
@@ -3,6 +3,9 @@ import * as paths from './npmci.paths'
|
||||
import { GitRepo } from 'smartstring'
|
||||
import { Dockerfile } from './mod_docker/index'
|
||||
|
||||
/**
|
||||
* a info instance about the git respoitory at cwd :)
|
||||
*/
|
||||
export let repo: GitRepo
|
||||
if (process.env.CI_REPOSITORY_URL) {
|
||||
repo = new GitRepo(process.env.CI_REPOSITORY_URL)
|
||||
@@ -31,6 +34,9 @@ export let config = {
|
||||
project: undefined
|
||||
}
|
||||
|
||||
/**
|
||||
* the configuration store
|
||||
*/
|
||||
export let configStore = async () => {
|
||||
config.dockerRegistry = dockerRegistry
|
||||
plugins.smartfile.memory.toFsSync(
|
||||
@@ -39,6 +45,9 @@ export let configStore = async () => {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* load the config in case a previous run has stored it
|
||||
*/
|
||||
let configLoad = () => {
|
||||
// internal config to transfer information in between npmci shell calls
|
||||
try {
|
||||
|
Reference in New Issue
Block a user