fix docker testing

This commit is contained in:
2017-10-13 16:44:25 +02:00
parent 977ecabb41
commit 34753a4ae0
13 changed files with 102 additions and 103 deletions

View File

@ -18,7 +18,7 @@ let getQenvKeyValueObject = async () => {
qenvKeyValueObjectArray = new plugins.qenv.Qenv(paths.cwd, '.nogit/').keyValueObjectArray
} else {
qenvKeyValueObjectArray = []
};
}
return qenvKeyValueObjectArray
}

View File

@ -1,5 +1,5 @@
import * as plugins from './npmdocker.plugins';
import * as paths from './npmdocker.paths';
import * as plugins from './npmdocker.plugins'
import * as paths from './npmdocker.paths'
import * as snippets from './npmdocker.snippets'
// interfaces
@ -45,8 +45,9 @@ let buildDockerFile = () => {
})
plugins.beautylog.info(`Base image is: ${config.baseImage}`)
plugins.beautylog.info(`Command is: ${config.command}`)
plugins.smartfile.memory.toFsSync(dockerfile, paths.dockerfile)
plugins.smartfile.memory.toFsSync(dockerfile, plugins.path.join(paths.cwd, 'npmdocker'))
plugins.beautylog.ok('Dockerfile created!')
plugins.beautylog.ora.stop()
done.resolve()
return done.promise
}
@ -55,26 +56,19 @@ let buildDockerFile = () => {
* builds the Dockerimage from the built Dockerfile
*/
let buildDockerImage = async () => {
plugins.beautylog.ora.text('pulling latest base image from registry...')
await plugins.smartshell.execSilent(
plugins.beautylog.info('pulling latest base image from registry...')
await plugins.smartshell.exec(
`docker pull ${config.baseImage}`
).then(async () => {
plugins.beautylog.ora.text('building Dockerimage...')
// are we creating a build context form project ?
if (process.env.CI === 'true') {
plugins.beautylog.ora.text('creating build context...')
plugins.smartfile.fs.copySync(paths.cwd, paths.buildContextDir)
}
await plugins.smartshell.execSilent(
`docker build -f ${paths.dockerfile} -t ${dockerData.imageTag} ${paths.assets}`
).then(async (response) => {
if (response.exitCode !== 0) {
console.log(response.stdout)
process.exit(1)
}
plugins.beautylog.ok('Dockerimage built!')
})
})
)
plugins.beautylog.ora.text('building Dockerimage...')
let execResult = await plugins.smartshell.execSilent(
`docker build -f npmdocker -t ${dockerData.imageTag} ${paths.cwd}`
)
if (execResult.exitCode !== 0) {
console.log(execResult.stdout)
process.exit(1)
}
plugins.beautylog.ok('Dockerimage built!')
}
let buildDockerProjectMountString = async () => {
@ -89,7 +83,7 @@ let buildDockerProjectMountString = async () => {
let buildDockerEnvString = async () => {
for (let keyValueObjectArg of config.keyValueObjectArray) {
let envString = dockerData.dockerEnvString = dockerData.dockerEnvString + `-e ${keyValueObjectArg.key}=${keyValueObjectArg.value} `
};
}
}
/**
@ -130,13 +124,6 @@ let deleteDockerImage = async () => {
})
}
/**
* cleans up, deletes the build context
*/
let deleteBuildContext = async () => {
await plugins.smartfile.fs.remove(paths.buildContextDir)
}
let preClean = async () => {
await deleteDockerImage()
.then(deleteDockerContainer)
@ -148,14 +135,12 @@ let preClean = async () => {
let postClean = async () => {
await deleteDockerContainer()
.then(deleteDockerImage)
.then(deleteBuildContext)
.then(async () => {
plugins.beautylog.ok('cleaned up!')
})
await plugins.smartfile.fs.remove(paths.npmdockerFile)
}
export let run = async (configArg: IConfig): Promise<IConfig> => {
plugins.beautylog.ora.start()
config = configArg

View File

@ -1,13 +1,8 @@
import * as plugins from "./npmdocker.plugins";
import * as plugins from "./npmdocker.plugins"
// directories
export let cwd = process.cwd();
export let packageBase = plugins.path.join(__dirname, "../");
export let assets = plugins.path.join(packageBase, "assets/");
plugins.smartfile.fs.ensureDirSync(assets);
export let buildContextDir = plugins.path.join(assets,"buildContextDir");
plugins.smartfile.fs.ensureDirSync(buildContextDir);
// files
export let dockerfile = plugins.path.join(assets, "Dockerfile");
export let cwd = process.cwd()
export let packageBase = plugins.path.join(__dirname, "../")
export let assets = plugins.path.join(packageBase, "assets/")
plugins.smartfile.fs.ensureDirSync(assets)
export let npmdockerFile = plugins.path.join(cwd, 'npmdocker')

View File

@ -1,17 +1,37 @@
import * as plugins from "./npmdocker.plugins";
export interface IDockerfileSnippet {
baseImage: string;
command: string;
baseImage: string
command: string
}
let getMountSolutionString = (optionsArg: IDockerfileSnippet) => {
if (process.env.CI) {
return 'COPY ./ /workspace'
} else {
return '# not copying workspcae since not in CI'
}
}
let getGlobalPreparationString = (optionsArg: IDockerfileSnippet) => {
if (optionsArg.baseImage !== 'hosttoday/ht-docker-node:npmdocker') {
return 'RUN yarn global add npmdocker'
} else {
return '# not installing npmdocker since it is included in the base image'
}
}
export let dockerfileSnippet = (optionsArg: IDockerfileSnippet): string => {
return plugins.smartstring.indent.normalize(`
FROM ${optionsArg.baseImage}
RUN yarn global add npmdocker
COPY ./buildContextDir /workspace
WORKDIR /workspace
ENV CI=true
CMD ["npmdocker","runinside"];
`)
return plugins.smartstring.indent.normalize(
`
FROM ${optionsArg.baseImage}
# For info about what npmdocker does read the docs at https://gitzone.github.io/npmdocker
${getGlobalPreparationString(optionsArg)}
${getMountSolutionString(optionsArg)}
WORKDIR /workspace
ENV CI=true
ENTRYPOINT ["npmdocker"]
CMD ["runinside"]
`
)
}