Skip to content

Commit

Permalink
Show running status as icon, only appropriate actions
Browse files Browse the repository at this point in the history
  • Loading branch information
dave-lang committed May 23, 2024
1 parent 77bb545 commit 5659f19
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 7 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ Once installed a new option 'Docker Containers' will appear in the menu under 'S

Docker configuration has been setup to allow easier development.

This environment has webmin and docker already installed, along with a very basic Ubuntu 18 docker config ready to start in the container (Docker in Docker).
This environment has Webmin and Docker already installed, along with a very basic Ubuntu 18 docker config ready to start in the container (Docker in Docker).

The plugin is installed in the Webmin environment via shared folder, changes will appear immediately.

1. `cd tools`
2. `docker-compose up -d` to run docker compose as daemon
3. Open http://localhost:10000 to access the webmin console
4. Login is `root` + `password`, this can be adjusted in the Dockerfile

To burn and recreate the environment use `docker-compose down -v`

Use `docker exec -it webmin_master /bin/bash` to get a SSH console.

Expand Down
23 changes: 23 additions & 0 deletions docker/docker-lib.pl
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,27 @@ sub circular_grid

# return ui_grid_table(\@stats, 1);
return $result;
}

sub starts_with
{
my ($str, $prefix) = @_;
return substr($str, 0, length($prefix)) eq $prefix;
}

sub get_container_up
{
my ($status) = @_;
return starts_with($status, "Up ");
}

sub get_status_icon
{
my ($status) = @_;

my ($up) = get_container_up($status);
my ($color) = $up ? 'green' : 'red';

return '<span style="font-weight: bold; font-size: 140%; color: ' . $color . '; float: left; padding-right: 10px">'
. ($up ? "&check;" : "&cross;") . '</span>';
}
22 changes: 18 additions & 4 deletions docker/index.cgi
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,30 @@ if ($fail) {
print &ui_submit(text('label_refresh'));
print &ui_form_end(),"<br>\n";

print ui_columns_start([&text('label_name'), &text('label_label'), &text('label_runningfor'), &text('label_cpu'), &text('label_mem'), ' ' ]);
print '<style>.panel-body tr td { padding: 5px 22px 7px 22px !important} </style>';
print ui_columns_start([
&text('label_name'),
&text('label_label'),
&text('label_running'),
&text('label_runningfor'),
&text('label_cpu'),
&text('label_mem'),
' '
]);

foreach my $u (@containers) {
my ($status) = $u->{'status'};

print ui_columns_row([
html_escape($u->{'name'}),
html_escape($u->{'image'}),
html_escape($u->{'status'}),
get_status_icon($status),
html_escape($status),
html_escape($stats{$u->{'id'}}{'cpu'}),
html_escape($stats{$u->{'id'}}{'memUsage'}) . " (" . html_escape($stats{$u->{'id'}}{'mem'}) . ")",
sprintf("<a href='command.cgi?c=start&container=%s'>%s</a>", urlize($u->{'name'}), &text('label_start')),
sprintf("<a href='command.cgi?c=stop&container=%s'>%s</a>", urlize($u->{'name'}), &text('label_stop')),
get_container_up($status) ?
sprintf("<a href='command.cgi?c=stop&container=%s'>%s</a>", urlize($u->{'name'}), &text('label_stop'))
: sprintf("<a href='command.cgi?c=start&container=%s'>%s</a>", urlize($u->{'name'}), &text('label_start')),
sprintf("<a href='command.cgi?c=restart&container=%s'>%s</a>", urlize($u->{'name'}), &text('label_restart')),
&ui_link('container.cgi?tab=log&container=' . urlize($u->{'id'}), 'View log'),
&ui_link('container.cgi?tab=inspect&container=' . urlize($u->{'id'}), 'Inspect')
Expand Down
1 change: 1 addition & 0 deletions docker/lang/en
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ command_err=Command could not be run

label_name=Name
label_label=Label
label_running=Running
label_runningfor=Running for
label_cpu=CPU
label_mem=MEM
Expand Down
2 changes: 0 additions & 2 deletions tools/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ services:
build:
context: ./
volumes:
#- ../nut/:/etc/webmin/nut:rw
#- ../pihole:/etc/webmin/pihole:rw
- ../docker:/usr/share/webmin/docker:rw
- ./dind:/home/dind:rw
ports:
Expand Down

0 comments on commit 5659f19

Please sign in to comment.