This page will help you to self hosted our project
📝 Overview
Our application is open source and you can self-host it. Self-hosting means that you can run the application, including the database, on your own server. But you have to manage the server yourself. And if anything goes wrong, you're the one who has to deal with it. We don't have any responsibility for anything that might happen to your data or your application.
⚙️Environment Setup
- Install Git if you don't have it already. You can find the installation instructions here: https://git-scm.com/book/en/v2/Getting-Started-Installing-Git
- Install Docker and Docker Compose on your server. https://docs.docker.com/engine/install/
- Clone our repository. https://github.com/drithh/e-commerce-website
- Change Directory to the project folder.
cd e-commerce-website - Create a .env file in the root directory of the project. You can copy the content of the .env.example file and paste it into the .env file.
cp .env.example .env - Run
docker-compose up -dto start the application. - Run
make migrate-upto run the database migrations. - Run
make seedto seed the database with some data.
That's it. You can now access the application on http://localhost:8000/ or http://your-server.com:8000/ if you are running the application on a server. if you want to access the application on a different port, you can change the port in docker-compose.yml file.
📕Environment Variable
We will walk you trough the environment variables in this section. make sure to read it carefully.
Project Settings:
PROJECT_NAMEis the name of the project. It is used in OpenAPI documentation.VERSIONis the version of the project. It is used in OpenAPI documentation.
Core Settings:
POSTGRES_USERis the username of the postgres database.POSTGRES_PASSWORDis the password of the postgres database.POSTGRES_DBis the name of the postgres database.DATABASE_URLis the url of the postgres database. It is used by the application (sqlalchemy) to connect to the database.TEST_DATABASE_URLis the url of the postgres database. It is used by the application (sqlalchemy) to connect to the database when running tests.SECRET_KEYis the secret key of the application. It is used to sign JWT tokens.BUCKET_NAMEis the name of the cloud storage service to use.TEST_BUCKET_NAMEis the name of the cloud storage service to use for testing.
Mail Settings:
if you are using google mail (gmail), you can see this link https://support.google.com/mail/answer/185833?hl=en to get the credentials
-
MAIL_USERNAMEis the username of the email account that is used to send emails. -
MAIL_PASSWORDis the password of the email account that is used to send emails. -
MAIL_FROMis the email address of the email account that is used to send emails. -
MAIL_PORTis the port of the email account that is used to send emails. -
MAIL_SERVERis the server of the email account that is used to send emails. -
MAIL_STARTTLSis meant to be a boolean value. It is used to determine whether to start TLS or not. -
MAIL_SSL_TLSis meant to be a boolean value. It is used to determine whether to use SSL or TLS. -
USE_CREDENTIALSis meant to be a boolean value. It is used to determine whether to use credentials or not. -
VALIDATE_CERTSis meant to be a boolean value. It is used to determine whether to validate certificates or not.
GCP Settings:
CLOUD_STORAGEis the link to the cloud storage. It is used to retrieve images from the cloud storage or cdn server.
GCP CREDENTIAL
You can find the instructions to create a service account here: https://cloud.google.com/iam/docs/creating-managing-service-accounts
Just copy the content of the json file and paste it one by one in the .env file with exactly the same name. For example, the content of the json file should be like this:
{
"type": "service_account",
"project_id": "your-project-id",
...
}
Then you should copy the content of the json file and paste it in the .env file like this:
GCP_TYPE=service_account
GCP_PROJECT_ID=your-project-id
...
Twitter Settings:
Twitter API needed for shower thoughts 'useless thoughts' . its too make user don't get bored while waiting for the server to respond. its not a must to have twitter api. you can remove it from the code if you want and/or use reddit api instead which doesn't need any api key.
You can find the instructions to create a twitter app here: https://developer.twitter.com/en/docs/twitter-api/getting-started/getting-access-to-the-twitter-api
TWITTER_APIis the token of the twitter api.
Certbot Settings:
To automatically create and renew SSL certificates, it is used for production environment.
CERTBOT_EMAILis the email address of the email account that is used to send emails.CERTBOT_DOMAINis the domain of the website.
Backend Settings:
BACKEND_CORS_ORIGINSis the list of origins that are allowed to access the backend. to allow all origins, you can use*.
Frontend Settings:
REACT_APP_BACKEND_URLis the url of the backend. It is used by the frontend to connect to the backend.
🛠️Local Development
The backend setup of docker-compose is set to automatically reload the app whenever code is updated. This is done by using the uvicorn --reload flag. This is not recommended for production.
To develop the frontend, you can run npm start in the frontend directory. This will start a development server that will automatically reload whenever you make changes to the frontend code.
cd frontend
npm install # only the first time
npm start
I'm running out of emoji ideas so from this point onwards, i'll just throw some goofy ones for the rest of documentation
🙉 Database Migrations
Useful commands for database migrations:
# Auto generate a revision
docker-compose exec backend alembic revision --autogenerate -m 'message'
# Apply latest changes
docker-compose exec backend alembic upgrade head
# Run database migration
make migrate-up
# Run Seeder
make seed
# Dearchive Soft Deleted Field
make dearchive
# Drop all tables
make drop-tables
💀 Production
To run the app in production, you have to include docker-compose.prod.yml file, when you run docker-compose up. This file is set up to run the app in a production environment with nginx as a reverse proxy.
Embrace yourself when configuring nginx and ssl certificates. it's a pain, huge pain. Tutorial you may ask? No, you're on your own for this one, you need to feel what it's like to be in pain. Good luck mate. 💪
🎉🎉Yay the documentation is finally done, thank you for reading this far. I hope you enjoyed reading this documentation as much as i enjoyed writing it (not really, it's more painful than configuring nginx and ssl certificates but i'm glad it's finally done).🎉🎉
yup
