Skip to content

Commit

Permalink
1.5.8 (#26)
Browse files Browse the repository at this point in the history
* Bumped version to 1.5.8

* Create temp .env file during compose deployments

* Use --env-file instead of environment vars to compose

* Display volume status (In use/unused)

* Network inUse. Hide delete button for inUse items in all types.
  • Loading branch information
salilponde authored Jan 1, 2024
1 parent 58b4878 commit a696ebd
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
branches: ["main"]

env:
VERSION: "1.5.7"
VERSION: "1.5.8"

jobs:
docker:
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/common.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package common

const Version = "1.5.7"
const Version = "1.5.8"
51 changes: 31 additions & 20 deletions pkg/dockerapi/compose.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,27 +195,43 @@ func ComposeLogs(req *DockerComposeLogs, ws *websocket.Conn) error {
return nil
}

func createTempComposeFile(projectName string, definition string) (string, string, error) {
func createTempComposeFile(projectName string, definition string, variables map[string]store.VariableValue) (string, string, string, error) {
dir, err := os.MkdirTemp("", projectName)
if err != nil {
log.Error().Err(err).Msg("Error while creating temp directory for compose")
return "", "", err
return "", "", "", err
}

filename := filepath.Join(dir, "compose.yaml")
composeFile, err := os.Create(filename)
composeFilename := filepath.Join(dir, "compose.yaml")
composeFile, err := os.Create(composeFilename)
if err != nil {
log.Error().Err(err).Msg("Error while creating temp compose file")
return "", "", err
return "", "", "", err
}

_ , err = composeFile.WriteString(definition)
if err != nil {
log.Error().Err(err).Msg("Error while writing to temp compose file")
return "", "", err
return "", "", "", err
}

return dir, filename, nil
envFilename := filepath.Join(dir, ".env")
envFile, err := os.Create(envFilename)
if err != nil {
log.Error().Err(err).Msg("Error while creating temp compose file")
return "", "", "", err
}

envVars := toEnvFormat(variables)
for _, v := range envVars {
_ , err = envFile.WriteString(v + "\r\n")
if err != nil {
log.Error().Err(err).Msg("Error while writing to temp .env file")
return "", "", "", err
}
}

return dir, composeFilename, envFilename, nil
}

func toEnvFormat(variables map[string]store.VariableValue) ([]string) {
Expand All @@ -230,8 +246,7 @@ func toEnvFormat(variables map[string]store.VariableValue) ([]string) {
return ret
}

func processVars(cmd *exec.Cmd, variables map[string]store.VariableValue, ws *websocket.Conn, print bool) {
cmd.Env = os.Environ()
func logVars(cmd *exec.Cmd, variables map[string]store.VariableValue, ws *websocket.Conn, print bool) {
if print {
ws.WriteMessage(websocket.TextMessage, []byte("*** SETTING BELOW VARIABLES: ***\n\n"))
}
Expand All @@ -251,35 +266,31 @@ func processVars(cmd *exec.Cmd, variables map[string]store.VariableValue, ws *we
ws.WriteMessage(websocket.TextMessage, []byte(fmt.Sprintf("%s=%s\n", k, val)))
}
}

for _, v := range toEnvFormat(variables) {
cmd.Env = append(cmd.Env, v)
}
}

func performComposeAction(action string, projectName string, definition string, variables map[string]store.VariableValue, ws *websocket.Conn, printVars bool) error {
dir, file, err := createTempComposeFile(projectName, definition)
log.Debug().Str("fileName", file).Msg("Created temporary compose file")
dir, composefile, envfile, err := createTempComposeFile(projectName, definition, variables)
log.Debug().Str("composeFileName", composefile).Str("envFileName", envfile).Msg("Created temporary compose file and .env file")
if err != nil {
return err
}
defer func() {
log.Debug().Str("fileName", file).Msg("Deleting temporary compose file")
log.Debug().Str("fileName", composefile).Msg("Deleting temporary compose file and .env file")
os.RemoveAll(dir)
}()

var cmd *exec.Cmd
switch action {
case "up":
cmd = exec.Command("docker-compose", "-p", projectName, "-f", file, action, "-d")
cmd = exec.Command("docker-compose", "-p", projectName, "--env-file", envfile, "-f", composefile, action, "-d")
case "down":
cmd = exec.Command("docker-compose", "-p", projectName, action)
cmd = exec.Command("docker-compose", "-p", projectName, "--env-file", envfile, action)
case "pull":
cmd = exec.Command("docker-compose", "-p", projectName, "-f", file, action)
cmd = exec.Command("docker-compose", "-p", projectName, "--env-file", envfile, "-f", composefile, action)
default:
panic(fmt.Errorf("unknown compose action %s", action))
}
processVars(cmd, variables, ws, printVars)
logVars(cmd, variables, ws, printVars)

ws.WriteMessage(websocket.TextMessage, []byte(fmt.Sprintf("\n*** STARTING ACTION: %s ***\n\n", action)))
f, err := pty.Start(cmd)
Expand Down
2 changes: 1 addition & 1 deletion pkg/dockerapi/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func ImageList(req *DockerImageList) (*DockerImageListResponse, error) {
return nil, err
}

dcontainers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{All: req.All})
dcontainers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{All: true})
if err != nil {
return nil, err
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/dockerapi/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ type DockerVolumeList struct {
}

type Volume struct {
Driver string `json:"driver"`
Name string `json:"name"`
Driver string `json:"driver"`
Name string `json:"name"`
InUse bool `json:"inUse"`
}

type DockerVolumeListResponse struct {
Expand Down Expand Up @@ -131,6 +132,7 @@ type Network struct {
Name string `json:"name"`
Driver string `json:"driver"`
Scope string `json:"scope"`
InUse bool `json:"inUse"`
}

type DockerNetworkListResponse struct {
Expand Down
16 changes: 16 additions & 0 deletions pkg/dockerapi/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,34 @@ func NetworkList(req *DockerNetworkList) (*DockerNetworkListResponse, error) {
return nil, err
}

dcontainers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{All: true})
if err != nil {
return nil, err
}

usedNetworks := make(map[string]interface{}, 0)
for _, c := range dcontainers {
if c.NetworkSettings != nil {
for _, n := range c.NetworkSettings.Networks {
usedNetworks[n.NetworkID] = nil
}
}
}

dnetworks, err := cli.NetworkList(context.Background(), types.NetworkListOptions{})
if err != nil {
return nil, err
}

networks := make([]Network, len(dnetworks))
for i, item := range dnetworks {
_, inUse := usedNetworks[item.ID]
networks[i] = Network{
Id: item.ID,
Name: item.Name,
Driver: item.Driver,
Scope: item.Scope,
InUse: inUse,
}
}

Expand Down
20 changes: 19 additions & 1 deletion pkg/dockerapi/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"context"
"sort"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/filters"
"github.com/docker/docker/api/types/mount"
"github.com/docker/docker/api/types/volume"
"github.com/docker/docker/client"
)
Expand All @@ -15,16 +17,32 @@ func VolumeList(req *DockerVolumeList) (*DockerVolumeListResponse, error) {
return nil, err
}

dcontainers, err := cli.ContainerList(context.Background(), types.ContainerListOptions{All: true})
if err != nil {
return nil, err
}

usedVolumes := make(map[string]interface{}, 0)
for _, c := range dcontainers {
for _, m := range c.Mounts {
if m.Type == mount.TypeVolume {
usedVolumes[m.Name] = nil
}
}
}

dvolumes, err := cli.VolumeList(context.Background(), volume.ListOptions{})
if err != nil {
return nil, err
}

volumes := make([]Volume, len(dvolumes.Volumes))
for i, item := range dvolumes.Volumes {
_, inUse := usedVolumes[item.Name]
volumes[i] = Volume{
Driver: item.Driver,
Name: item.Name,
InUse: inUse,
}
}

Expand Down Expand Up @@ -56,7 +74,7 @@ func VolumesPrune(req *DockerVolumesPrune) (*DockerVolumesPruneResponse, error)
}

all := "true"
if req.All {
if !req.All {
all = "false"
}
allFilter := filters.KeyValuePair{Key: "all", Value: all}
Expand Down
2 changes: 1 addition & 1 deletion pkg/server/handler/request_docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func (r *dockerContainerRemoveRequest) bind(c echo.Context, m *dockerapi.DockerC

type dockerImageRemoveRequest struct {
Id string `json:"id" validate:"required,max=100"`
Force bool `json:"force" validate:"required"`
Force bool `json:"force"`
}

func (r *dockerImageRemoveRequest) bind(c echo.Context, m *dockerapi.DockerImageRemove) error {
Expand Down
16 changes: 9 additions & 7 deletions web/src/app/images/image-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export default function ImageList() {
{
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ id: image?.id, force: true }),
body: JSON.stringify({ id: image?.id, force: false }),
}
)
if (!response.ok) {
Expand Down Expand Up @@ -162,12 +162,14 @@ export default function ImageList() {
<TableCell>{item.inUse ? "In use" : "Unused"}</TableCell>
<TableCell>{convertByteToMb(item.size)}</TableCell>
<TableCell className="text-right">
<TableButtonDelete
onClick={(e) => {
e.stopPropagation()
handleDeleteImageConfirmation(item)
}}
/>
{!item.inUse && (
<TableButtonDelete
onClick={(e) => {
e.stopPropagation()
handleDeleteImageConfirmation(item)
}}
/>
)}
</TableCell>
</TableRow>
))}
Expand Down
25 changes: 19 additions & 6 deletions web/src/app/networks/network-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@ import { toastFailed, toastSuccess } from "@/lib/utils"
import apiBaseUrl from "@/lib/api-base-url"
import DeleteDialog from "@/components/delete-dialog"

const systemNetwoks = [
"none",
"bridge",
"host",
"ingress",
"docker_gwbridge",
"docker_volumes-backup-extension-desktop-extension_default",
]

export default function NetworkList() {
const { nodeId } = useParams()
const { nodeHead } = useNodeHead(nodeId!)
Expand Down Expand Up @@ -137,6 +146,7 @@ export default function NetworkList() {
<TableHead scope="col">Name</TableHead>
<TableHead scope="col">Driver</TableHead>
<TableHead scope="col">Scope</TableHead>
<TableHead scope="col">Status</TableHead>
<TableHead scope="col">
<span className="sr-only">Actions</span>
</TableHead>
Expand All @@ -151,13 +161,16 @@ export default function NetworkList() {
<TableCell>{item.name}</TableCell>
<TableCell>{item.driver}</TableCell>
<TableCell>{item.scope}</TableCell>
<TableCell>{item.inUse ? "In use" : "Unused"}</TableCell>
<TableCell className="text-right">
<TableButtonDelete
onClick={(e) => {
e.stopPropagation()
handleDeleteNetworkConfirmation(item)
}}
/>
{!systemNetwoks.includes(item.name) && !item.inUse && (
<TableButtonDelete
onClick={(e) => {
e.stopPropagation()
handleDeleteNetworkConfirmation(item)
}}
/>
)}
</TableCell>
</TableRow>
))}
Expand Down
16 changes: 10 additions & 6 deletions web/src/app/volumes/volume-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ export default function VolumeList() {
<TableRow>
<TableHead scope="col">Driver</TableHead>
<TableHead scope="col">Name</TableHead>
<TableHead scope="col">Status</TableHead>
<TableHead scope="col">
<span className="sr-only">Actions</span>
</TableHead>
Expand All @@ -151,13 +152,16 @@ export default function VolumeList() {
<TableRow key={item.name}>
<TableCell>{item.driver}</TableCell>
<TableCell>{item.name}</TableCell>
<TableCell>{item.inUse ? "In use" : "Unused"}</TableCell>
<TableCell className="text-right">
<TableButtonDelete
onClick={(e) => {
e.stopPropagation()
handleDeleteVolumeConfirmation(item)
}}
/>
{!item.inUse && (
<TableButtonDelete
onClick={(e) => {
e.stopPropagation()
handleDeleteVolumeConfirmation(item)
}}
/>
)}
</TableCell>
</TableRow>
))}
Expand Down
2 changes: 2 additions & 0 deletions web/src/lib/api-models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,15 @@ export interface IImage {
export interface IVolume {
driver: string
name: string
inUse: boolean
}

export interface INetwork {
id: string
name: string
driver: string
scope: string
inUse: boolean
}

export interface IComposeLibraryItemHead {
Expand Down
2 changes: 1 addition & 1 deletion web/src/lib/version.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const VERSION = "1.5.7"
export const VERSION = "1.5.8"

0 comments on commit a696ebd

Please sign in to comment.