Skip to content

Commit 1f47a4e

Browse files
authored
Merge pull request #153 from dcube0710/project-pikachu-simran
Organised Dockerfile
2 parents ce2cf68 + bfd79b2 commit 1f47a4e

File tree

3 files changed

+127
-7
lines changed

3 files changed

+127
-7
lines changed

src/envs/pokemon_env/README.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,21 @@ print(f"Reward: {result.reward}, Done: {result.done}")
4848
### Docker
4949

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

54-
# Run
55-
docker run -d -p 8000:8000 -p 9980:9980 pokemon-env:latest
55+
# Create Docker network for container communication
56+
docker network create pokemon-network
57+
58+
# Run Pokemon Showdown server
59+
docker run -d --name pokemon-showdown --network pokemon-network -p 8000:8000 pokemon-showdown:latest
60+
61+
# Run OpenEnv server (pointing to the Showdown container)
62+
docker run -d --name pokemon-env --network pokemon-network -p 9980:9980 pokemon-env:latest
5663

5764
# Test
58-
curl http://localhost:9980/health
65+
curl http://localhost:9980/health # Test OpenEnv server
5966
```
6067

6168
## Configuration
@@ -71,13 +78,14 @@ Environment variables:
7178
### Battle Flow
7279

7380
```
74-
HTTP Client → FastAPI Server → PokemonEnvironment
81+
HTTP Client → FastAPI Server → PokemonEnvironment (Container 2)
7582
7683
OpenEnvPokemonPlayer
7784
7885
poke-env (POKE_LOOP)
7986
80-
Pokemon Showdown (WebSocket)
87+
Pokemon Showdown Server (Container 1)
88+
(WebSocket)
8189
```
8290

8391
### Key Design Decisions
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Dockerfile for Pokemon Battle Environment OpenEnv
2+
# This image provides Pokemon battles via poke-env
3+
4+
# Build OpenEnv base (can be overridden for CI/CD)
5+
ARG BASE_IMAGE
6+
FROM ${BASE_IMAGE:-openenv-base:latest} AS final
7+
8+
# Install dependencies
9+
RUN apt-get update && apt-get install -y \
10+
curl \
11+
supervisor \
12+
&& rm -rf /var/lib/apt/lists/*
13+
14+
# Install poke-env and dependencies
15+
RUN pip install --no-cache-dir \
16+
poke-env>=0.9.0 \
17+
gymnasium>=0.29.0
18+
19+
# Copy OpenEnv core (base image already set WORKDIR=/app)
20+
COPY src/core/ /app/src/core/
21+
22+
# Copy Pokemon environment code
23+
COPY src/envs/pokemon_env/ /app/src/envs/pokemon_env/
24+
25+
# Copy README for web interface documentation
26+
COPY src/envs/pokemon_env/README.md /app/README.md
27+
28+
# Pokemon environment variables
29+
ENV POKEMON_BATTLE_FORMAT=gen9randombattle
30+
ENV POKEMON_PLAYER_USERNAME=player
31+
ENV POKEMON_REWARD_MODE=sparse
32+
ENV POKEMON_MAX_TURNS=1000
33+
34+
# Expose OpenEnv port
35+
EXPOSE 9980
36+
37+
# Create supervisor config for OpenEnv
38+
RUN echo '[supervisord]\n\
39+
nodaemon=true\n\
40+
logfile=/dev/null\n\
41+
logfile_maxbytes=0\n\
42+
\n\
43+
[program:openenv]\n\
44+
command=uvicorn envs.pokemon_env.server.app:app --host 0.0.0.0 --port 9980\n\
45+
directory=/app\n\
46+
environment=PYTHONPATH="/app/src"\n\
47+
autostart=true\n\
48+
autorestart=true\n\
49+
stdout_logfile=/dev/fd/1\n\
50+
stdout_logfile_maxbytes=0\n\
51+
stderr_logfile=/dev/fd/2\n\
52+
stderr_logfile_maxbytes=0\n\
53+
startsecs=10\n' > /etc/supervisor/conf.d/pokemon-env.conf
54+
55+
# Health check
56+
HEALTHCHECK --interval=30s --timeout=3s --start-period=15s --retries=3 \
57+
CMD curl -f http://localhost:9980/health || exit 1
58+
59+
# Run supervisor
60+
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Dockerfile for Pokemon Showdown Server
2+
# Stage 1: Build Pokemon Showdown
3+
FROM node:18-slim AS showdown-builder
4+
5+
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*
6+
7+
WORKDIR /pokemon-showdown
8+
9+
RUN git clone https://github.com/smogon/pokemon-showdown.git . && \
10+
npm install && \
11+
cp config/config-example.js config/config.js
12+
13+
# Stage 2: Final Image
14+
FROM node:18-slim
15+
16+
# Install Node.js for running Pokemon Showdown
17+
RUN apt-get update && apt-get install -y \
18+
nodejs \
19+
npm \
20+
curl \
21+
supervisor \
22+
&& rm -rf /var/lib/apt/lists/*
23+
24+
# Copy Pokemon Showdown from builder
25+
COPY --from=showdown-builder /pokemon-showdown /pokemon-showdown
26+
27+
# Expose port (8000=Showdown)
28+
EXPOSE 8000
29+
30+
# Create supervisor config for Showdown
31+
RUN echo '[supervisord]\n\
32+
nodaemon=true\n\
33+
logfile=/dev/null\n\
34+
logfile_maxbytes=0\n\
35+
\n\
36+
[program:showdown]\n\
37+
command=node pokemon-showdown start --no-security\n\
38+
directory=/pokemon-showdown\n\
39+
autostart=true\n\
40+
autorestart=true\n\
41+
stdout_logfile=/dev/fd/1\n\
42+
stdout_logfile_maxbytes=0\n\
43+
stderr_logfile=/dev/fd/2\n\
44+
stderr_logfile_maxbytes=0\n\
45+
startsecs=5\n' > /etc/supervisor/conf.d/pokemon-env.conf
46+
47+
# Health check (check showdown service)
48+
HEALTHCHECK --interval=30s --timeout=3s --start-period=15s --retries=3 \
49+
CMD curl -f http://localhost:8000 || exit 1
50+
51+
# Run supervisor
52+
CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/supervisord.conf"]

0 commit comments

Comments
 (0)