Skip to content

Commit

Permalink
wip: more swarm helpers & doc [skip build]
Browse files Browse the repository at this point in the history
  • Loading branch information
robinbourianes-kalisio committed Mar 19, 2021
1 parent 450749f commit 76b90e9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 5 deletions.
20 changes: 16 additions & 4 deletions docs/reference/scripts-library.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,26 @@ Usage: `notify_slack_danger <message>`

## swarm

### this_swarm_node
### all_swarm_nodes

Print the name of the runngin node.
Print the name of all the nodes in the swarm

Usage: `THIS=$(this_swarm_node)`
Usage: `ALL=$(all_swarm_nodes)`

### docker_id_from_name

Print the id of the docker with a matching name

Usage: `DOCKER_ID=$(docker_id_from_name mapserver)`

### other_swarm_nodes

Print the name of the other nodes in the swarm.
Print the name of the all nodes in the swarm minus the node we're running on.

Usage: `OTHER=$(other_swarm_nodes)`

### this_swarm_node

Print the name of the running node.

Usage: `THIS=$(this_swarm_node)`
11 changes: 10 additions & 1 deletion scripts/swarm.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@ this_swarm_node() {
uname -n
}

all_swarm_nodes() {
docker node ls --format "{{.Hostname}}"
}

other_swarm_nodes() {
docker node ls | grep Ready | grep -v $(this_swarm_node) | awk '{ print $2 }'
docker node ls --format "{{.Hostname}}" | grep -v $(this_swarm_node)
}

docker_id_from_name() {
local NAME=$1
docker ps --filter "status=running" --filter "name=${NAME}" --format "{{.ID}}" | head -1
}

0 comments on commit 76b90e9

Please sign in to comment.