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
22 changes: 15 additions & 7 deletions src/envs/pokemon_env/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,21 @@ print(f"Reward: {result.reward}, Done: {result.done}")
### Docker

```bash
# Build
docker build -t pokemon-env:latest -f server/Dockerfile ../../../..
# Build both images (run from project root directory)
docker build -t pokemon-showdown:latest -f src/envs/pokemon_env/server/Dockerfile.showdown .
docker build -t pokemon-env:latest -f src/envs/pokemon_env/server/Dockerfile.env .

# Run
docker run -d -p 8000:8000 -p 9980:9980 pokemon-env:latest
# Create Docker network for container communication
docker network create pokemon-network

# Run Pokemon Showdown server
docker run -d --name pokemon-showdown --network pokemon-network -p 8000:8000 pokemon-showdown:latest

# Run OpenEnv server (pointing to the Showdown container)
docker run -d --name pokemon-env --network pokemon-network -p 9980:9980 pokemon-env:latest

# Test
curl http://localhost:9980/health
curl http://localhost:9980/health # Test OpenEnv server
```

## Configuration
Expand All @@ -71,13 +78,14 @@ Environment variables:
### Battle Flow

```
HTTP Client → FastAPI Server → PokemonEnvironment
HTTP Client → FastAPI Server → PokemonEnvironment (Container 2)
OpenEnvPokemonPlayer
poke-env (POKE_LOOP)
Pokemon Showdown (WebSocket)
Pokemon Showdown Server (Container 1)
(WebSocket)
```

### Key Design Decisions
Expand Down
60 changes: 60 additions & 0 deletions src/envs/pokemon_env/server/Dockerfile.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Dockerfile for Pokemon Battle Environment OpenEnv
# This image provides Pokemon battles via poke-env

# Build OpenEnv base (can be overridden for CI/CD)
ARG BASE_IMAGE
FROM ${BASE_IMAGE:-openenv-base:latest} AS final

# Install dependencies
RUN apt-get update && apt-get install -y \
curl \
supervisor \
&& rm -rf /var/lib/apt/lists/*

# Install poke-env and dependencies
RUN pip install --no-cache-dir \
poke-env>=0.9.0 \
gymnasium>=0.29.0

# Copy OpenEnv core (base image already set WORKDIR=/app)
COPY src/core/ /app/src/core/

# Copy Pokemon environment code
COPY src/envs/pokemon_env/ /app/src/envs/pokemon_env/

# Copy README for web interface documentation
COPY src/envs/pokemon_env/README.md /app/README.md

# Pokemon environment variables
ENV POKEMON_BATTLE_FORMAT=gen9randombattle
ENV POKEMON_PLAYER_USERNAME=player
ENV POKEMON_REWARD_MODE=sparse
ENV POKEMON_MAX_TURNS=1000

# Expose OpenEnv port
EXPOSE 9980

# Create supervisor config for OpenEnv
RUN echo '[supervisord]\n\
nodaemon=true\n\
logfile=/dev/null\n\
logfile_maxbytes=0\n\
\n\
[program:openenv]\n\
command=uvicorn envs.pokemon_env.server.app:app --host 0.0.0.0 --port 9980\n\
directory=/app\n\
environment=PYTHONPATH="/app/src"\n\
autostart=true\n\
autorestart=true\n\
stdout_logfile=/dev/fd/1\n\
stdout_logfile_maxbytes=0\n\
stderr_logfile=/dev/fd/2\n\
stderr_logfile_maxbytes=0\n\
startsecs=10\n' > /etc/supervisor/conf.d/pokemon-env.conf

# Health check
HEALTHCHECK --interval=30s --timeout=3s --start-period=15s --retries=3 \
CMD curl -f http://localhost:9980/health || exit 1

# Run supervisor
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
52 changes: 52 additions & 0 deletions src/envs/pokemon_env/server/Dockerfile.showdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Dockerfile for Pokemon Showdown Server
# Stage 1: Build Pokemon Showdown
FROM node:18-slim AS showdown-builder

RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*

WORKDIR /pokemon-showdown

RUN git clone https://github.com/smogon/pokemon-showdown.git . && \
npm install && \
cp config/config-example.js config/config.js

# Stage 2: Final Image
FROM node:18-slim

# Install Node.js for running Pokemon Showdown
RUN apt-get update && apt-get install -y \
nodejs \
npm \
curl \
supervisor \
&& rm -rf /var/lib/apt/lists/*

# Copy Pokemon Showdown from builder
COPY --from=showdown-builder /pokemon-showdown /pokemon-showdown

# Expose port (8000=Showdown)
EXPOSE 8000

# Create supervisor config for Showdown
RUN echo '[supervisord]\n\
nodaemon=true\n\
logfile=/dev/null\n\
logfile_maxbytes=0\n\
\n\
[program:showdown]\n\
command=node pokemon-showdown start --no-security\n\
directory=/pokemon-showdown\n\
autostart=true\n\
autorestart=true\n\
stdout_logfile=/dev/fd/1\n\
stdout_logfile_maxbytes=0\n\
stderr_logfile=/dev/fd/2\n\
stderr_logfile_maxbytes=0\n\
startsecs=5\n' > /etc/supervisor/conf.d/pokemon-env.conf

# Health check (check showdown service)
HEALTHCHECK --interval=30s --timeout=3s --start-period=15s --retries=3 \
CMD curl -f http://localhost:8000 || exit 1

# Run supervisor
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]