Skip to content

Commit d2c7477

Browse files
committed
fix(docker): ensure temp admin pass shows
1 parent 683c20c commit d2c7477

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

src/backend/src/modules/selfhosted/DefaultUserService.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,18 @@ class DefaultUserService extends BaseService {
9090
if ( ! is_default_password ) return;
9191

9292
// show console widget
93-
this.default_user_widget = () => {
93+
this.default_user_widget = ({ is_docker }) => {
94+
if ( is_docker ) {
95+
// In Docker we keep the output as simple as possible because
96+
// we're unable to determine the size of the terminal
97+
return [
98+
'Password for `admin`: ' + tmp_password,
99+
// TODO: possible bug
100+
// These blank lines are necessary for it to render and
101+
// I'm not entirely sure why anymore.
102+
'', '',
103+
];
104+
}
94105
const lines = [
95106
`Your admin user has been created!`,
96107
`\x1B[31;1musername:\x1B[0m ${USERNAME}`,
@@ -100,6 +111,7 @@ class DefaultUserService extends BaseService {
100111
surrounding_box('31;1', lines);
101112
return lines;
102113
};
114+
this.default_user_widget.critical = true;
103115
this.start_poll_({ tmp_password, user });
104116
const svc_devConsole = this.services.get('dev-console');
105117
svc_devConsole.add_widget(this.default_user_widget);

src/backend/src/services/DevConsoleService.js

+19-2
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,26 @@ const { consoleLogManager } = require('../util/consolelog');
2020
const BaseService = require('./BaseService');
2121

2222
class DevConsoleService extends BaseService {
23+
static MODULES = {
24+
fs: require('fs'),
25+
}
26+
2327
_construct () {
2428
this.static_lines = [];
2529
this.widgets = [];
2630
this.identifiers = {};
2731
this.has_updates = false;
32+
33+
try {
34+
const require = this.require;
35+
const fs = require('fs');
36+
this.is_docker = fs.existsSync('/.dockerenv');
37+
} catch (e) {
38+
// if this fails, we assume is_docker should
39+
// be false.
40+
this.log.error(e.message);
41+
this.is_docker = false;
42+
}
2843
}
2944

3045
turn_on_the_warning_lights () {
@@ -60,7 +75,7 @@ class DevConsoleService extends BaseService {
6075
let positions = [];
6176
for ( const w of this.widgets ) {
6277
let output; try {
63-
output = w();
78+
output = w({ is_docker: this.is_docker });
6479
} catch ( e ) {
6580
consoleLogManager.log_raw('error', e);
6681
to_remove.push(w);
@@ -78,6 +93,7 @@ class DevConsoleService extends BaseService {
7893
for ( let i = this.widgets.length-1 ; i >= 0 ; i-- ) {
7994
if ( size_ok() ) break;
8095
const w = this.widgets[i];
96+
if ( w.critical ) continue;
8197
if ( ! w.unimportant ) continue;
8298
n_hidden++;
8399
const [start, length] = positions[i];
@@ -89,8 +105,9 @@ class DevConsoleService extends BaseService {
89105
}
90106
for ( let i = this.widgets.length-1 ; i >= 0 ; i-- ) {
91107
if ( size_ok() ) break;
92-
n_hidden++;
93108
const w = this.widgets[i];
109+
if ( w.critical ) continue;
110+
n_hidden++;
94111
const [start, length] = positions[i];
95112
this.static_lines.splice(start, length);
96113
}

0 commit comments

Comments
 (0)