# Staging

## Setting Up Your Environment

### **Create a .envrc File**

1. **Create the .envrc file:**

   * In the root directory of the project, create a file named `.envrc`.
   * The file should contain the following lines (fill in the values or ask Trevor/Britton):

   ```sh
   shCopy codeexport ETHEREUM_RPC_URL=
   export OPTIMISM_RPC_URL=
   export ARBITRUM_RPC_URL=
   export AVALANCHE_RPC_URL=
   export POLYGON_RPC_URL=
   export PRIV_KEY=
   ```
2. **Use direnv to load environment variables:**
   * We recommend using [direnv](https://direnv.net/) to automatically load the environment variables when you enter the root directory.
   * Follow the instructions to install direnv and hook into your shell.

### **Create a Virtual Environment**

1. **Create the virtual environment:**

   ```sh
   shCopy codepython3 -m venv .venv
   ```
2. **Activate the virtual environment:**

   ```sh
   shCopy codesource .venv/bin/activate
   ```

   * Note: If you are using a shell other than bash or zsh, you may need to use a different activate binary.
3. **Install dependencies:**

   ```sh
   shCopy codepip install -r requirements.txt
   ```
4. **Allow direnv to load the .envrc file:**

   ```sh
   shCopy codedirenv allow
   ```

### Running the Server Locally

After setting up your environment, run the server locally with:

```sh
shCopy codeuvicorn frontend:app --host localhost --port 8080
```

### Working on a Branch Locally

1. **Clone the repository:**
   * Using HTTPS:

     ```sh
     shCopy codegit clone https://github.com/tristeroresearch/cache-half-full
     ```
   * Using SSH:

     ```sh
     shCopy codegit clone git@github.com:tristeroresearch/cache-half-full
     ```
2. **Check out the staging branch (or any other branch):**

   ```sh
   shCopy codegit checkout staging
   ```
3. **Create a new branch:**

   ```sh
   shCopy codegit checkout -b new_branch_name
   ```

### Pushing Local Changes

1. **Add your changes:**
   * Add everything:

     ```sh
     shCopy codegit add .
     ```
   * Add specific files:

     ```sh
     shCopy codegit add <file_path>
     ```
2. **Commit your changes:**

   ```sh
   shCopy codegit commit -m "commit message"
   ```
3. **Push your changes:**

   ```sh
   shCopy codegit push
   ```
4. **Push a new branch to origin:**

   ```sh
   shCopy codegit push -u origin new_branch_name
   ```

### Reading Logs

1. **Access logs and metrics:**

   * Go to the [Fly.io dashboard](https://fly.io/dashboard) and ensure you have an invite.
   * Navigate to the Tristero project:

   ![](https://lh7-us.googleusercontent.com/wtBaq_-XhpyoW8QJHIAubj0i3pxFMFWxGJhT6VEyCP_oIV2B0J9lmSPPEvdxmzV3vNkyuvqSbpYbKtE98m6_-b5H4J_wvrR5OMQtqeW4OGWTI77xIcnwRmsEYVZVtSWcsTUI8t3EVGy9qfMyeyi-tX8)

   [View Logs and Metrics](https://fly.io/apps/cache-half-full-staging/monitoring)

<figure><img src="https://lh7-us.googleusercontent.com/1wJG46VV4a5MN3k4XyvJ4ofNewkRa72pUHNQuIsJr-8sqFtMa2LGhNsv_MjJrlTWCJHZxlxshchrMbwRzqkoH_WSSk4bm92XMU-eXZ1krNdq06RQtQTKqJmeWlKF1xM4Z4WPzKYTl-lpQ7wGlGmAEPI" alt=""><figcaption></figcaption></figure>

### Changing Secrets/Environment Variables of the Deployed App

1. **Install Flyctl:**
   * Follow the instructions to install Flyctl.
2. **Log in to Flyctl:**

   ```sh
   shCopy codeflyctl auth login
   ```
3.

```
<figure><img src="https://lh7-us.googleusercontent.com/QqYpSA4yD7_SJ3dcyh4xN3E05lRZDwdSsgeqnPsDogQ2-0DX3wslDrkjGFZN_8dbJhDCVH5huc5iXcvXoNUtK-vTsV10GzbyvJXfkiJR70TGVbKrEgJ202T9XS-24f3lJ6Uw5Bczv_BsA0WRfbLWm4M" alt=""><figcaption></figcaption></figure>
```

```
<figure><img src="https://lh7-us.googleusercontent.com/85LzTmtMooAO9EYV7Z2XCV53eU0KpV3yzKW7-aggGXW8samEeuqLLCnSofWxQOGZpGL3J3Kdha1tobvsGukHb75osCMKgA5BI41YNMAtzv-POHzcOUb-vKD62nKlXkLTi9vdAwttJfxZR6YppM43PpA" alt=""><figcaption></figcaption></figure>
```

4\. **Push to rebuild:**

* After making changes to secrets or environment variables, push to rebuild the staging app.
