Skip to content

Commit 1a2f552

Browse files
author
yolo h8cker 93
committed
WIP(AWS): One more attempt at docker in docker building
1 parent eb55723 commit 1a2f552

2 files changed

Lines changed: 64 additions & 44 deletions

File tree

aws/setup/AWSCodeClash.Dockerfile

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -44,50 +44,10 @@ RUN mkdir -p /var/lib/docker /var/run/docker \
4444
&& mkdir -p /etc/docker \
4545
&& echo '{"storage-driver": "vfs", "iptables": false, "ip-masq": false, "log-driver": "json-file", "log-opts": {"max-size": "10m", "max-file": "3"}}' > /etc/docker/daemon.json
4646

47-
# Start Docker daemon temporarily to build game images
48-
RUN echo "Starting Docker daemon for image building..." && \
49-
dockerd --config-file=/etc/docker/daemon.json > /var/log/dockerd-build.log 2>&1 & \
50-
DOCKERD_PID=$! && \
51-
echo "Docker daemon PID: $DOCKERD_PID" && \
52-
# Wait for Docker daemon to be ready with better error detection
53-
for i in {1..60}; do \
54-
echo "Attempt $i/60: Checking Docker daemon status..." && \
55-
if docker info >/dev/null 2>&1; then \
56-
echo "✅ Docker daemon is ready for building images!"; \
57-
break; \
58-
fi; \
59-
if ! kill -0 $DOCKERD_PID 2>/dev/null; then \
60-
echo "❌ ERROR: Docker daemon process died. Log contents:"; \
61-
cat /var/log/dockerd-build.log; \
62-
exit 1; \
63-
fi; \
64-
if [ $i -eq 60 ]; then \
65-
echo "❌ ERROR: Docker daemon failed to start after 60 seconds. Log contents:"; \
66-
cat /var/log/dockerd-build.log; \
67-
exit 1; \
68-
fi; \
69-
sleep 1; \
70-
done && \
71-
# Build all game-specific Docker images
72-
docker build --no-cache --build-arg GITHUB_TOKEN=${GITHUB_TOKEN} -t codeclash/battlesnake -f ../docker/BattleSnake.Dockerfile . && \
73-
docker build --no-cache --build-arg GITHUB_TOKEN=${GITHUB_TOKEN} -t codeclash/dummygame -f ../docker/DummyGame.Dockerfile . && \
74-
docker build --no-cache --build-arg GITHUB_TOKEN=${GITHUB_TOKEN} -t codeclash/robotrumble -f ../docker/RobotRumble.Dockerfile . && \
75-
docker build --no-cache --build-arg GITHUB_TOKEN=${GITHUB_TOKEN} -t codeclash/huskybench -f ../docker/HuskyBench.Dockerfile . && \
76-
# Stop the Docker daemon gracefully
77-
echo "Stopping Docker daemon..." && \
78-
kill $DOCKERD_PID && \
79-
# Wait for daemon to stop properly
80-
for i in {1..10}; do \
81-
if ! kill -0 $DOCKERD_PID 2>/dev/null; then \
82-
echo "✅ Docker daemon stopped successfully"; \
83-
break; \
84-
fi; \
85-
if [ $i -eq 10 ]; then \
86-
echo "⚠️ Force killing Docker daemon"; \
87-
kill -9 $DOCKERD_PID || true; \
88-
fi; \
89-
sleep 1; \
90-
done
47+
# Copy and run the Docker image building script
48+
COPY build_children_docker_files.sh /build_children_docker_files.sh
49+
RUN chmod +x /build_children_docker_files.sh && \
50+
/build_children_docker_files.sh
9151

9252
# Set build timestamp as environment variable
9353
ARG BUILD_TIMESTAMP
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "Starting Docker daemon for image building..."
5+
6+
# Start Docker daemon in background
7+
dockerd --config-file=/etc/docker/daemon.json > /var/log/dockerd-build.log 2>&1 &
8+
DOCKERD_PID=$!
9+
echo "Docker daemon PID: $DOCKERD_PID"
10+
11+
# Wait for Docker daemon to be ready with better error detection
12+
for i in $(seq 1 60); do
13+
echo "Attempt $i/60: Checking Docker daemon status..."
14+
if docker info >/dev/null 2>&1; then
15+
echo "✅ Docker daemon is ready for building images!"
16+
break
17+
fi
18+
19+
if ! kill -0 $DOCKERD_PID 2>/dev/null; then
20+
echo "❌ ERROR: Docker daemon process died. Log contents:"
21+
cat /var/log/dockerd-build.log
22+
exit 1
23+
fi
24+
25+
if [ $i -eq 60 ]; then
26+
echo "❌ ERROR: Docker daemon failed to start after 60 seconds. Log contents:"
27+
cat /var/log/dockerd-build.log
28+
exit 1
29+
fi
30+
31+
sleep 1
32+
done
33+
34+
# Build all game-specific Docker images
35+
echo "Building game-specific Docker images..."
36+
docker build --no-cache --build-arg GITHUB_TOKEN=${GITHUB_TOKEN} -t codeclash/battlesnake -f ../../docker/BattleSnake.Dockerfile .
37+
docker build --no-cache --build-arg GITHUB_TOKEN=${GITHUB_TOKEN} -t codeclash/dummygame -f ../../docker/DummyGame.Dockerfile .
38+
docker build --no-cache --build-arg GITHUB_TOKEN=${GITHUB_TOKEN} -t codeclash/robotrumble -f ../../docker/RobotRumble.Dockerfile .
39+
docker build --no-cache --build-arg GITHUB_TOKEN=${GITHUB_TOKEN} -t codeclash/huskybench -f ../../docker/HuskyBench.Dockerfile .
40+
41+
# Stop the Docker daemon gracefully
42+
echo "Stopping Docker daemon..."
43+
kill $DOCKERD_PID
44+
45+
# Wait for daemon to stop properly
46+
for i in $(seq 1 10); do
47+
if ! kill -0 $DOCKERD_PID 2>/dev/null; then
48+
echo "✅ Docker daemon stopped successfully"
49+
break
50+
fi
51+
52+
if [ $i -eq 10 ]; then
53+
echo "⚠️ Force killing Docker daemon"
54+
kill -9 $DOCKERD_PID || true
55+
fi
56+
57+
sleep 1
58+
done
59+
60+
echo "Docker image building completed successfully!"

0 commit comments

Comments
 (0)