HUB
Sign inSign up

tebwritescode/flashgames-proxy

By tebwritescode

•Updated about 2 years ago

A Docker container providing a web interface to browse and play Flash game containers easily.

Image
Web servers
1

1.2K

tebwritescode/flashgames-proxy repository overview

⁠Flash Game Proxy

⁠Overview

Flash Game Proxy provides a web interface for selecting and accessing Flash game containers running in your Docker environment. It simplifies the process of playing Flash games through an easy-to-use dropdown menu and embedded iframe display.

⁠Features

  • Web Interface for Game Selection: A user-friendly interface for browsing and playing Flash games.
  • Automatic Game Discovery: The game selector is populated with available Flash game containers for quick access.
  • Responsive Iframe Display: Play games directly within the browser.
  • Expose Only One Port: Flash Game Proxy proxies Flash game containers, eliminating the need for each container to have exposed ports.

⁠Getting Started

Make sure that you deploy the Flash game containers and Flash Game Proxy in the same network. Flash Game Proxy scans the local network for labels that indicate inclusion for the proxy.

⁠Step 1: Pull the Image

Download the container image directly from Docker Hub:

docker pull tebwritescode/flashgames-proxy
⁠Step 2: Assign Labels to Containers

Add these environment variables to each Flash game container:

  • SERVICE_NAME=<NAME>
  • SERVICE_PATH=<IP>

Replace <NAME> with the name to display in the dropdown (using only a-z, A-Z, 0-9, -, _). Replace <IP> with the container's Docker IP or hostname (no ports, no http:// or https://).

⁠Example Flash Game Container YAML

Here's an example docker-compose configuration for a Flash game container to be included in the Flash Game Proxy:

flash_example_game:
  image: tebwritescode/flashcontainer
  container_name: "flash_example_game"
  volumes:
    - "/path/to/your/game.swf:/app/game.swf"
  networks:
    local_network:
      ipv4_address: "172.30.0.100"
  environment:
    - SERVICE_NAME=example_game_name
    - SERVICE_PATH=172.30.0.100
  restart: unless-stopped
⁠Explanation:
  • image: The Flash game container image.
  • container_name: Name of the container.
  • volumes: Maps the path to the SWF game file on the host to the container.
  • networks: Specifies the Docker network and IP address for the container.
  • environment:
    • SERVICE_NAME: The display name for the game in the proxy dropdown.
    • SERVICE_PATH: The IP address or hostname of the container for proxy access.
  • restart: Ensures the container restarts unless stopped manually.

Replace /path/to/your/game.swf, local_network, and example_game_name with your own paths, network, and game details.

⁠Step 3: Run the Proxy Container
⁠Using Docker Compose

Use this docker-compose.yml configuration for the Flash Game Proxy:

flashgames-proxy:
  image: tebwritescode/flashgames-proxy
  container_name: flashgames-proxy
  ports:
    - "8080:80"
  networks:
   local_network:
     ipv4_address: "172.30.0.101"
  restart: always

networks:
  local_network:
    driver: bridge
⁠Explanation:
  • ports: Maps port 8080 on the host to port 80 in the container for accessing the web interface.
  • networks: Statically assigns the IP 172.30.0.101 to the Flash Game Proxy container for consistency.

Deploy with:

docker-compose up -d
⁠Step 4: Access the Game Selector

Go to http://localhost:8080 in your browser to use the game selector. Choose a game from the dropdown and play it within the iframe.

⁠Screenshots

⁠Home Page

Home Page

⁠Game Display

Flash Game 1

Flash Game 2

Ruffle

⁠Example Container

The Flash Game Proxy pairs well with FlashContainer⁠, making it simple to set up and manage your Flash game collection.

⁠License

This project is licensed under the MIT License.


⁠Source

Dockerfile

# Start with an official Nginx image
FROM nginx:latest

# Install curl to query Docker API
RUN apt-get update && apt-get install -y curl jq && rm -rf /var/lib/apt/lists/*

# Copy the configuration files
COPY nginx.conf /etc/nginx/nginx.conf
# COPY default.conf /etc/nginx/main/default.conf
COPY entrypoint.sh /entrypoint.sh

# Remove default.conf file
RUN rm -rf /etc/nginx/conf.d/default.conf 

# Create index.html
RUN mkdir /etc/nginx/html
RUN touch /etc/nginx/html/index.html

# Make the entrypoint script executable
RUN chmod +x /entrypoint.sh

# Expose the port where the proxy will run
EXPOSE 80

# Run the entrypoint script
ENTRYPOINT ["/entrypoint.sh"]

default.conf

server {
    listen 80;

    # Include only location rules from `conf.d`
    include /etc/nginx/conf.d/*.conf;
}

nginx.conf

worker_processes auto;
events { worker_connections 1024; }

http {
    server {
        listen 80;

        # Include all configurations in the /etc/nginx/conf.d directory
        include /etc/nginx/conf.d/*.conf;
    }
}

entrypoint.sh

#!/bin/bash

echo "Waiting for other containers to start"
sleep 30s
echo "Starting..."

generate_configs() {
    # Start the HTML file with improved structure and styling
    cat <<EOL > /etc/nginx/html/index.html
<html>
<head>
    <title>Game Selector</title>
    <style>
        body { font-family: Arial, sans-serif; background-color: #f4f4f9; color: #333; margin: 0; }
        h1 { color: #4a90e2; font-size: 24px; margin: 0; padding: 15px 0; }
        .top-bar { display: flex; align-items: center; justify-content: center; padding: 10px; background-color: #4a90e2; color: white; }
        .dropdown { padding: 5px; font-size: 14px; margin-right: 10px; }
        .button { padding: 5px 10px; font-size: 14px; color: #4a90e2; background-color: #fff; border: 1px solid #4a90e2; border-radius: 4px; text-decoration: none; cursor: pointer; }
        .button:hover { background-color: #357ABD; color: #fff; }
        .iframe-container { width: 100%; height: 600px; padding: 0; box-sizing: border-box; display: flex; align-items: center; justify-content: center; background-color: #e9ecef; color: #6c757d; font-size: 18px; }
        iframe { width: 100%; height: 100%; border: none; display: none; }
    </style>
    <script>
        function getQueryParameter(param) {
            const urlParams = new URLSearchParams(window.location.search);
            return urlParams.get(param);
        }

        function loadGame() {
            const selector = document.getElementById('gameSelector');
            const iframe = document.getElementById('gameIframe');
            if (selector.value === "#") {
                iframe.style.display = "none";
                document.getElementById("iframeMessage").style.display = "flex";
            } else {
                iframe.src = selector.value;
                iframe.style.display = "block";
                document.getElementById("iframeMessage").style.display = "none";
            }
        }

        window.onload = function() {
            const gameParam = getQueryParameter('game');
            if (gameParam) {
                const selector = document.getElementById('gameSelector');
                for (let i = 0; i < selector.options.length; i++) {
                    if (selector.options[i].value === '/' + gameParam + '/') {
                        selector.selectedIndex = i;
                        loadGame();
                        break;
                    }
                }
            }
        };
    </script>
</head>
<body>
    <div class="top-bar">
        <select id="gameSelector" class="dropdown" onchange="loadGame()">
            <option value="#">Choose a game...</option>
EOL

    echo "Starting service discovery..."  # Debug statement

    # Temporary file to store game names and paths for sorting
    temp_file=$(mktemp)

    # Loop through all containers to collect game entries
    for container_id in $(curl -s --unix-socket /var/run/docker.sock http://localhost/containers/json | jq -r '.[] | .Id'); do
        ENV_VARS=$(curl -s --unix-socket /var/run/docker.sock http://localhost/containers/$container_id/json | jq -r '.Config.Env[]')

        SERVICE_NAME=""
        SERVICE_PATH=""

        # Extract SERVICE_NAME and SERVICE_PATH from environment variables
        for env in $ENV_VARS; do
            if [[ $env == SERVICE_NAME=* ]]; then
                SERVICE_NAME="${env#*=}"
            elif [[ $env == SERVICE_PATH=* ]]; then
                SERVICE_PATH="${env#*=}"
            fi
        done

        echo "Discovered container ID: $container_id, SERVICE_NAME: $SERVICE_NAME, SERVICE_PATH: $SERVICE_PATH"

        # Ensure both SERVICE_NAME and SERVICE_PATH are set and add to the temporary file
        if [[ -n "$SERVICE_NAME" && -n "$SERVICE_PATH" ]]; then
            echo "$SERVICE_NAME|$SERVICE_PATH" >> "$temp_file"

            # Create Nginx config for this service
            echo "location /$SERVICE_NAME/ {
                proxy_pass http://$SERVICE_PATH/;
                proxy_set_header Host \$host;
                proxy_set_header X-Real-IP \$remote_addr;
                proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
                proxy_set_header X-Forwarded-Proto \$scheme;

                # Remove the /SERVICE_NAME prefix from the URI
                rewrite ^/$SERVICE_NAME/(.*)$ /\$1 break;
            }" > /etc/nginx/conf.d/$SERVICE_NAME.conf
        fi
    done

    # Sort the temporary file alphabetically by SERVICE_NAME and append to HTML
    sort "$temp_file" | while IFS="|" read -r name path; do
        echo "<option value=\"/$name/\">$name</option>" >> /etc/nginx/html/index.html
    done

    # Close the HTML dropdown, add a button, and set up iframe with a placeholder message
    cat <<EOL >> /etc/nginx/html/index.html
        </select>
        <a href="/" class="button">Return to Game Selector</a>
    </div>
    <div class="iframe-container" id="iframeMessage">Please select a game</div>
    <div class="iframe-container">
        <iframe id="gameIframe" src="#" title="Game Display"></iframe>
    </div>
</body>
</html>
EOL

    # Clean up temporary file
    rm "$temp_file"

    echo "HTML generation complete. Final HTML content:"  
    cat /etc/nginx/html/index.html
}

generate_configs
nginx -g 'daemon off;'

Easily manage and play your Flash games with this intuitive web interface.

Tag summary
Recent tags
Content type
Image
Digest
sha256:879a6e1c3…
Size
70.2 MB
Last updated
about 2 years ago
docker pull tebwritescode/flashgames-proxy:latest