Skip to content

Commit

Permalink
fix for passwd entry and fix for side car controls
Browse files Browse the repository at this point in the history
  • Loading branch information
DeepCowProductions committed Sep 6, 2024
1 parent 3b5e811 commit 0a291da
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
3 changes: 2 additions & 1 deletion base-images/vscode/rebind_home.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ if [[ -w /etc/passwd ]] && [[ -w /home ]]; then
if [[ "${NB_USER}" != "jovyan" ]]; then
_log "creating enw home for user ${NB_USER}"
mkdir -p /home/${NB_USER};
head -n -1 /etc/passwd > /tmp/passwd;
cp /etc/passwd /tmp/passwd;
sed -i '/jovyan:x:1000:100/d' /tmp/passwd
echo "creating passwd entry ${NB_USER}:x:$(id -u):$(id -g):,,,:/home/${NB_USER}:/bin/bash";
echo "${NB_USER}:x:$(id -u):$(id -g):,,,:/home/${NB_USER}:/bin/bash" >> /tmp/passwd;
cat /tmp/passwd > /etc/passwd;
Expand Down
4 changes: 2 additions & 2 deletions packages/jupyter_command_launcher/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
python_requires=">=3.8",
include_package_data=True,
#package_data={"jupyter_vscodeserver_proxy": ["icons/*"]},
entry_points={"jupyter_serverproxy_servers": ["start_sidecar = jupyter_command_launcher:start"],
"jupyter_serverproxy_servers": ["stop_sidecar = jupyter_command_launcher:stop"] }
entry_points={"jupyter_serverproxy_servers": ["sidecar_controle = jupyter_command_launcher:start"],
}
)

setup_args['install_requires'] = install_requires = []
Expand Down
45 changes: 34 additions & 11 deletions packages/py_cmd_launcher_gui/py_cmd_launcher_gui/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
#env for apps:
#export JUPYTER_COMMAND_LAUNCHER_APPS='{"app1": "http://external-api-url/app1", "app2": "http://external-api-url/app2"}'

def create_app(API_URL):
def create_app():
app = Flask(__name__)
if API_URL is None:
apps_config = os.getenv('JUPYTER_COMMAND_LAUNCHER_APPS', '{"default": "http://localhost:4990"}')
apps = json.loads(apps_config)
else:
apps = {"default": "http://localhost:4990"}
apps_config = os.getenv('JUPYTER_COMMAND_LAUNCHER_APPS', "{}")
apps = json.loads(apps_config)

# HTML template for the UI
HTML_TEMPLATE = '''
<!DOCTYPE html>
Expand All @@ -43,6 +41,30 @@ def create_app(API_URL):
<script>
const appNames = {{ app_names|tojson }};
// Function to create control buttons dynamically
function createButtons() {
const controlsDiv = document.getElementById('controls');
appNames.forEach(app => {
const startButton = document.createElement('button');
startButton.innerText = `Start ${app}`;
startButton.onclick = () => sendRequest(`/start/${app}`);
const stopButton = document.createElement('button');
stopButton.innerText = `Stop ${app}`;
stopButton.onclick = () => sendRequest(`/stop/${app}`);
// Append the buttons to the controls div
controlsDiv.appendChild(startButton);
controlsDiv.appendChild(stopButton);
controlsDiv.appendChild(document.createElement('br')); // Line break for clarity
// Add a status placeholder for each app
const statusDiv = document.createElement('div');
statusDiv.id = app;
controlsDiv.appendChild(statusDiv);
});
}
function sendRequest(endpoint) {
fetch(endpoint)
.then(response => {
Expand All @@ -52,10 +74,10 @@ def create_app(API_URL):
return response.json();
})
.then(data => {
document.getElementById('response').innerText = data.message;
document.getElementById('status').innerText = data.message;
})
.catch(error => {
document.getElementById('response').innerText = 'Error: ' + error.message;
document.getElementById('status').innerText = 'Error: ' + error.message;
});
}
Expand All @@ -80,7 +102,8 @@ def create_app(API_URL):
// Automatically refresh status every 10 seconds
setInterval(getStatus, 10000);
// Initial status fetch
getStatus();
createButtons(); // Create buttons dynamically
getStatus(); // Initial status fetch
</script>
</body>
</html>
Expand Down Expand Up @@ -141,12 +164,12 @@ def main():
help='Host (default is 127.0.0.1)')
parser.add_argument('--port', type=int, default=4900,
help='Port (default is 4900)')
parser.add_argument(name_or_flags='--server', help="api server to talk to (default is None => config via json env JUPYTER_COMMAND_LAUNCHER_APPS)", default=None)
#parser.add_argument(name_or_flags='--server', help="api server to talk to (default is None => config via json env JUPYTER_COMMAND_LAUNCHER_APPS)", default=None)
parser.add_argument(name_or_flags='--debug', help="debug", default=False, type=bool)

args = parser.parse_args()

app = create_app(args.server)
app = create_app()
app.run(host=args.host, port=args.port,debug=args.debug)

except Exception as e:
Expand Down

0 comments on commit 0a291da

Please sign in to comment.