Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix tty:true containers. Add GHA push workflow. #1

Merged
merged 5 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Push

on:
push: {}
pull_request:
branches: [ main ]
workflow_dispatch: {}

jobs:
compose-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3

- name: npm install
run: npm install

- name: Startup compose example
timeout-minutes: 2
run: time docker compose -p dcmon-test -f examples/docker-compose.yaml up -d

- name: dcmon
timeout-minutes: 5
run: |
time ./dcmon --no-tui --show-events all dcmon-test ./examples/checks.yaml

- name: dcmon final state
if: always()
timeout-minutes: 1
run: |
export FORCE_COLOR=1
./dcmon --static-once dcmon-test ./examples/checks.yaml
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Monitor docker-compose services.

```
npm install
./node_modules/.bin/nbb -cp src/ -m dcmon.core PROJECT ./checks.yaml
./dcmon PROJECT ./checks.yaml
```

* Compile and run with shadow-cljs:
Expand Down Expand Up @@ -38,7 +38,7 @@ In one terminal, launch dcmon as described above using a PROJECT value
of `${USER}-test`. For example, to use nbb directly:

```
./node_modules/.bin/nbb -cp src/ -m dcmon.core ${USER}-test ./examples/checks.yaml
./dcmon ${USER}-test ./examples/checks.yaml
```


Expand Down
10 changes: 8 additions & 2 deletions examples/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,14 @@ checks:
- {id: "Line 10", regex: "Line 10\\b"}
- {id: "Line 15", regex: "Line 15\\b"}
- {id: "Line 20", regex: "Line 20\\b"}
- {id: "ping", cmd: "ping -c 1 8.8.8.8",
- {id: "ping", cmd: "ping -c 1 final",
deps: {counter: "Line 20"}}

with_tty:
- {id: "Started", regex: "Started"}
- {id: "Line 10", regex: "Line 10\\b"}
- {id: "Line 20", regex: "Line 20\\b"}

delay30:
- {id: "Started", regex: "Started"}
- {noop: true}
Expand All @@ -46,8 +51,9 @@ checks:
- {noop: true}
- {noop: true}
- {noop: true}
- {id: "ping", cmd: "ping -c 1 8.8.8.8",
- {id: "ping", cmd: "ping -c 1 counter",
deps: {scale: "Started",
counter: "ping",
with_tty: "Line 20",
delay30: "Done",
final: "Started"}}
5 changes: 5 additions & 0 deletions examples/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ services:
image: alpine
command: sh -c 'echo "Started"; i=0; while true; do echo "Line $$i"; sleep 1; i=$$(( i + 1 )); done'

with_tty:
image: alpine
tty: true
command: sh -c 'echo "Started"; i=0; while true; do echo "Line $$i"; sleep 1; i=$$(( i + 1 )); done'

delay30:
image: alpine
command: sh -c 'echo "Started"; for i in $$(seq 30); do echo "i - $$i"; sleep 1; done; echo "Done"; sleep 99999'
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dcmon",
"version": "1.4",
"version": "1.5",
"description": "docker-compose monitor",
"dependencies": {
"dockerode": "^3.3.1",
Expand Down
11 changes: 7 additions & 4 deletions src/dcmon/core.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ Options:
(defn init-container
"[Async] Configure log monitoring for a newly detected or newly
running container. Resolves to the updated state of ctx."
[service cidx container status log-handler]
[service cidx container status tty log-handler]
(let [{:keys [services]} @ctx
old-stream (get-in services [service cidx :log-stream])
log-stream (doto (stream/PassThrough.)
Expand All @@ -452,8 +452,10 @@ Options:
:stdout true
:stderr true
:timestamps true})]
(-> (.-modem container)
(.demuxStream stream log-stream log-stream))
(if tty
(.pipe stream log-stream)
(-> (.-modem container)
(.demuxStream stream log-stream log-stream)))
(.on stream "end" #(.end log-stream "!stop!"))
(swap! ctx assoc-in [:services service cidx :log-stream] stream))))

Expand All @@ -469,14 +471,15 @@ Options:
inspect-raw (.inspect container)
inspect (->clj inspect-raw)
status (-> inspect :State :Status)
tty (-> inspect :Config :Tty)
service (keyword (-> inspect :Config :Labels :com.docker.compose.service))
cidx (js/parseInt (-> inspect :Config :Labels :com.docker.compose.container-number))
{:keys [services]} (ensure-service service cidx)]
(swap! ctx #(-> %
(assoc-in [:containers id] inspect)
(assoc-in [:services service cidx :id] id)))
(if init?
(init-container service cidx container status
(init-container service cidx container status tty
(partial docker-log-handler service cidx))
(event :container-update {:service service :cidx cidx :id id
:status status})))
Expand Down
Loading