Files
sablier-example/README.md
2024-08-30 15:36:33 +08:00

6.7 KiB

sablier-example

docker compose create
docker compose up -d sablier proxy
curl http://localhost:8080/whoami; echo -e "\n等待启动完成"; sleep 3; curl http://localhost:8080/whoami;
root@Airoli-Maharashtra-IN-150-230:~/_docker-stacks/sablier-example# docker compose create
[+] Creating 5/4
 ✔ Network sablier-example_default                                                                                                                       Created                    0.1s 
 ✔ Container sablier-example-proxy-1                                                                                                                     Created                    0.1s 
 ✔ Container sablier-example-whoami-1                                                                                                                    Created                    0.1s 
 ✔ Container sablier-example-sablier-1                                                                                                                   Created                    0.1s 
 ! whoami The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested                            0.0s 
root@Airoli-Maharashtra-IN-150-230:~/_docker-stacks/sablier-example# docker compose up -d sablier proxy
[+] Running 2/2
 ✔ Container sablier-example-proxy-1    Started                                                                                                                                     0.3s 
 ✔ Container sablier-example-sablier-1  Started                                                                                                                                     0.3s 
root@Airoli-Maharashtra-IN-150-230:~/_docker-stacks/sablier-example# curl http://localhost:8080/whoami; echo -e "\n等待启动完成"; sleep 3; curl http://localhost:8080/whoami;
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="robots" content="noindex, nofollow"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta http-equiv="refresh" content="1" />
    <title>Sablier</title>
    <style>
        html, body {
            margin: 0;
            background-color: #222;
            color: #aaa;
            font-family: 'Hack', monospace;
            font-size: 0;
        }

        .full-height {
            height: 100vh;
        }

        .flex-center {
            align-items: center;
            display: flex;
            justify-content: center;
        }

        #error_text {
            font-size: 32px;
        }

        #details table {
            width: 100%;
            border-collapse: collapse;
            box-sizing: border-box;
            margin-top: 20px;
        }

        #details.hidden td {
            opacity: 0;
            font-size: 0;
            color: #222;
        }

        #details td {
            font-size: 11px;
            color: #999;
            padding-top: .5em;
            transition: opacity 1s, font-size .3s, color 1.2s;
            opacity: 1;
        }

        #details td.name {
            text-align: right;
            padding-right: .3em;
            width: 50%;
        }

        #details td.value {
            text-align: left;
            padding-left: .3em;
            font-family: 'Lucida Console', 'Courier New', monospace;
        }

        #details td.value.success {
            color: rgb(50, 209, 106)
        }

        #details td.value.error {
            color: rgb(195, 41, 41)
        }
    </style>
</head>
<body>
<div class="flex-center full-height">
    <div>
        <div id="error_text">
            <span class="source">Starting <span>My Whoami Service...</span></span>
            <span class="target"></span>
        </div>
        <div class="hidden" id="details">
            <table>
                <tr>
                    <td class="name">sablier-example-whoami-1</td>
                    <td class="value success">not-ready (0/1)</td>
                </tr>
                </table>
        </div>
    </div>
</div>

<script>
    'use strict';

    

    const Shuffle = function ($el) {
        const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890-=+<>,./?[{()}]!@#$%^&*~`\|'.split(''),
            $source = $el.querySelector('.source'), $target = $el.querySelector('.target');

        let cursor = 0, scrambleInterval = undefined, cursorDelayInterval = undefined, cursorInterval = undefined;

        

        const getRandomizedString = function (len) {
            let s = '';

            for (let i = 0; i < len; i++) {
                s += chars[Math.floor(Math.random() * chars.length)];
            }

            return s;
        };

        this.start = function () {
            $source.style.display = 'none';
            $target.style.display = 'block';

            scrambleInterval = window.setInterval(() => {
                if (cursor <= $source.innerText.length) {
                    $target.innerText = $source.innerText.substring(0, cursor) + getRandomizedString($source.innerText.length - cursor);
                }
            }, 200 / 30);

            cursorDelayInterval = window.setTimeout(() => {
                cursorInterval = window.setInterval(() => {
                    if (cursor > $source.innerText.length - 1) {
                        this.stop();
                    }

                    cursor++;
                }, 40);
            }, 200);
        };

        this.stop = function () {
            $source.style.display = 'block';
            $target.style.display = 'none';
            $target.innerText = '';
            cursor = 0;

            if (scrambleInterval !== undefined) {
                window.clearInterval(scrambleInterval);
                scrambleInterval = undefined;
            }

            if (cursorInterval !== undefined) {
                window.clearInterval(cursorInterval);
                cursorInterval = undefined;
            }

            if (cursorDelayInterval !== undefined) {
                window.clearInterval(cursorDelayInterval);
                cursorDelayInterval = undefined;
            }
        };
    };

    (new Shuffle(document.getElementById('error_text'))).start();

    window.setTimeout(function () {
        document.getElementById('details').classList.remove('hidden');
    }, 200);
</script>
</body>
</html>
等待启动完成
Hostname: 15dc096e1bcf
IP: 127.0.0.1
IP: ::1
IP: 172.20.0.4
RemoteAddr: 172.20.0.3:39000
GET /whoami HTTP/1.1
Host: localhost:8080
User-Agent: curl/7.88.1
Accept: */*
Accept-Encoding: gzip
X-Forwarded-For: 172.20.0.1
X-Forwarded-Host: localhost:8080
X-Forwarded-Proto: http

root@Airoli-Maharashtra-IN-150-230:~/_docker-stacks/sablier-example#