Skip to content

Latest commit

 

History

History
164 lines (131 loc) · 3.83 KB

SETUP.md

File metadata and controls

164 lines (131 loc) · 3.83 KB

Setting up the Database

Install dbdocs
# clean cache and update to the latest version
sudo npm cache clean -f
sudo npm update -g npm

# install dbdocs
sudo npm install -g dbdocs
Install dbml2sql
# install dbml to sql cli tool
npm install -g @dbml/cli
Install postgresql
# Add repository keys and gpg keys
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -

# update apt list
sudo apt-get update

# install postgresql
sudo apt-get -y install postgresql postgresql-contrib

# Add working environment variables to user profile
echo -c 'export LC_ALL="en_US.UTF-8"' | sudo tee -a ~/.profile
echo -c 'export PGHOST=localhost' | sudo tee -a ~/.profile
Creating a single dbml file
# move to the database directory
cd backend/database

# Concatenate all files into a single file
# validate and build the project
cat users.dbml vault.dbml search.dbml > learn_db_dev.dbml &&\
dbdocs build learn_db_dev.dbml
Creating a sqldump from dbml file
# create a sql dump from the dbml file
dbml2sql learn_db_dev.dbml -o learn_db_dev.sql

Setting up the Backend

# Add working environment variables to user profile
echo "source /vagrant/GumGumLearn/DEV_ENV.sh" | sudo tee -a ~/.profile
# sometimes you may need to run this twice if you get an error

# you may also need to make sure '/etc/postgresql/15/main/pg_hba.conf'
# has local connections to trust, like this:
# local        all      postgres     trust
cat database/setup_db_test.sql | psql postgres postgres
View the database and tables
# Enter password 'learn_dev_pwd'
psql -U learn_test -d learn_test_db -W

# To view the databases
\l

# To view all database tables
\dt+

# To exit the psql cli
\q
Testing class models
# create test user and view dictionary attributes
python3 backend/models/test_models.py

Setting up the API

# create a tmux session with the server running
tmux new-session -d 'python3 backend/main.py'

Setting up the Frontend

# install react, create template and dependencies from boilerplate
npx create-react-app my-app

Setting up Docker

Creating requirements file for dependencies
python3 -m pip freeze > requirements.txt
Creating a docker volume
sudo docker volume create postgres_data # database data files
sudo docker volume create postgres_config # database configuration files
Creating a network
sudo docker network create mynet
Building the image using Dockerfile
cd frontend
sudo docker build -f Dockerfile . --tag learn-frontend:latest # frontend

cd ../backend
sudo docker build -f Dockerfile . --tag learn-backend:latest # backend
List all created docker images
sudo docker images
Running a local container from created docker image
sudo docker run --rm -it \
	--network $NETWORK_NAME \
	--name $CONTAINER_NAME \
	--publish $HOST_PORT:$CONTAINER_PORT \
	$CONTAINER_IMAGE_NAME:$CONTAINER_IMAGE_TAG
Running a local postgresql container using postgres image
sudo docker run --rm --detach \
	--volume postgres_data:/var/lib/postgresql \
	--volume postgresql_config:/etc/postgresql \
	--network mynet \
	--name postgresdb \
	--publish 2232:5432 \
	-e POSTGRES_PASSWORD=motobay_admin_pwd \
	-e POSTGRES_USER=motobay_admin \
	-e POSTGRES_DB=motobay_prod_db \
	postgres:15.1-alpine
Creating both frontend and backend containers with docker compose file
sudo docker-compose -f docker-compose.yml up --build