Skip to content

Commit

Permalink
When starting docker containers, adds the CHE_* env variables
Browse files Browse the repository at this point in the history
For action, test and che-dir, improve log output to match the new cli output

Change-Id: I2f7da27f9a9658e2fbc49f3a766593203b172f4d
Signed-off-by: Florent BENOIT <fbenoit@codenvy.com>
  • Loading branch information
benoitf committed Dec 20, 2016
1 parent aba9a87 commit 3975d69
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 11 deletions.
23 changes: 21 additions & 2 deletions dockerfiles/base/scripts/base/docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -121,12 +121,31 @@ docker_run() {
DOCKER_HOST="/var/run/docker.sock"
fi

echo "" > /tmp/docker_run_vars
# Add environment variables for CHE
while IFS='=' read -r -d '' key value; do
if [[ ${key} == "CHE_"* ]]; then
echo ${key}=${value} >> /tmp/docker_run_vars
fi
done < <(env -0)

# Add scripts global variables for CHE
while read key; do
if [[ ${key} == "CHE_"* ]]; then
local ENV_VAL="${!key}"
echo ${key}=${ENV_VAL} >> /tmp/docker_run_vars
fi
done < <(compgen -v)


if [ -S "$DOCKER_HOST" ]; then
docker run --rm -v $DOCKER_HOST:$DOCKER_HOST \
docker run --rm --env-file /tmp/docker_run_vars \
-v $DOCKER_HOST:$DOCKER_HOST \
-v $HOME:$HOME \
-w "$(pwd)" "$@"
else
docker run --rm -e DOCKER_HOST -e DOCKER_TLS_VERIFY -e DOCKER_CERT_PATH \
docker run --rm --env-file /tmp/docker_run_vars \
-e DOCKER_HOST -e DOCKER_TLS_VERIFY -e DOCKER_CERT_PATH \
-v $HOME:$HOME \
-w "$(pwd)" "$@"
fi
Expand Down
6 changes: 3 additions & 3 deletions dockerfiles/lib/src/internal/action/che-action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class CheAction {


static init() : Map<string,any> {
Log.context = ProductName.getDisplayName() + '(action)';
Log.context = '(' + ProductName.getMiniDisplayName() + ' action)';
let actionMap : Map<string, any> = new Map<string, any>();
actionMap.set('create-start-workspace', CreateStartWorkspaceAction);
actionMap.set('add-user', AddUserAction);
Expand All @@ -71,7 +71,7 @@ export class CheAction {
run() : Promise<any> {
let classOfAction: any = this.mapOfActions.get(this.actionName);
if (classOfAction) {
Log.context = ProductName.getDisplayName() + '(action/' + this.actionName + ')';
Log.context = '(' + ProductName.getMiniDisplayName() + ' action/' + this.actionName + ')';
var instance = new classOfAction(this.args);
return instance.run();
} else {
Expand All @@ -86,7 +86,7 @@ export class CheAction {
help() : void {
Log.getLogger().info("Available actions are : ");
for (var [key, value] of this.mapOfActions.entries()) {
Log.getLogger().info('\u001b[1m' + key + '\u001b[0m');
Log.getLogger().direct('\u001b[1m' + key + '\u001b[0m');
ArgumentProcessor.help(Object.create(value.prototype));
}
}
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/lib/src/internal/dir/che-dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class CheDir {
}

run() : Promise<string> {
Log.context = ProductName.getDisplayName() + '(dir)';
Log.context = '(' + ProductName.getMiniDisplayName() + ' dir)';

// call the method analyzed from the argument
return this.parseArgument().then((methodName) => {
Expand Down
4 changes: 2 additions & 2 deletions dockerfiles/lib/src/internal/test/che-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export class CheTest {
mapOfTests : Map<string, any> = CheTest.init();

static init() : Map<string,any> {
Log.context = ProductName.getDisplayName() + '(test)';
Log.context = '(' + ProductName.getMiniDisplayName() + ' test)';
let testMap : Map<string, any> = new Map<string, any>();
testMap.set('post-flight-check', PostFlightCheckTest);
return testMap;
Expand All @@ -61,7 +61,7 @@ export class CheTest {
let classOfTest: any = this.mapOfTests.get(this.testName);
if (classOfTest) {
// update logger
Log.context = ProductName.getDisplayName() + '(test/' + this.testName + ')';
Log.context = '(' + ProductName.getMiniDisplayName() + ' test/' + this.testName + ')';
var instance = new classOfTest(this.args);
return instance.run();
} else {
Expand Down
2 changes: 1 addition & 1 deletion dockerfiles/lib/src/spi/decorator/argument-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class ArgumentProcessor {
asciiFormParameters.withEntry(" <" + metadataArgument.fieldName + ">", metadataArgument.description);
});
}
Log.getLogger().log("multiline:info", asciiFormParameters.toAscii());
Log.getLogger().log("multiline:direct", asciiFormParameters.toAscii());
}

static help(object : any) : void {
Expand Down
6 changes: 5 additions & 1 deletion dockerfiles/lib/src/spi/log/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ export class Log {
} else if ('multiline:info' === type) {
prefix = Log.INFO_PREFIX;
displayEachLine = true;
} else if ('multiline:direct' === type) {
prefix = '';
useContext = false;
displayEachLine = true;
}

if (useContext && Log.context) {
Expand Down Expand Up @@ -125,4 +129,4 @@ export class Log {
}


export type LogType = 'info' | 'debug' | 'warn' | 'error' | 'direct' | 'multiline:info';
export type LogType = 'info' | 'debug' | 'warn' | 'error' | 'direct' | 'multiline:info' | 'multiline:direct';
10 changes: 9 additions & 1 deletion dockerfiles/lib/src/utils/product-name.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,12 @@ export class ProductName {
return productName;
}

}
static getMiniDisplayName() : string {
let miniProductName: string = process.env.CHE_MINI_PRODUCT_NAME;
if (!miniProductName) {
return 'Eclipse Che';
}
return miniProductName;
}

}

0 comments on commit 3975d69

Please sign in to comment.