Table of Contents
CodeHive aims to be a tool to help aspiring developers get fast, reliable, and contextual feedback on their questions. This is achieved by enabling seamless project integration and providing holistic context to related questions.
This is an example of how you may give instructions on setting up your project locally. To get a local copy up and running follow these simple example steps.
This is an example of how to list things you need to use the software and how to install them.
-
pip
python -m pip install --upgrade pip
-
Clone the repo
git clone https://github.com/Spark-Project-Pulse/backend.git
- Go to the Google Cloud Console, navigate to
IAM & Admin>Service Accounts, and and download the already existing json key from the service acount called Secret Accessor Service Account. Go to theKeystab and clickAdd KeythenCreate New KeythenCreate(use json format). Your key will download aspulse-random-letters-and-numbers.jsonin the root of the project. - Add a
.env.localfile to the root of the project with the following contents:
GOOGLE_CLOUD_PROJECT=google_cloud_project_id
GOOGLE_APPLICATION_CREDENTIALS=pulse-random-letters-and-numbers.json- Use the
get_secretfunction inservices/secret_manager.pyto access secrets stored in Google Secret Manager locally. The function takes the secret name as an argument and returns the secret value.
To ensure they will be available in production and consistent across all environments and between developers, secrets should be stored in Google Secret Manager. To update a secret:
- Navigate to the Google Cloud Console
- Select the project
Pulse - Navigate to
Secret Manager - Select the secret you want to update
- Click
Deleteto delete the secret - Now recreate the secret with the new value (I am aware this is kind of a pain, but I haven't researched how versions work yet)
For the frontend, there are three kinds of secrets: local, local docker, and production. When creating a new secret, make sure to add the local version by appending _LOCAL, the local docker version by append _LOCAL_DOCKER to the secret name, and the production version by appending _PRODUCTION to the secret name. Even if the secret is the same for all environments, it should be added for each environment to ensure that the secret is available in all environments. The get_secret function handles the logic of which secret to return based on the environment, so after adding the secret to Google Secret Manager, it should be accessible via the function.
- Navigate to the Google Cloud Console
- Select the project
Pulse - Navigate to
Secret Manager - Select the secret you want to update
- Click
Create Secret - Enter the secret's name and value
- Click
Create Secret
In order to run the backend locally, you must ensure that you have installed the Supabase CLI and started the database:
-
Install Supabase CLI
-
Make sure the Docker daemon is running (open Docker Desktop)
-
Start supabase db
supabase start
-
Proceed to running the backend (note that all db updates will only be saved on your machine)
-
Stop supabase when finished
supabase stop
-
Make sure the Docker daemon is running (open Docker Desktop)
-
Navigate to the backend repository
-
Use this command to build and run the backend container:
docker compose up --build
-
Navigate to
http://localhost:8000/questions/getAllto see an example of an API response
-
Make sure the Docker daemon is running (open Docker Desktop)
-
Navigate to the backend repository
-
Make sure the backend repository is in the same directory as the frontend repository
-
Use this command to run the project locally:
docker compose --profile frontend-and-backend up --build
-
This will run the frontend and backend in separate containers
-
Install Pipenv (if not already installed):
pip install pipenv
-
Install the project dependencies using Pipenv:
pipenv install --dev
-
Activate the Pipenv virtual environment:
pipenv shell
-
Run the Django development server locally:
python manage.py runserver
This project uses a combination of Django's built in ORM and supabase to store/edit data. In order to edit/add/remove any database tables, be sure to follow these steps:
-
Make needed changes to
pulse/models.py -
Stage the migrations:
python manage.py makemigrations
-
Execute the migrations (DISCLAIMER: this will NOT apply changes directly to the hosted database, they will only be applied locally, and will take effect in the hosted database when your PR is merged into
main)python manage.py migrate
-
Run the following SQL commands in your SQL Editor on your local Supabase DB
CREATE EXTENSION IF NOT EXISTS pg_trgm; CREATE EXTENSION IF NOT EXISTS unaccent;
-- create profile-images bucket insert into storage.buckets (id, name, public) values ('profile-images', 'profile-images', true);
-- create hive-avatars bucket insert into storage.buckets (id, name, public) values ('hive-avatars', 'hive-avatars', true);
-- enable uploading to the profile-images bucklet CREATE POLICY "Allow all on profile-images" ON storage.objects FOR ALL USING (bucket_id = 'profile-images');
-- enable uploading to the hive-avatars bucklet CREATE POLICY "Allow all on hive-avatars" ON storage.objects FOR ALL USING (bucket_id = 'hive-avatars');
-- enable public operations on all buckets (this is needed to avoid RLS issues) CREATE POLICY "Allow all bucket operations" ON storage. buckets FOR ALL USING (true) ;
Use this space to show useful examples of how a project can be used. Additional screenshots, code examples and demos work well in this space. You may also link to more resources.
For more examples, please refer to the Documentation
Distributed under the MIT License. See LICENSE.txt for more information.
CodeHive - [email protected]
Project Link: https://github.com/Spark-Project-Pulse/backend