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 -d
to start the application. - Run
make migrate-up
to run the database migrations. - Run
make seed
to 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_NAME
is the name of the project. It is used in OpenAPI documentation.VERSION
is the version of the project. It is used in OpenAPI documentation.
Core Settings:
POSTGRES_USER
is the username of the postgres database.POSTGRES_PASSWORD
is the password of the postgres database.POSTGRES_DB
is the name of the postgres database.DATABASE_URL
is the url of the postgres database. It is used by the application (sqlalchemy) to connect to the database.TEST_DATABASE_URL
is the url of the postgres database. It is used by the application (sqlalchemy) to connect to the database when running tests.SECRET_KEY
is the secret key of the application. It is used to sign JWT tokens.BUCKET_NAME
is the name of the cloud storage service to use.TEST_BUCKET_NAME
is 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_USERNAME
is the username of the email account that is used to send emails. -
MAIL_PASSWORD
is the password of the email account that is used to send emails. -
MAIL_FROM
is the email address of the email account that is used to send emails. -
MAIL_PORT
is the port of the email account that is used to send emails. -
MAIL_SERVER
is the server of the email account that is used to send emails. -
MAIL_STARTTLS
is meant to be a boolean value. It is used to determine whether to start TLS or not. -
MAIL_SSL_TLS
is meant to be a boolean value. It is used to determine whether to use SSL or TLS. -
USE_CREDENTIALS
is meant to be a boolean value. It is used to determine whether to use credentials or not. -
VALIDATE_CERTS
is meant to be a boolean value. It is used to determine whether to validate certificates or not.
GCP Settings:
CLOUD_STORAGE
is 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_API
is the token of the twitter api.
Certbot Settings:
To automatically create and renew SSL certificates, it is used for production environment.
CERTBOT_EMAIL
is the email address of the email account that is used to send emails.CERTBOT_DOMAIN
is the domain of the website.
Backend Settings:
BACKEND_CORS_ORIGINS
is the list of origins that are allowed to access the backend. to allow all origins, you can use*
.
Frontend Settings:
REACT_APP_BACKEND_URL
is 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