Skip to content

Commit 5ca52a6

Browse files
authored
cli: Add missing function (#219)
1 parent 881f84d commit 5ca52a6

File tree

2 files changed

+73
-0
lines changed

2 files changed

+73
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ devops-toolkit-cli shell my_toolkit_01
9797

9898
```bash
9999
devops-toolkit-cli cleanup my_toolkit_01
100+
# Run 'devops-toolkit-cli list' to list all available containers
100101
# Run 'devops-toolkit-cli cleanup --all' to cleanup all devops-toolkit containers
101102
```
102103

devops-toolkit-cli

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,78 @@ start_container() {
106106
fi
107107
}
108108

109+
110+
update() {
111+
local container_name="$1"
112+
local version="$2"
113+
local new_image
114+
115+
if [ -z "$version" ]; then
116+
new_image="${DOCKER_IMAGE%:*}:latest"
117+
log $BLUE "Updating $container_name to the latest version..."
118+
else
119+
new_image="${DOCKER_IMAGE%:*}:$version"
120+
log $BLUE "Updating $container_name to version $version..."
121+
fi
122+
123+
if [ "$new_image" == "$DOCKER_IMAGE" ]; then
124+
if is_image_up_to_date "$new_image"; then
125+
log $YELLOW "The specified image ($new_image) is already in use and up-to-date. No update needed."
126+
return
127+
else
128+
log $BLUE "The specified image ($new_image) is in use but outdated. Updating..."
129+
fi
130+
fi
131+
132+
pull_image "$new_image"
133+
cleanup "$container_name"
134+
DOCKER_IMAGE="$new_image"
135+
start_container "$DOCKER_IMAGE" "$container_name"
136+
add_container "$container_name"
137+
log $GREEN "Update completed successfully for $container_name. New image: $DOCKER_IMAGE"
138+
}
139+
140+
version() {
141+
local container_name="$1"
142+
log $BLUE "DevOps Toolkit Version Information for $container_name:"
143+
log $GREEN "Current Docker Image: $DOCKER_IMAGE"
144+
if docker inspect --type=container "$container_name" > /dev/null 2>&1; then
145+
local container_image=$(docker inspect --format='{{.Config.Image}}' "$container_name")
146+
log $GREEN "Running Container Image: $container_image"
147+
else
148+
log $YELLOW "No running container found for $container_name."
149+
fi
150+
}
151+
152+
list_versions() {
153+
log $BLUE "Available versions of DevOps Toolkit:"
154+
local repo="${DOCKER_IMAGE%:*}"
155+
curl -s "https://registry.hub.docker.com/v2/repositories/${repo}/tags?page_size=100" | \
156+
jq -r '.results[].name' | sort -V
157+
}
158+
159+
health_check() {
160+
local container_name="$1"
161+
if docker inspect --type=container "$container_name" > /dev/null 2>&1; then
162+
local status=$(docker inspect --format='{{.State.Status}}' "$container_name")
163+
local health=$(docker inspect --format='{{.State.Health.Status}}' "$container_name")
164+
log $GREEN "Container Status for $container_name: $status"
165+
log $GREEN "Container Health for $container_name: ${health:-N/A}"
166+
else
167+
log $RED "Container $container_name does not exist."
168+
fi
169+
}
170+
171+
show_logs() {
172+
local container_name="$1"
173+
if docker inspect --type=container "$container_name" > /dev/null 2>&1; then
174+
docker logs "$container_name"
175+
else
176+
log $RED "Container $container_name does not exist."
177+
fi
178+
}
179+
180+
109181
exec_in_container() {
110182
local container_name="$1"
111183
shift

0 commit comments

Comments
 (0)