This is a website for the EMWI Auto Moto company.
Set the required environment variables for the program to run. If you have access to a .env file, run the following command to load the vars before running the program.
export $(grep -v '^#' .env | xargs)
Navigate to the root of the project in the /MotorcycleStore
directory and run the following command:
uvicorn backend.app:app --host 0.0.0.0 --port 8080 --reload
By default, the backend target for the website will be the localhost environment.
If instead you wish to point the environment at the prod backend, modify
the /frontend/.env.development
file so that VITE_APP_DOMAIN
points to the prod endpoint as such:
VITE_APP_DOMAIN='https://emwiautomotoapi.sebtota.com'
Navigate to the /MotorcycleStore/frontend
directory and run the following command:
npm run dev
- Install Postgres
- Access the postgres shell
sudo -u postgres psql
- Update the postgres password
ALTER USER postgres PASSWORD 'newPassword';
- Create the EmwiAutoMoto user
CREATE USER emwiautomotoreadwrite WITH PASSWORD 'password';
- Create the EmwiAutoMoto database and grant access to the EmwiAutoMoto user
CREATE DATABASE emwiautomoto OWNER postgres;
GRANT ALL PRIVILEGES ON DATABASE emwiautomoto TO emwiautomotoreadwrite;
- Exit the postgres shell and user
\q
exit
- Update the
pg_hba.conf
file to allow access from all ips
sudo nano /etc/postgresql/12/main/pg_hba.conf
- Create a file in
/etc/emwiautomoto.env
to store the application environment variables.
File content:
API_CREDENTIALS_GENERATOR_SECRET_KEY=secretKeyOne
API_CREDENTIALS_REFRESH_TOKEN_SECRET_KEY=secretKeyTwo
DATABASE_HOST=host
DATABASE_USER=user
DATABASE_PASSWORD=password
DATABASE=database
BUCKET_STORAGE_BUCKET_NAME=bucketname
BUCKET_STORAGE_OBJECT_BASE_URL=objUrl
BUCKET_STORAGE_ENDPOINT_URL=endpointUrl
BUCKET_STORAGE_ACCESS_KEY=accessKey
BUCKET_STORAGE_SECRET_ACCESS_KEY=secretAccessKey
- Create the following directories and empty files:
/root/prod_logs/output/output.log
/root/prod_logs/error/error.log
- Download SSL Certs and place them in:
/root/cf_certs/origin_cert.pem
/root/cf_certs/private_key.key
- Create a file:
/etc/systemd/system/emwiautomoto.service
[Unit]
Description=EmwiAutoMoto
After=network.target
[Service]
EnvironmentFile=/etc/emwiautomoto.env
ExecStart=backend/.venv/bin/python3 -m uvicorn backend.app:app --host 0.0.0.0 --port 443 --ssl-keyfile=/root/cf_certs/private_key.key --ssl-certfile=/root/cf_certs/origin_cert.pem
WorkingDirectory=/root/MotorcycleStore
User=root
Restart=always
StandardOutput=file:/root/prod_logs/output/output.log
StandardError=file:/root/prod_logs/error/error.log
[Install]
WantedBy=multi-user.target
If you add this file, OR make any changes to this file, you must run the following command:
sudo systemctl daemon-reload
sudo systemctl restart emwiautomoto
All frontend deployments are automatically handled by GitHub Action, and deploy directly to Cloudflare.
- SSH into the server
cd MotorcycleStore
git pull
source backend/.venv/bin/activate
pip install -r backend/requirements.txt
sudo systemctl restart emwiautomoto.service
Use the command:
sudo journalctl -u emwiautomoto -r
to get log files from the service in reverse, meaning the most recent logs will be first.
Oracle by default blocks all ports on its hosts apart from 22. This means that even if you have the port open on the network configuration page, you still need to open the port within the host itself.
Sometimes, the config can get reset on reboot. Run the following commands to fix the issue:
sudo iptables -A INPUT -p tcp --dport 443 -j ACCEPT
sudo iptables -I INPUT -j ACCEPT
sudo su
iptables-save > /etc/iptables/rules.v4
exit
All database backups are done on the postgres
user. This user should have read access to the database being backed up.
After a successful backup, a success ping will be sent to https://www.cronitor.io to manage alerting of a failed backup job.
To edit the crontab responsible for running these backups, run the following command:
sudo crontab -u postgres -e
In the case that you must restore the database from a backup file, follow the steps below:
- Download the database backup file locally on the host
- Connect to the host on which the database resides on
- Create a new Database called
EmwiAutoMoto
- Run the following command:
psql -U postgres -d EmwiAutoMoto -f ./YYYY-MM-DD_EmwiAutoMoto_YYYY-MM-DD_HH-MM-SS.sql