Accessing the TM351 VCE environment from a VS Code editor - innovationOUtside/tm351vm-binder GitHub Wiki
We can run simple notebooks within the VS Code editor on host against the TM351 Python environment using the VS Code Python extension (see also the Jupyter support documentation for that extension).
Note that this is NOT the recommended way of running notebooks, and not all notebooks may run successfully in VS Code, particular where we make use of widgets of notebook extensions, but we are interested in what the experience of using TM351 notebooks via VS Code is like...
If the default TM351 virtual computing environment is running, from the command palette, search for Python: specify local or remote Jupyter server for connections, then select Existing (specify the URI of an existing server) and use the URL: http://localhost:35180/?token=letmein
You should then be able to run the notebooks in VS Code. (See also these early notes on running course containers using Digital Ocean remote servers.)
We could probably provide a default TM351.code-workspace
file to help set up the required connection string. For example:
{
"folders": [
{
"path": "."
}
],
"settings": {
"python.dataScience.jupyterServerURI": "http://localhost:35180/?token=letmein"
}
}
See also:
Accessing the PostgreSQL server from VS Code host
We access the PostgreSQL server from VS Code on host using the VS Code postgres extension if we relax the security settings on the Postgres server.
The server config file can be found via: find $CONDA_DIR -name "postgresql.conf"
To make the postgres server wide open (for initial testing, for example), we can configure it to accept requests from anywhere by adding the following to /srv/conda/srv/pgsql/postgresql.conf
. This means changing the default listen_addresses='localhost'
(and uncommenting it by removing the leading #
if it is commented out) as follows:
# nano $CONDA_DIR/srv/pgsql/postgresql.conf
listen_addresses='*' #Allow all incoming addresses
We also need to add a line to the pg_hba.conf
file:
# nano $CONDA_DIR/srv/pgsql/pg_hba.conf
host all all 0.0.0.0/0 md5
The following may do the above from Jupyter terminal [untested]:
echo "listen_addresses='*'" >> $CONDA_DIR/srv/pgsql/postgresql.conf
echo "host all all 0.0.0.0/0 md5" >> $CONDA_DIR/srv/pgsql/pg_hba.conf
Or maybe (not sure about the quotes! Again - this is untested...) something like:
find $CONDA_DIR -name "postgresql.conf" -exec sh -c "echo listen_addresses='*' >> {}" \;
and
find $CONDA_DIR -name "postgresql.conf" -exec sh -c "echo 'host all all 0.0.0.0/0 md5' >> {}" \;
After editing the server config files, the docker container will need restarting: docker restart tm351VCE
. (Actually, it needs running with an additional port, eg -p 35181:5432
in the original run command, which will mean killing and removing the containing and issuing a new docker run
command with the additional port specified, unless we can attach additional ports to the running container or via the restart?).
Using credentials localhost
, 35181
, user tm351admin
and password tm351admin
then gives us sight into the database from VS Code:
We should probably look at finding a way to easily tighten security back up to only allow requests coming in from the host IP address, or the student's local network if they are running the TM351VCE as a network server on their home network.
TO DO
- a
sed
command that will update current/default rules to allow for external access* - should this be the default setting for the server anyway?
- is there a docker command that will expose the additional port on the already running container?
Accessing the MongoDB database from VS Code on host
Connections can be made onto the MongoDB server running inside the TM351VCE container by making a couple of config changes to the Mongo server configuration:
- the container needs to be run with an additional port mapping, such as
-p 35182:27017
- the
${MONGODB_PATH}/bin/mongod
command in the/home/jovyan/.binder/start
file needs updating to include the--bind_ip_all
switch (open the file to edit it usingnano /home.jovyan/.binder/start
from the TM351VCE terminal); the container then needs restarting by runningdocker restart tm351vce
in theTM351VCE
directory on host.
After editing the server config files, the docker container will need restarting by running the following command on host: docker restart tm351VCE
. (Actually, it needs running with an additional port, eg -p 35182:27017
in the original run command, which will mean killing and removing the containing and issuing a new docker run
command with the additional port specified, unless we can attach additional ports to the running container or via the restart?).
Using the VS Code MongoDB extension, create a connection to localhost
port 35182
.
Run a query by clicking on a collection, hitting the magnifying glass / search icon, and running the the query:
TO DO
- add some authentication to the
mongod
startup? This would then require updated connection strings in the notebooks. - a
sed
command that will update current/default rules to allow for external access* - should this be the default setting for the server anyway?
- is there a docker command that will expose the additional port on the already running container?
Controlling the TM351VCE using the VS Code Docker Extension
The VS Code docker extension might provide a handy way of controlling the TM351 VCE.
For example, we can access the command line inside the container using the extension:
### TO DO
- can we also run, start and stop the container using the extension, either directly, or using
docker-compose
?