diff --git a/SETUP.md b/SETUP.md index 555ca9396..040c6e026 100644 --- a/SETUP.md +++ b/SETUP.md @@ -14,31 +14,54 @@ the main two for you to set up: └── test/ # End-to-end tests ``` -## API +## Setting up With Docker +A [`Docker Compose`](./docker-compose.yml) file has been provided to quickly get the API, database, verifier, celery workers, and interface +up and running. Setup instructions are provided below: -A [`Dockerfile`](./api/Dockerfile) has been provided to quickly get the API -environment up and running. Setup instructions are also provided below. +1. Download the Passport Scorer Repo -### With Docker +```shell +git clone https://github.com/gitcoinco/passport-scorer.git +``` -1. Create a new `.env` file by copying the existing `.env-sample` file +2. Create a new `.env` file in the `api` directory & update the variables. ```shell # From inside the api/ directory cp .env-sample .env ``` +Update the `DATABASE_URL` variable to `postgres://passport_scorer:passport_scorer_pwd@postgres:5432/passport_scorer` + +Update the `CERAMIC_CACHE_SCORER_ID` variable to match a `SCORER_ID` you create from the scorer UI. + (You will have to complete all these setup steps first, then you will be able to create a `SCORER_ID` from the UI & update this variable.) -2. Run and build the `Dockerfile`. The first time you run this, it will take +3. Create a new `.env` file in the `interface` directory & update the varaibles. +```shell +# From inside the interface/ directory +cp .env.example .env +``` +Update the `NEXT_PUBLIC_PASSPORT_SCORER_ALCHEMY_API_KEY` varaible to an Alchemy API key you own. If you don't have one, you can create one for free [here](https://docs.alchemy.com/reference/api-overview) + + +4. Run and build the `Dockerfile` from the root directory. The first time you run this, it will take a while to build the Docker images. + ``` -cd api docker-compose up --build ``` +Upon subsequent runs, you can omit the `--build` flag. + +5. Perform a database migration in the root directory by opening a new terminal & running: + +```shell +docker-compose exec api python manage.py migrate +``` + +The API will be running on port 8002, interface on 3001, redis on 6379, and the database will be running on port 5432. -The API will be running on port 8000 and the database will be running on port -5432. -### Without docker + +## Setting up Without docker We assume that you have a working python environment set up on your machine with the following: @@ -46,25 +69,37 @@ the following: - A recent version of Python - `pipenv` +### Download this Repo + +```shell +git clone https://github.com/gitcoinco/passport-scorer.git +``` + +### API + The following commands should be run from within the `api/` directory. -1. Activate your local virtual environment: +1. Create a `.env` file: + +```shell +cp .env-sample .env +``` + +2. Activate your local virtual environment: ``` pipenv shell ``` -2. Install dependencies in your virtual environment: +3. Install dependencies in your virtual environment: ``` pipenv install pipenv install --dev ``` -3. Start the dev server: -**First**: make sure you have the `.env` file in the api folder, with proper -values (copy the `.env-sample` and adjust it). Then: +4. Start the dev server: ```shell gunicorn -b 127.0.0.1:8002 -w 4 -k uvicorn.workers.UvicornWorker scorer.asgi:application @@ -76,27 +111,47 @@ or: uvicorn scorer.asgi:application --reload --port 8002 ``` -Start the celery worker: +5. Run Redis locally in a new terminal: + +```shell +pipenv shell +docker run -d -p 6379:6379 redis +``` + +> Make sure you have Docker running + +6. Start the celery worker: ```shell celery -A scorer worker -l DEBUG ``` -And run Redis locally: +### Migrations + +You will need to run database migrations in the `api/` directory by running: ```shell -docker run -d -p 6379:6379 redis +pipenv shell +python manage.py migrate ``` -> Make sure you have Docker running +### Verifier -## Interface +Navigate to the `verifier/` directory & run the verifier: +```shell +yarn +#yarn only needs to be run when first installing the app +yarn dev +``` + +### Interface The front end is built using Next.js and is using a fairly standard installation without much customization. To run the front end, change into the `interface/` directory and install the dependencies: + ``` yarn ``` @@ -107,7 +162,7 @@ Copy the `.env.example` file: cp .env.example .env ``` -You will need an [Alchemy API key](https://docs.alchemy.com/reference/api-overview). +Update the `NEXT_PUBLIC_PASSPORT_SCORER_ALCHEMY_API_KEY` varaible to an Alchemy API key you own. If you don't have one, you can create one for free [here](https://docs.alchemy.com/reference/api-overview) To start the development server: @@ -119,8 +174,7 @@ yarn dev ### API -> The following assumes you are in the api/ directory and that you've already -activated your local virtual environment +> The following assumes you are in the api/ directory and that you've already activated your local virtual environment In the `./api` directory run (make sure your local virtual env is activated): diff --git a/api/docker-compose.yml b/api/docker-compose.yml deleted file mode 100644 index 2b0ac96a4..000000000 --- a/api/docker-compose.yml +++ /dev/null @@ -1,28 +0,0 @@ -version: "3" - -services: - db: - image: postgres:12.3-alpine - restart: unless-stopped - ports: - - 5432:5432 - - environment: - POSTGRES_USER: passport_scorer - POSTGRES_PASSWORD: passport_scorer_pwd - POSTGRES_DB: passport_scorer - PGDATA: /db_fix_trading_data - - volumes: - - ./postgres_db_data:/db_fix_trading_data - - scorer: - build: . - restart: unless-stopped - env_file: .env - - volumes: - - ./db.sqlite3:/db.sqlite3 - - ports: - - 80:8000 diff --git a/docker-compose.yml b/docker-compose.yml index f4fedb8d9..1513f5d1c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -36,7 +36,7 @@ services: build: interface ports: - - "127.0.0.1:3001:3000" + - "3001:3001" verifier: build: verifier @@ -53,3 +53,6 @@ services: volumes: - ./postgres_db_data:/db_data + + ports: + - 5432:5432 diff --git a/interface/Dockerfile b/interface/Dockerfile index e27ecdfc9..e577acb7b 100644 --- a/interface/Dockerfile +++ b/interface/Dockerfile @@ -15,8 +15,8 @@ COPY . . # Build the Next.js app RUN yarn build -# Expose port 3000 to the outside world -EXPOSE 3000 +# Expose port 3001 to the outside world +EXPOSE 3001 # Set the command to start the app CMD [ "yarn", "start" ]