These instructions are for installing and running the application in either Development Mode or in Production Mode.
Prior to starting, please install docker for your operating system if you have not already as both installations require the use of docker. If these methods don't work on your system, try following these older instructions which provide a different set instructions which may work on your machine.
This installation method is for developers who wish to see their website and API changes live as they develop.
-
Install NodeJS (LTS) and autopep8 locally on your computer. These two will help autoformat your code when you commit.
-
Clone this repository and enter it by running:
git clone [email protected]:AlbertaSat/ex2_ground_station_website.git cd ex2_ground_station_website
-
Clone this repository's submodules (ex2_ground_station_software/ and libcsp/) by running:
git submodule update --init --recursive
-
Create a copy of
keys-example.sh
and name itkeys.sh
cp keys-example.sh keys.sh
Feel free to change any of the values inside
keys.sh
but their default values works fine. Note thatSLACK_TOKEN
is used inautomation.py
as a way of notifying users through Slack when a satellite passover occurs. Information on using the Slack API can be found here. -
Start the development environment by running:
docker-compose up
It may take a while for the first time but subsequent runs will be much quicker.
-
Visit http://localhost:8000 to view the webpage
Note that on Safari and iOS, timestamps render improperly so it is recommended that you use a Chromium browser (Chrome, Edge, etc.) or Firefox.
Whenever you make a change to the website code (inside
groundstation/static/js
), you would need to hard refresh the page withCtrl+Shift+R
on Windows/Linux orCommand+Shift+R
on Mac to empty the cache.
The website uses a PostgreSQL database to store its data. To view all the tables and their entries, you can either use a command line tool like psql or a GUI tool like DBeaver.
With psql, you can connect to the database by runnning the following command in a separate terminal window:
psql postgres://postgres:postgres@localhost:5432/ex2_gs
With DBeaver, create a new PostgreSQL database connection and set these fields to:
Host: localhost
Database: ex2_gs
Username: postgres
Password: postgres
The website's comm.py script communicates with the database and with ex2_ground_station_software in order to communicate with the satellite. In order to recieve command responses:
-
Open a seperate terminal inside the website container by running:
docker exec -it ex2_ground_station_website_web_1 bash
-
Build libcsp by running
./build_libcsp.sh
. This only needs to be done whenever the libcsp submodule or the script itself updated. -
Run
comm.py
with the appropriate command-line arguments according to ex2_ground_station_softwareIf you want to test responses without being connected to an OBC, run:
python3 comm.py -I dummy
If you want to use GNURadio with the satellite, first clone ex2_uhf_software and built it:
# NOTE: This is a PRIVATE repository accesible only to AlbertaSAT members git clone [email protected]:AlbertaSat/ex2_uhf_software.git cd ex2_uhf_software ./build.sh
then run comm.py OUTSIDE the Docker container and on the host PC that is running GNURadio by running the following:
python3 comm.py -I sdr -u
-
You will then be prompted with:
Would like to communicate with the satellite simulator (if not, the program will attempt to communicate with the satellite) [Y/n]:
Respond with 'n' and let the script run in the background.
These instructions assume that the production server is running Ubuntu 20.04 with docker and docker-compose installed. Follow these instructions if you want to deploy the website on a web server.
-
Clone this repository and enter it:
git clone [email protected]:AlbertaSat/ex2_ground_station_website.git cd ex2_ground_station_website
-
Clone this repository's submodules (ex2_ground_station_software/ and libcsp/) by running:
git submodule update --init --recursive
-
Create a copy of
keys-example.sh
and name itkeys.sh
cp keys-example.sh keys.sh
Feel free to change any of the values inside
keys.sh
, particularlyPOSTGRES_USER
andPOSTGRES_PASSWORD
which act as the credentials for the database andSECRET_KEY
which is used for authentication. These three environment variables should be kept secure.Note that
SLACK_TOKEN
is used inautomation.py
as a way of notifying users through Slack when a satellite passover occurs. Information on using the Slack API can be found here. -
Set the system's environment variables by running:
source ./env.sh source ./keys.sh
-
Inside the repo, create a folder called
db_backups
and give initialize its permissions as followed:mkdir db_backups sudo chown -R 999:999 db_backups/
-
Create a Python virtual environment and install the website's Python dependencies by running:
python3 -m venv .venv # Creates python virtual environment in .venv/ source .venv/bin/activate # Activates virtual environment pip install -r requirements.txt # Installs dependencies
-
Start the production environment by running:
sudo -E docker-compose -f docker-compose.prod.yml up -d
To view the logs of the production server, run the following in a separate terminal window:
sudo docker-compose logs -f -t
-
Ensure that port 80 is port-forwarded on the web server and you can now access the website by visiting http://localhost if using a browser on the webserver or by visiting
http://<server ip here>
on a different device
When there is a new update to master, follow these instructions to update the server:
-
Shutdown the server by running:
sudo docker-compose down --remove-orphans
-
Pull the latest changes with
git pull
-
Reopen the server by running:
source ./env.sh source ./keys.sh sudo -E docker-compose -f docker-compose.prod.yml up -d
-
If there were any changes to the database schema (ie. new table, column, etc.) open a bash terminal inside the website docker container with:
sudo docker exec -it ex2_ground_station_website_web_1 bash
Then run the following commands to update the database schema without deleting existing rows:
flask db migrate flask db upgrade
The website uses a PostgreSQL database to store its data. To view all the tables and their entries, you can either use a command line tool like psql or a GUI tool like DBeaver.
For security purposes (for now), these commands only work when ran on the server computer itself locally.
With psql, you can connect to the database by runnning the following command in a separate terminal window:
psql -U <POSTGRES_USER> -h localhost -d ex2_gs -W
which will then prompts you for the database password.
With DBeaver, create a new PostgreSQL database connection and set these fields to:
Host: localhost
Database: ex2_gs
Username: <POSTGRES_USER>
Password: <POSTGRES_PASSWORD>
A database backup is scheduled to be created daily and backups can be found in the db_backups/
folder.
To restore a backup, follow these steps in the server's terminal:
-
Open a bash terminal inside the website container by running:
sudo docker exec -it ex2_ground_station_webste_web_1 bash
-
Run
python3 manage.py recreate_db
WARNING: This will completely wipe the database so that a backup can be restored. Please run it with caution!
-
Restore the a backup by running:
zcat db_backups/<path to backup file> | psql -U <POSTGRES_USER> -h db -d ex2_gs -W
which will then prompt you for the database password.
These commands should be the same regardless of which method of installation you're using.
-
python3 manage.py recreate_db
- delete the database and create a new empty one. -
python3 manage.py seed_db
- seed the database with sample data. -
cd groundstation/static && npm run build
- build the React JS frontend. -
source ./env.sh
- set the environment variables for Flask's config. Without it you'll get weird SQLAlchemy errors. -
source ./run_comm.sh
- start the comm module. This will enable the app to send data to whatever socket is specified incomm.py
. For example, ex2_services. -
source ./automate.sh
- run the automation module. It will automatically send whatever commands are insideautomation.txt
to the socket. (Note: the commands first have to be specified inmanage.py
, which the app refers to as "telecommands"). Not necessary for testing. -
flask run
- run the app. -
python3 manage.py test
- run the unit tests. -
python3 manage.py test frontend_test
- run the GUI frontend tests with Selenium. Please note that you will need to install the appropriate driver here. -
python3 manage.py test groundstation_test
- run ground station integration testing. Please note that you will need to have built libcsp in this repo's submodule and have set the appropriate env variables withsource ./env.sh