> ## Documentation Index
> Fetch the complete documentation index at: https://docs.openreward.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# GitHub Deployment

> Connect and deploy environments from GitHub repositories

## Overview

OpenReward integrates seamlessly with GitHub to provide continuous deployment for your environments. When you push code to a connected repository, OpenReward automatically:

1. Builds your container image
2. Deploys the new version
3. Makes your environment available

<Info>
  **Prerequisite**: You must create an environment before connecting a GitHub repository. See [Your First Environment](/environments/your-first-environment) for setup instructions.
</Info>

## Connecting a Repository

### Via OpenReward Web UI

1. **Navigate to Environment Page**
   * Go to `https://openreward.ai/{username}/{environment-name}`

2. **Connect GitHub Repository**
   * Click "Connect GitHub" button
   * You will need to login to github, and grant read access to the desired repository
   * Select the repository from dropdown

3. **Configure Build Settings**
   {/* - **Build Context**: Directory to use as build context (default: `.`) */}
   * **Resource Allocation**: CPU and memory for environment
   * **Scaling settings**: Minimum and maximum number of instances, and the number of sessions per instance

4. **Deploy**
   * Click "Deploy" button
   * First build starts immediately

## Deployment Flow

### Automatic Deployment on Push

Once connected, deployments happen automatically:

```text theme={null}
1. Developer pushes to GitHub
   ↓
2. GitHub webhook notifies OpenReward
   ↓
3. OpenReward validates the push event
   ↓
4. OpenReward builds container image
   ↓
5. New version deployed automatically
   ↓
6. Environment ready with new code
```

## Monitoring Deployments

### Deployment Status

**Via Web UI:**

* Navigate to environment page
* Click "Deployments" tab
* See list of recent deployments with status:
  * ⏳ **Building**: Build in progress
  * ✅ **Deployed**: Successfully deployed
  * ❌ **Failed**: Build or deployment failed

**Deployment Information:**

* Git commit SHA and message
* Triggered by (push or manual)
* Build duration
* Deployment timestamp

### Build Logs

**View in OpenReward:**

1. Go to "Deployments" tab
2. Click on deployment
3. View build logs inline

### Environment Logs

**View in OpenReward:**

1. Go to environment page
2. Click "Logs" tab
3. See real-time logs from your environment server

### Resource Configuration

**CPU and Memory:**
Configure via Web UI:

* Choose appropriate size for your workload
* Options like "1:2" (1 CPU, 2GB RAM)

**Scaling Configuration:**

* **Minimum instances**: Scales to zero when idle (saves cost)
* **Maximum instances**: Limit concurrent environment servers
* **Sessions per instance**: How many agents per server

### Branch and Tag Filtering

**Deploy from Specific Branch:**

* Set in repository connection settings
* Only pushes to this branch trigger deployments
* Default: `main`

**Deploy from Tags:**

```bash theme={null}
# Tag a commit
git tag v1.0.0
git push origin v1.0.0

# Triggers deployment if configured
```

## Best Practices

<AccordionGroup>
  <Accordion title="Use multi-stage Docker builds">
    Reduce image size and build time:

    ```dockerfile theme={null}
    # Build stage
    FROM python:3.11 AS builder
    COPY requirements.txt .
    RUN pip install --user -r requirements.txt

    # Runtime stage
    FROM python:3.11-slim
    COPY --from=builder /root/.local /root/.local
    COPY server.py .
    ENV PATH=/root/.local/bin:$PATH
    CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "8080"]
    ```
  </Accordion>

  <Accordion title="Test builds locally before pushing">
    Catch issues early:

    ```bash theme={null}
    docker build -t test-image .
    docker run -p 8080:8080 test-image
    curl http://localhost:8080/health
    ```
  </Accordion>

  <Accordion title="Use .dockerignore to reduce context">
    Exclude unnecessary files from build context:

    ```
    # .dockerignore
    .git
    .env
    *.pyc
    __pycache__
    tests/
    docs/
    *.md
    ```

    Faster builds, smaller images
  </Accordion>

  <Accordion title="Keep images small">
    * Use slim base images (python:3.11-slim vs python:3.11)
    * Remove unnecessary dependencies
    * Use multi-stage builds
    * Clean up after installations

    ```dockerfile theme={null}
    RUN pip install --no-cache-dir -r requirements.txt
    ```
  </Accordion>

  <Accordion title="Use meaningful commit messages">
    Commit messages appear in deployment history:

    ```bash theme={null}
    # Good
    git commit -m "Add caching to reduce response time"

    # Bad
    git commit -m "fix stuff"
    ```
  </Accordion>
</AccordionGroup>

## Next Steps

<CardGroup cols={3}>
  <Card title="Your First Environment" icon="rocket" href="/environments/your-first-environment">
    Complete tutorial for deploying your first environment
  </Card>

  <Card title="Local Development" icon="laptop-code" href="/deployment/local-development">
    Test environments locally before deploying
  </Card>

  <Card title="Environments" icon="server" href="/concepts/environments">
    Understand environment architecture
  </Card>
</CardGroup>
