From 9cc814bdb428bf494b092b844b15fd530ac3cd3a Mon Sep 17 00:00:00 2001 From: Andriy Date: Sat, 10 May 2025 23:31:41 +0200 Subject: [PATCH] karel simulator + maintenance page --- .gitignore | 2 + Dockerfile | 15 + disable-maintenance.sh | 6 + docker-compose.yml | 14 + enable-maintenance.sh | 6 + index.html | 849 +++++++++++++++++++++++++++++++++++++++++ maintenance/index.html | 10 + manual.html | 106 +++++ prepare-app.sh | 9 + remove-app.sh | 24 ++ start-app.sh | 20 + stop-app.sh | 5 + 12 files changed, 1066 insertions(+) create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100755 disable-maintenance.sh create mode 100644 docker-compose.yml create mode 100755 enable-maintenance.sh create mode 100755 index.html create mode 100644 maintenance/index.html create mode 100755 manual.html create mode 100755 prepare-app.sh create mode 100755 remove-app.sh create mode 100755 start-app.sh create mode 100755 stop-app.sh diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6582234 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Local Netlify folder +.netlify diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..4e005b9 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +# Dockerfile +FROM nginx:alpine + +# Remove default content +RUN rm -rf /usr/share/nginx/html/* + +# Copy your simulator files +COPY . /usr/share/nginx/html + +# Expose port 80 +EXPOSE 80 + +# Run Nginx in foreground +CMD ["nginx", "-g", "daemon off;"] + diff --git a/disable-maintenance.sh b/disable-maintenance.sh new file mode 100755 index 0000000..12e80ef --- /dev/null +++ b/disable-maintenance.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -e +# deploy the real site back +netlify deploy --prod --dir=. \ + --message="✅ Live site ON" + diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..a04527d --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,14 @@ +services: + simulator: + build: . + image: karel-simulator + container_name: karel-simulator + ports: + - "8080:80" + restart: unless-stopped + + redis: + image: redis:alpine + container_name: karel-redis + restart: unless-stopped + diff --git a/enable-maintenance.sh b/enable-maintenance.sh new file mode 100755 index 0000000..2269861 --- /dev/null +++ b/enable-maintenance.sh @@ -0,0 +1,6 @@ +#!/usr/bin/env bash +set -e +# deploy the maintenance folder +netlify deploy --prod --dir=maintenance \ + --message="⚙️ Maintenance page ON" + diff --git a/index.html b/index.html new file mode 100755 index 0000000..d1f9838 --- /dev/null +++ b/index.html @@ -0,0 +1,849 @@ + + + + + Karel Simulator + + + +

Karel Simulator

+ + +
+
+

+ Write your Karel program below. Parentheses & semicolons mandatory. + If you’re ever unsure how to use the Simulator, + + consult the manual + . +

+ + + + +

Console Output:

+
+

Upload Map File:

+ + +
+ +
+

Karel Map:

+
+
+
+
+ + + + + + + diff --git a/maintenance/index.html b/maintenance/index.html new file mode 100644 index 0000000..222a280 --- /dev/null +++ b/maintenance/index.html @@ -0,0 +1,10 @@ + + + +Down for Maintenance + +

⚙️ Site Under Maintenance

+

We’ll be back shortly. Thank you for your patience!

+ + + diff --git a/manual.html b/manual.html new file mode 100755 index 0000000..ae50aef --- /dev/null +++ b/manual.html @@ -0,0 +1,106 @@ + + + + + Karel Simulator — User Manual + + + +

Karel the Robot – Quick-Start User Guide

+ +

1. What Is Karel?

+

+ Karel lives in a 2-D grid (“world”) of square cells. + He can face North/East/South/West, move one cell at a time, + pick up or put down “beepers,” and detect walls. +

+ +

2. Simulator Interface

+ + +

3. Syntax Essentials

+ + +

4. Built-in Commands

+

Movement

+ + + + +
CommandEffect
move()Step forward if no wall ahead.
turnLeft()Rotate 90° counter-clockwise.
+ +

Beeper Handling

+ + + + +
CommandEffect
pickBeeper()Pick one beeper from current cell.
putBeeper()Place one beeper into current cell.
+ +

Sensors & Conditions

+ + + + + + + + + + + + + + +
ConditionTrue When…
frontIsClear()No wall immediately in front.
frontIsBlocked()Wall immediately in front.
leftIsClear()No wall on Karel’s left.
leftIsBlocked()Wall on Karel’s left.
rightIsClear()No wall on Karel’s right.
rightIsBlocked()Wall on Karel’s right.
nextToABeeper()One or more beepers in this cell.
notNextToABeeper()No beepers in this cell.
facingNorth(), facingEast(), …Karel’s orientation matches the named direction.
anyBeepersInBeeperBag()Bag contains ≥ 1 beeper.
noBeepersInBeeperBag()Bag is empty.
+ +

5. Example

+
while ( notNextToABeeper() ) {
+  move();
+}
+pickBeeper();
+turnLeft();
+move();
+putBeeper();
+ +

6. Tips

+ + +

← Back to Simulator

+ + diff --git a/prepare-app.sh b/prepare-app.sh new file mode 100755 index 0000000..0c7df7c --- /dev/null +++ b/prepare-app.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env bash +set -e + +# Name for the Docker image +IMAGE_NAME="karel-simulator" + +echo "🔨 Building Docker image '$IMAGE_NAME'..." +docker build -t "${IMAGE_NAME}" . +echo "✅ Image '${IMAGE_NAME}' built." diff --git a/remove-app.sh b/remove-app.sh new file mode 100755 index 0000000..d0280dc --- /dev/null +++ b/remove-app.sh @@ -0,0 +1,24 @@ +#!/usr/bin/env bash +set -e + +IMAGE_NAME="karel-simulator" +CONTAINER_NAME="karel-simulator" + +# Stop & remove the container if it exists +if docker ps -a --format '{{.Names}}' | grep -q "^${CONTAINER_NAME}\$"; then + echo "🗑️ Removing container '${CONTAINER_NAME}'..." + docker rm -f "${CONTAINER_NAME}" + echo "✅ Container removed." +else + echo "ℹ️ No container named '${CONTAINER_NAME}' to remove." +fi + +# Remove the image if it exists +if docker images -q "${IMAGE_NAME}" >/dev/null; then + echo "🗑️ Removing image '${IMAGE_NAME}'..." + docker rmi "${IMAGE_NAME}" + echo "✅ Image removed." +else + echo "ℹ️ No image named '${IMAGE_NAME}' to remove." +fi + diff --git a/start-app.sh b/start-app.sh new file mode 100755 index 0000000..b0c7d93 --- /dev/null +++ b/start-app.sh @@ -0,0 +1,20 @@ +#!/usr/bin/env bash +set -e + +# 1) Clean up any existing containers (manual or compose) +for NAME in karel-simulator karel-redis; do + if docker ps -a --format '{{.Names}}' | grep -q "^${NAME}\$"; then + echo "🛑 Removing existing container '${NAME}'..." + docker rm -f "${NAME}" >/dev/null 2>&1 || true + fi +done + +# 2) (Re)start both services in detached mode +echo "🚀 Starting multi-container application..." +docker compose up -d + +# 3) Status +echo "✅ All containers are up:" +docker ps --filter "name=karel" --format " • {{.Names}} ({{.Image}}) → {{.Ports}}" +echo "" +echo "🌐 Simulator: http://localhost:8080/" diff --git a/stop-app.sh b/stop-app.sh new file mode 100755 index 0000000..9d4cb3a --- /dev/null +++ b/stop-app.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash +set -e +echo "⏹ Shutting down all containers..." +docker-compose down +echo "✅ Stopped."