-
Notifications
You must be signed in to change notification settings - Fork 113
Add git server environment #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| # Copy this file to .env and customize as needed | ||
|
|
||
| # Gitea Service Configuration | ||
| GITEA_URL=http://host.docker.internal:3000 | ||
| GITEA_USERNAME=gitea | ||
| GITEA_PASSWORD=gitea123 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,142 @@ | ||
| #!/usr/bin/env python3 | ||
| """ | ||
| Simple test showing how users will use GitEnv.from_docker_image(). | ||
|
|
||
| This is the simplest possible usage. | ||
|
|
||
| Prerequisites: | ||
| 1. .env file configured (copy from .env.example) | ||
| 2. Shared Gitea running: ./scripts/setup_shared_gitea.sh | ||
| 3. OpenEnv repo migrated to Gitea (see README) | ||
| """ | ||
|
|
||
| import os | ||
| import sys | ||
| from pathlib import Path | ||
|
|
||
| # Load environment variables from .env file | ||
| from dotenv import load_dotenv | ||
| load_dotenv() | ||
|
|
||
| # Add src to path | ||
| sys.path.insert(0, str(Path(__file__).parent.parent / "src")) | ||
|
|
||
| from envs.git_env import GitAction, GitEnv | ||
|
|
||
|
|
||
| def main(): | ||
| """Test GitEnv.from_docker_image().""" | ||
| print("=" * 60) | ||
| print("GitEnv.from_docker_image() Test") | ||
| print("=" * 60) | ||
| print() | ||
|
|
||
| try: | ||
| # Pass environment variables from .env to container | ||
| env_vars = { | ||
| "GITEA_URL": os.getenv("GITEA_URL"), | ||
| "GITEA_USERNAME": os.getenv("GITEA_USERNAME"), | ||
| "GITEA_PASSWORD": os.getenv("GITEA_PASSWORD"), | ||
| } | ||
|
|
||
| # Verify env vars are loaded | ||
| if not all(env_vars.values()): | ||
| print("❌ Error: Required environment variables not found in .env") | ||
| print(" Make sure .env file exists (copy from .env.example)") | ||
| return False | ||
|
|
||
| print("Creating client from Docker image with .env credentials...") | ||
| print(" Using GitEnv.from_docker_image() factory method") | ||
| print() | ||
|
|
||
| # Create client using from_docker_image factory method | ||
| client = GitEnv.from_docker_image("git-env:latest", env_vars=env_vars) | ||
|
|
||
| print("✓ Client created and container started!\n") | ||
|
|
||
| # Now use it like any other client | ||
| print("Testing the environment:") | ||
| print("-" * 60) | ||
|
|
||
| # Reset | ||
| print("\n1. Reset:") | ||
| result = client.reset() | ||
| print(f" Message: {result.observation.message}") | ||
| print(f" Success: {result.observation.success}") | ||
|
|
||
| # Get initial state | ||
| state = client.state() | ||
| print(f" State: episode_id={state.episode_id}, step_count={state.step_count}") | ||
| print(f" Gitea ready: {state.gitea_ready}") | ||
|
|
||
| # List repositories | ||
| print("\n2. List repositories:") | ||
| result = client.step(GitAction(action_type="list_repos")) | ||
| print(f" Success: {result.observation.success}") | ||
| print(f" Found {len(result.observation.repos)} repositories") | ||
| for repo in result.observation.repos: | ||
| print(f" - {repo['name']}") | ||
|
|
||
| # Clone repository | ||
| print("\n3. Clone repository:") | ||
| result = client.step(GitAction(action_type="clone_repo", repo_name="OpenEnv")) | ||
| print(f" Success: {result.observation.success}") | ||
| print(f" Message: {result.observation.message}") | ||
| print(f" Output: {result.observation.output}") | ||
|
|
||
| # Execute git commands | ||
| print("\n4. Execute git commands:") | ||
|
|
||
| git_commands = [ | ||
| "status", | ||
| "log --oneline -5", | ||
| "branch -a", | ||
| ] | ||
|
|
||
| for cmd in git_commands: | ||
| result = client.step( | ||
| GitAction(action_type="execute_git_command", command=cmd, working_dir="OpenEnv") | ||
| ) | ||
| print(f"\n git {cmd}:") | ||
| print(f" Success: {result.observation.success}") | ||
| if result.observation.output: | ||
| # Show first few lines | ||
| lines = result.observation.output.strip().split("\n")[:5] | ||
| for line in lines: | ||
| print(f" {line}") | ||
| if len(result.observation.output.strip().split("\n")) > 5: | ||
| print(" ...") | ||
|
|
||
| # Check final state | ||
| print("\n5. Check final state:") | ||
| state = client.state() | ||
| print(f" episode_id: {state.episode_id}") | ||
| print(f" step_count: {state.step_count}") | ||
| print(f" gitea_ready: {state.gitea_ready}") | ||
|
|
||
| print("\n" + "-" * 60) | ||
| print("\n✓ All operations successful!") | ||
| print() | ||
|
|
||
| print("Cleaning up...") | ||
| client.close() | ||
| print("✓ Container stopped and removed") | ||
| print() | ||
|
|
||
| print("=" * 60) | ||
| print("Test completed successfully!") | ||
| print("=" * 60) | ||
|
|
||
| return True | ||
|
|
||
| except Exception as e: | ||
| print(f"\n❌ Test failed: {e}") | ||
| import traceback | ||
|
|
||
| traceback.print_exc() | ||
| return False | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| success = main() | ||
| exit(0 if success else 1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| #!/bin/bash | ||
| # Setup script for shared Gitea instance | ||
| # This script starts Gitea, waits for it to be ready, and creates the admin user | ||
| # Requires: .env file with GITEA_USERNAME and GITEA_PASSWORD | ||
|
|
||
| set -e | ||
|
|
||
| # Load credentials from .env file | ||
| if [ -f .env ]; then | ||
| export $(cat .env | grep -E '^(GITEA_USERNAME|GITEA_PASSWORD)=' | xargs) | ||
| else | ||
| echo "❌ Error: .env file not found" | ||
| echo " Please copy .env.example to .env and configure credentials" | ||
| exit 1 | ||
| fi | ||
|
|
||
| echo "=====================================" | ||
| echo "Setting up shared Gitea instance" | ||
| echo "=====================================" | ||
| echo | ||
|
|
||
| # Start Gitea with docker-compose | ||
| echo "1. Starting Gitea container..." | ||
| docker-compose -f src/envs/git_env/docker-compose.gitea.yml up -d | ||
|
|
||
| # Wait for Gitea to be healthy | ||
| echo "2. Waiting for Gitea to be ready..." | ||
| timeout=60 | ||
| elapsed=0 | ||
| while [ $elapsed -lt $timeout ]; do | ||
| if docker exec openenv-gitea curl -sf http://localhost:3000/ > /dev/null 2>&1; then | ||
| echo " ✓ Gitea is ready!" | ||
| break | ||
| fi | ||
| echo " Waiting... (${elapsed}s/${timeout}s)" | ||
| sleep 2 | ||
| elapsed=$((elapsed + 2)) | ||
| done | ||
|
|
||
| if [ $elapsed -ge $timeout ]; then | ||
| echo " ✗ Timeout waiting for Gitea" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Initialize Gitea (POST to root URL) | ||
| echo "3. Initializing Gitea configuration..." | ||
| docker exec openenv-gitea curl -s -X POST \ | ||
| -H "Content-Type: application/x-www-form-urlencoded" \ | ||
| -d "db_type=sqlite3" \ | ||
| -d "db_path=%2Fdata%2Fgitea%2Fgitea.db" \ | ||
| -d "app_name=Gitea" \ | ||
| -d "repo_root_path=%2Fdata%2Fgit%2Frepositories" \ | ||
| -d "run_user=git" \ | ||
| -d "domain=gitea" \ | ||
| -d "http_port=3000" \ | ||
| -d "app_url=http%3A%2F%2Fgitea%3A3000%2F" \ | ||
| -d "log_root_path=%2Fdata%2Fgitea%2Flog" \ | ||
| -d "offline_mode=on" \ | ||
| http://localhost:3000/ > /dev/null || echo " (Config may already exist)" | ||
|
|
||
| # Create admin user | ||
| echo "4. Creating admin user ($GITEA_USERNAME)..." | ||
| docker exec openenv-gitea su git -c \ | ||
| "gitea admin user create --username $GITEA_USERNAME --password $GITEA_PASSWORD --email ${GITEA_USERNAME}@local.env --admin" \ | ||
| 2>&1 | grep -q "already exists" && echo " ✓ User already exists" || echo " ✓ User created" | ||
|
|
||
| echo | ||
| echo "=====================================" | ||
| echo "✓ Gitea setup complete!" | ||
| echo "=====================================" | ||
| echo | ||
| echo "Gitea is now available at:" | ||
| echo " - Web UI: http://localhost:3000" | ||
| echo " - From containers: http://gitea:3000" | ||
| echo | ||
| echo "Admin credentials are configured from .env file" | ||
| echo | ||
| echo "To stop Gitea:" | ||
| echo " docker-compose -f src/envs/git_env/docker-compose.gitea.yml down" | ||
| echo | ||
| echo "To remove all data:" | ||
| echo " docker-compose -f src/envs/git_env/docker-compose.gitea.yml down -v" | ||
| echo | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be better to model this as an MCP tool for this env eventually? RFC 004 touches upon this point. WDYT?
cc: @Darktex