mirror of
https://github.com/jpetazzo/container.training.git
synced 2026-07-18 20:39:17 +00:00
Put 'wait' and 'keys' HTML comments before the command they apply to. Add colored logs.
This commit is contained in:
@@ -7,6 +7,9 @@ import subprocess
|
||||
import sys
|
||||
import time
|
||||
|
||||
import coloredlogs, logging
|
||||
coloredlogs.install()
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
def hrule():
|
||||
@@ -95,25 +98,45 @@ except Exception as e:
|
||||
|
||||
keymaps = { "^C": "\x03" }
|
||||
|
||||
def wait_for_success():
|
||||
def wait_for_success(wait_for=None):
|
||||
secs, timeout = 0, 30
|
||||
while secs <= timeout:
|
||||
time.sleep(1)
|
||||
output = [x for x in subprocess.check_output(["tmux", "capture-pane", "-p"]).split("\n") if x]
|
||||
if wait_for and [x for x in output if wait_for in x]:
|
||||
return True
|
||||
if output[-1] == "$":
|
||||
return True
|
||||
else:
|
||||
print(".")
|
||||
secs += 1
|
||||
|
||||
wait_for, action, method = "", "", ""
|
||||
while True:
|
||||
with open("nextstep","w") as f:
|
||||
f.write(str(i))
|
||||
slide, snippet, method, data = actions[i]
|
||||
data = data.strip()
|
||||
|
||||
# Look behind at the last slide to see if 'wait' or 'keys' was defined.
|
||||
# If so, we need to wait for the specified output and/or terminate the command with the specified keys.
|
||||
if method == "wait":
|
||||
wait_for = data
|
||||
print("Setting wait_for to: {}".format(data))
|
||||
i += 1
|
||||
continue
|
||||
if method == "keys":
|
||||
action = data
|
||||
print("Setting action to: {}".format(data))
|
||||
i += 1
|
||||
continue
|
||||
print(hrule())
|
||||
print(slide.content.replace(snippet.content, ansi(7)(snippet.content)))
|
||||
print(hrule())
|
||||
if wait_for:
|
||||
print("waiting for: {}".format(wait_for))
|
||||
if action:
|
||||
print("action: {}".format(action))
|
||||
print("[{}] Shall we execute that snippet above?".format(i))
|
||||
command = raw_input()
|
||||
if command == "":
|
||||
@@ -125,8 +148,17 @@ while True:
|
||||
if method == "bash":
|
||||
data += "\n"
|
||||
subprocess.check_call(["tmux", "send-keys", "{}".format(data)])
|
||||
if not wait_for_success():
|
||||
print("WARNING /!\ Command timed out.")
|
||||
result = wait_for_success(wait_for=wait_for)
|
||||
if result is True:
|
||||
if action:
|
||||
subprocess.check_call(["tmux", "send-keys", "{}".format(action)])
|
||||
wait_for_success()
|
||||
# Unset wait_for and action so they don't carry over to the next loop.
|
||||
wait_for, action = "", ""
|
||||
elif result is False:
|
||||
logging.warning("Last command failed!")
|
||||
else:
|
||||
logging.warning("Last command timed out!")
|
||||
else:
|
||||
print "DO NOT KNOW HOW TO HANDLE {} {!r}".format(method, data)
|
||||
i += 1
|
||||
|
||||
@@ -135,6 +135,17 @@ Without further ado, let's start our application.
|
||||
cd ~/orchestration-workshop/dockercoins
|
||||
```
|
||||
|
||||
<!--
|
||||
```wait
|
||||
units of work done
|
||||
```
|
||||
|
||||
```keys
|
||||
^C
|
||||
```
|
||||
|
||||
-->
|
||||
|
||||
- Use Compose to build and run all containers:
|
||||
```bash
|
||||
docker-compose up
|
||||
@@ -160,17 +171,6 @@ and displays aggregated logs.
|
||||
|
||||
- Stop the application by hitting `^C`
|
||||
|
||||
<!--
|
||||
```wait
|
||||
units of work done
|
||||
```
|
||||
|
||||
```keys
|
||||
^C
|
||||
```
|
||||
|
||||
-->
|
||||
|
||||
]
|
||||
|
||||
- `^C` stops all containers by sending them the `TERM` signal
|
||||
@@ -215,17 +215,22 @@ class: extra-details
|
||||
docker-compose logs
|
||||
```
|
||||
|
||||
<!--
|
||||
```wait
|
||||
units of work done
|
||||
```
|
||||
|
||||
```keys
|
||||
^C
|
||||
```
|
||||
|
||||
-->
|
||||
|
||||
- Stream container logs, starting at the last 10 lines for each container:
|
||||
```bash
|
||||
docker-compose logs --tail 10 --follow
|
||||
```
|
||||
|
||||
<!--
|
||||
```keys
|
||||
^C
|
||||
```
|
||||
-->
|
||||
|
||||
]
|
||||
|
||||
Tip: use `^S` and `^Q` to pause/resume log output.
|
||||
@@ -319,22 +324,29 @@ class: extra-details
|
||||
- run `top` to see CPU and memory usage (you should see idle cycles)
|
||||
|
||||
<!--
|
||||
```wait
|
||||
Tasks
|
||||
```
|
||||
```keys ^C```
|
||||
|
||||
```bash
|
||||
top
|
||||
```
|
||||
|
||||
```keys ^C```
|
||||
-->
|
||||
|
||||
- run `vmstat 1` to see I/O usage (si/so/bi/bo)
|
||||
<br/>(the 4 numbers should be almost zero, except `bo` for logging)
|
||||
|
||||
<!--
|
||||
```wait
|
||||
memory
|
||||
```
|
||||
```keys ^C```
|
||||
```bash
|
||||
vmstat 1
|
||||
```
|
||||
|
||||
```keys ^C```
|
||||
-->
|
||||
|
||||
]
|
||||
|
||||
@@ -22,7 +22,10 @@ DEPENDENCIES="
|
||||
jq
|
||||
pssh
|
||||
wkhtmltopdf
|
||||
jinja2
|
||||
pdfkit
|
||||
man
|
||||
coloredlogs
|
||||
"
|
||||
|
||||
ENVVARS="
|
||||
|
||||
Reference in New Issue
Block a user