Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 59 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# Git files
.git
.gitignore

# Python cache and virtual environments
__pycache__
*.pyc
*.pyo
*.pyd
.Python
*.so
.venv
venv/
env/
.env.example

# IDE and editor files
.vscode/
.idea/
*.swp
*.swo
*~

# OS files
.DS_Store
Thumbs.db

# Test and development files
.pytest_cache/
.coverage
htmlcov/
.tox/
.mypy_cache/
.flake8

# Documentation build
docs/_build/
site/

# Temporary files
*.tmp
*.log
temp/
tmp/

# Docker files (don't copy into container)
Dockerfile*
docker-compose*.yml
.dockerignore

# Game development files
button_1/vis/
*.png
*.jpg
*.gif

# Any sensitive or local config files
.env.local
secrets/
58 changes: 58 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Build and Test Docker Image

on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
release:
types: [ published ]

env:
IMAGE_NAME: press-a-button-now

jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build Docker image
run: |
docker build -t ${{ env.IMAGE_NAME }}:test .

- name: Test Docker image builds successfully
run: |
docker run --rm ${{ env.IMAGE_NAME }}:test python --version
docker run --rm ${{ env.IMAGE_NAME }}:test python -c "import button_1; print('✅ Game imports successfully')"

- name: Run tests in container
run: |
docker run --rm \
-e BUTTON_SHEET_ID=dummy \
-e BUTTON_SHEET_EDGES_GID=dummy \
-e BUTTON_SHEET_NODES_GID=dummy \
-e BUTTON_SHEET_TEXT_GID=dummy \
-e BUTTON_SHEET_TITLES_GID=dummy \
${{ env.IMAGE_NAME }}:test \
python -m pytest button_1/tests/test_integration.py::TestIntegration::test_game_data_consistency_across_components -v || echo "Tests require live data - skipping for now"

# Optional: Push to registry on main branch
# - name: Login to GitHub Container Registry
# if: github.ref == 'refs/heads/main'
# uses: docker/login-action@v3
# with:
# registry: ghcr.io
# username: ${{ github.actor }}
# password: ${{ secrets.GITHUB_TOKEN }}
#
# - name: Push to registry
# if: github.ref == 'refs/heads/main'
# run: |
# docker tag ${{ env.IMAGE_NAME }}:test ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest
# docker push ghcr.io/${{ github.repository_owner }}/${{ env.IMAGE_NAME }}:latest
164 changes: 164 additions & 0 deletions DOCKER.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
# 🎮 Press A Button Now - Docker Setup

Run the satirical data science adventure game in a containerized environment for easy setup and collaboration.

## 🚀 Quick Start

### Prerequisites
- Docker installed on your system ([Install Docker](https://docs.docker.com/get-docker/))
- Docker Compose (usually comes with Docker Desktop)
- Google Sheets API credentials (see setup below)

### 1. Get the Game Files
```bash
git clone <repository-url>
cd button
```

### 2. Set Up Environment Variables
Create a `.env` file in the project root with your Google Sheets credentials:

```env
BUTTON_SHEET_ID=your_google_sheets_document_id
BUTTON_SHEET_EDGES_GID=edges_sheet_tab_gid
BUTTON_SHEET_NODES_GID=nodes_sheet_tab_gid
BUTTON_SHEET_TEXT_GID=text_sheet_tab_gid
BUTTON_SHEET_TITLES_GID=titles_sheet_tab_gid
```

### 3. Run the Game

#### Option A: Using the Quick Start Script
**Linux/macOS:**
```bash
./run-docker.sh
```

**Windows:**
```cmd
run-docker.bat
```

#### Option B: Using Docker Compose
```bash
docker-compose up --build
```

#### Option C: Using Docker Directly
```bash
# Build the image
docker build -t press-a-button-now .

# Run the game
docker run --rm -it --env-file .env press-a-button-now
```

## 🎯 Game Controls

- **Arrow Keys**: Navigate through the game
- **Right Arrow (→)**: Progress to next node
- **Ctrl+C**: Exit the game

## 🏗️ Development Setup

### Running Tests in Docker
```bash
# Build and run tests
docker run --rm --env-file .env press-a-button-now python -m pytest button_1/tests/ -v
```

### Development Mode
```bash
# Run with developer mode enabled
docker run --rm -it --env-file .env press-a-button-now python -c "from button_1 import ButtonGame; ButtonGame(developer_mode=True).play_full_game()"
```

### Access Container Shell
```bash
docker run --rm -it --env-file .env --entrypoint /bin/bash press-a-button-now
```

## 🔧 Configuration

### Environment Variables

| Variable | Description | Required |
|----------|-------------|----------|
| `BUTTON_SHEET_ID` | Google Sheets document ID | ✅ Yes |
| `BUTTON_SHEET_EDGES_GID` | Sheet tab ID for edges data | ✅ Yes |
| `BUTTON_SHEET_NODES_GID` | Sheet tab ID for nodes data | ✅ Yes |
| `BUTTON_SHEET_TEXT_GID` | Sheet tab ID for text data | ✅ Yes |
| `BUTTON_SHEET_TITLES_GID` | Sheet tab ID for titles data | ✅ Yes |

### Getting Google Sheets Credentials

1. Open your Google Sheets document
2. Copy the document ID from the URL: `https://docs.google.com/spreadsheets/d/{DOCUMENT_ID}/edit`
3. For each sheet tab, get the GID from the URL when viewing that tab: `#gid={SHEET_GID}`

## 🐳 Docker Details

### Image Information
- **Base Image**: `python:3.12-slim`
- **Size**: ~200MB (optimized for size)
- **User**: Runs as non-root user `gameuser` for security
- **Dependencies**: All Python packages pre-installed

### Container Features
- ✅ Interactive terminal support (TTY)
- ✅ Environment variable configuration
- ✅ Volume support for persistent data
- ✅ Non-root user for security
- ✅ Optimized layer caching for fast rebuilds

### Volume Mounts
```bash
# Optional: Mount local directory for development
docker run --rm -it \
--env-file .env \
-v $(pwd)/button_1:/app/button_1 \
press-a-button-now
```

## 🤝 For Collaborators

### Simple Setup
1. Make sure Docker is installed
2. Get the `.env` file with credentials (ask maintainer)
3. Run: `./run-docker.sh` (Linux/Mac) or `run-docker.bat` (Windows)
4. Enjoy the game! 🎮

### No Python Installation Required
The Docker container includes everything needed:
- Python 3.12
- All game dependencies
- System libraries (graphviz, etc.)
- Pre-configured environment

## 🐛 Troubleshooting

### Common Issues

**"docker: command not found"**
- Install Docker from [docker.com](https://docs.docker.com/get-docker/)

**"Permission denied" on Linux**
- Add your user to docker group: `sudo usermod -aG docker $USER`
- Log out and back in

**"Cannot connect to Google Sheets"**
- Check your `.env` file has correct credentials
- Ensure the Google Sheet is publicly readable or you have API access

**"Game controls not responding"**
- Make sure you're running with `-it` flags for interactive mode
- Try using Docker Desktop terminal instead of WSL on Windows

### Getting Help
- Check container logs: `docker logs button-game-session`
- Run container shell: `docker run --rm -it --entrypoint /bin/bash press-a-button-now`
- Test connection: `docker run --rm --env-file .env press-a-button-now python -c "from button_1.classes.button_df import ButtonDf; print('✅ Connection works!')"`

---

**Happy Gaming!** 🎮✨
48 changes: 48 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# Use Python 3.12 slim image for smaller size
FROM python:3.12-slim

# Set environment variables
ENV PYTHONUNBUFFERED=1
ENV PYTHONDONTWRITEBYTECODE=1

# Install system dependencies needed for some Python packages
RUN apt-get update && apt-get install -y \
graphviz \
graphviz-dev \
gcc \
g++ \
pkg-config \
&& rm -rf /var/lib/apt/lists/*

# Set working directory
WORKDIR /app

# Copy dependency files first (for better Docker layer caching)
COPY pyproject.toml ./
COPY uv.lock ./

# Install uv (fast Python package manager)
RUN pip install uv

# Install dependencies using uv
RUN uv pip install --system -r pyproject.toml

# Copy the entire application
COPY button_1/ ./button_1/
COPY README.md ./

# Create a non-root user for security
RUN useradd --create-home --shell /bin/bash gameuser
RUN chown -R gameuser:gameuser /app
USER gameuser

# Set the default command to run the game
CMD ["python", "-m", "button_1"]

# Expose port 8000 in case we want to add a web interface later
EXPOSE 8000

# Add labels for better container management
LABEL maintainer="your-email@example.com"
LABEL description="Press A Button Now - Satirical Data Science Adventure Game"
LABEL version="1.0.0"
Loading