This repository provides containerized applications and microservices for the Information Systems and Databases Course @ Instituto Superior Técnico.
This guide helps setting up a workspace environment for completing lab classes, which includes a database management system and other auxiliary services.
Services provided include:
- PostgreSQL Open Source database management system
- pgAdmin4 Open Source administration and development platform for PostgreSQL
- bdist/notebook Jupyter Notebook Databases Stack
Docker Desktop is an application for MacOS, Linux, and Windows machines for the building and sharing of containerized applications and microservices.
Install Docker Desktop on Mac, Windows or Linux
Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
Install Git on Mac Windows or Linux
-
Open Terminal.
-
Change the current working directory to the location where you want the cloned directory.
-
Run the following command to create your local clone
git clone https://github.com/bdist/bdist-workspace.git
-
Change the current working directory to the location of the cloned directory.
cd bdist-workspace/
-
From the cloned directory, start up
bdist-workspace
by runningdocker compose up
Note: The services are attached to this Terminal, so the logs for all the services provided will be printed on its window. To shutdown safely you will need to issue CTRL+C in the Terminal window and wait until all the services stop gracefuly.
Using the Jupyter Notebook (Docs)
The Jupyter Notebook service runs on the port 9999
. Token authentication is enabled.
-
You need to find your Authentication Token to login every time the
bdist-workspace
is launched (e.g., after a reboot) -
Find the section of the logs towards the bottom of the Terminal window that look like this excerpt:
bdist-workspace-notebook-1 | Or copy and paste one of these URLs: bdist-workspace-notebook-1 | http://7fd8c38e99bd:9999/lab?token=f83ee982668ebe66bee2dbeb5875d14131a1d118d1e0fa12 bdist-workspace-notebook-1 | http://127.0.0.1:9999/lab?token=f83ee982668ebe66bee2dbeb5875d14131a1d118d1e0fa12
Note: You can also view the logs for the
bdist-workspace-notebook-1
in the Containers tab in the Docker Desktop application. -
Follow the link printed last with host
127.0.0.1
. The authentication token is embedded in the URL.
pgAdmin is the most popular and feature rich Open Source administration and development platform for PostgreSQL, the most advanced Open Source database in the world.
-
Login here.
Username: [email protected] Password: pgadmin
-
Click the button
Add New Server
. -
Set the Name in the General tab to
postgres
. -
Set the Hostname in the Connection tab to
postgres
. -
Use the same username and password you would provide
psql
.Username: postgres Password: postgres
-
Make sure the
app/
directory is right next to thebdist-workspace/
directory. If needed, move theapp/
directory out ofbdist-workspace/
.$ ls app/ bdist-workspace/
-
The
docker-compose..app.yml
file contains the instructions to launch the app. Relaunch the workspace with the following command to use it:docker compose -f docker-compose..app.yml up
Note: Please run the instructions in the
How do I update my workspace?
section if this file is does not exist. -
Check if the app is running and open ping.
-
Do you get an API-like HTTP JSON-formatted response like this?
{ "message": "pong!" }
-
Try modifying the message in
../app/app.py
while it is running. -
In the logs, check if an automatic reload of the Flask Web App is triggered when you save your changes.
You need to delete the data volume used by postgres and recreate it.
-
Open a new Terminal.
-
Run this to shutdown the containers and remove all associated volumes.
docker compose down -v
-
Run the steps in the following section to update
bdist-workspace
.
-
Firstly, from the project directory run
git pull
This updates
bdist-workspace
to the latest version. -
Secondly, from the project directory run
docker compose pull
This updates container images to the latest version.
-
Lastly, from the project directory run
docker compose up --build --force-recreate --remove-orphans
This starts up the
bdist-workspace
and cleans up unused images.
You need to set the owner of every directory under /home/jovyan/
to the user jovyan
and groups users
. This is the default username and group for the user in the notebook container.
You only need to run this once.
-
Open Terminal.
-
Run this to reset the permissions for files and folders under
home/jovyan/
.chown -R jovyan:users /home/jovyan/
If this still does not solve the issue with permissions then follow this recipe:
-
Open Terminal.
-
Run this do access the notebook container as administrator (root):
docker compose exec -e GRANT_SUDO=yes --user root notebook /bin/bash
-
Run this to reset the permissions for files and folders under
home/jovyan/
.chown -R jovyan:users /home/jovyan/
(psycopg.errors.UndefinedTable) relation "depositor" does not exist
If the exception thrown looks like the one in the example, then follow this checklist:
-
Is the database you are connected to the correct one?
%sql postgresql://bank:bank@postgres/**bank**
-
Is the database empty?
Connect to the target database on the Terminal via
psql
and run the command\d
.$ psql -h postgres -U bank Password for user bank: psql (17.0 (Ubuntu 17.0-1.pgdg24.04+1)) Type "help" for help. postgres bank@bank=>\d List of relations Schema | Name | Type | Owner --------+-----------+-------+------- public | account | table | bank public | borrower | table | bank public | branch | table | bank public | customer | table | bank public | depositor | table | bank public | loan | table | bank (6 rows)
Note: Alternatively, get the list of relations inside the notebook. Run this on a new notebook cell:
%sqlcmd tables
Please use GitHub Issues to report any issues you might have with bdist-workspace
.
Flavio Martins