Ensure the Docker engine is installed on your system with version 18.06.0 or higher.
You can download and install the Docker engine from the official Docker website.
Note
- Especially on Linux, make sure your user has the required permissions to interact with the Docker daemon.
- If you are unable to do this, either append
sudo
in front of eachdocker
command or switch to root usingsudo -s
.
Ensure that Docker Compose is installed on your system with version 1.28.0 or higher.
You can download and install Docker Compose from the official Docker website.
Ensure that PostgreSQL is installed on your system with version 13 or higher.
You can download PostgreSQL using the following command based on your operating system:
macOS:
- Install Homebrew (if not already installed).
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Note
- Visit Homebrew's official website here for more information.
- You will require administrative priviledges during the installation process.
brew install postgresql
Note
- You may have to export the PostgreSQL
bin
directory to use the PostgreSQL commands system wide. - First, find out what shell you are currently using with:
echo $SHELL
- Open your shell config file (prefixed with a
.
) with an appropriate text editor (e.g.nano
,vim
,nvim
, etc.).
nano <SHELL_CONFIG_FILE>
- Add the following line:
export PATH="/usr/local/opt/postgresql@16/bin:$PATH"
- Update your shell based on the config file changes.
source <SHELL_CONFIG_FILE>
Linux:
- Debian/Ubuntu:
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib
- CentOS/RHEL:
sudo yum check-update
sudo yum install ftp
- Fedora:
sudo dnf check-update
sudo dnf install ftp
- Arch:
sudo pacman -Sy
sudo pacman -S ftp
Windows:
You can download the PostgreSQL installer from the official website here and follow the installation instructions.
The PostgreSQL service running on the Docker Container uses Port 5433
on your host system. Ensure that this port is free and is not running any conflicting services or has any firewall rules concerning them.
- Clone the repository to your local machine.
git clone https://github.com/iArcanic/im-cw2
- Navigate to the project's directory.
cd im-cw2
- Build and run all Docker containers.
docker-compose up
Note
With Docker Compose, you can also optionally use the following:
- If you want to build the images each time (or changed a Dockerfile), use:
docker-compose up --build
- If you want to run all the services in the background, use:
docker-compose up -d
After, you can optionally view Docker images, status of containers, and interact with running containers using the Docker Desktop application.
- Use the PostgreSQL CLI to connect to the Docker container.
psql -h localhost -p 5433 -U postgres
Note
- The default PostgreSQL user is
postgres
and its password ischangeme
. - The default port is
5433
. - These values can be found in the
.env
file and can be changed if necessary.
- Connect to the database.
\c student_db
Note
- The default database name is
student_db
. - These values can be found in the
.env
file and can be changed if necessary.
- Experiment with connecting to the database as different users.
\c student_db <USERNAME>
For example:
\c student_db admin_user
Note
The credentials for these users are found in sql/06_create_users.sql
.
Important
When referencing the tables, you must use the schema name student_info
before the table name.
- Experiment with Role-Based Access Control (RBAC).
For example, as admin_user
(assuming that you have connected as admin_user
beforehand):
SELECT date_of_birth FROM student_info.students;
You should see the following:
ERROR: permission denied for schema student_info
Note
The permissions for these roles are found in sql/05_grant_permissions.sql
.
- Backup and export the database
Navigate to the scripts folder.
cd scripts
Make the backup.sh
script an executable.
chmod +x backup.sh
Run the backup.sh
script.
./backup.sh
Navigate to your home folder and you should see the backup folder (student_db-backups
) with a database dump .sql
file (timestamped accordingly).
Note
- You will be prompted to enter a password for this script.
- This is the password of the user that the script is using.
- In this case, it is the default user
postgres
with its passwordchangeme
. - These values can be found in the
.env
file and can be changed if necessary.
- Quit the PostgreSQL connection to the Docker container after usage.
\q
- Destroy the Docker container after usage.
docker-compose down