Skip to content
This repository has been archived by the owner on Oct 4, 2023. It is now read-only.

Add den status command #94

Merged
merged 7 commits into from
Oct 14, 2022
Merged

Add den status command #94

merged 7 commits into from
Oct 14, 2022

Conversation

bap14
Copy link

@bap14 bap14 commented Oct 11, 2022

Adds a new status command showing the current projects that are running and Den's Traefik instance is connected to.
Screen Shot 2022-10-11 at 7 18 46 PM

@navarr
Copy link

navarr commented Oct 12, 2022

I love the idea, but I'm unsure how good or bad of a decision it is to add python3 as a requirement to Den.

@navarr navarr self-requested a review October 12, 2022 13:09
@navarr navarr added the enhancement New feature or request label Oct 12, 2022
@navarr navarr added this to the v1 milestone Oct 12, 2022
@LeeSaferite
Copy link

LeeSaferite commented Oct 12, 2022

Given that den is using docker, why not simply use docker to run the python command? Or rewrite it to use jq and still use docker to run the command.

@bap14
Copy link
Author

bap14 commented Oct 12, 2022

@LeeSaferite The idea was to use tools already available on the Mac without adding external dependencies, as well as not having to download another docker container to parse JSON.

I'll give some alternatives a try (jq docker, python docker, manually parsing via bash).

@navarr Python should already be available on MacOS. I have Xcode tools installed so Python3 is also available (though the syntax only changes a little bit between 2 and 3). But as Lee pointed out, I'll research alternatives.

@navarr
Copy link

navarr commented Oct 12, 2022

@navarr Python should already be available on MacOS. I have Xcode tools installed so Python3 is also available (though the syntax only changes a little bit between 2 and 3). But as Lee pointed out, I'll research alternatives.

It is, and while Mac is the primary target at SO, Den supports Linux and Windows as well.

@bap14
Copy link
Author

bap14 commented Oct 12, 2022

I'll have a fix for this later this evening. I think i just need to step up my Golang template fu and I can completely remove the Python scripts.

@bap14
Copy link
Author

bap14 commented Oct 12, 2022

@navarr Removed python as dependency, also changed the output to add more information about the project (Traefik domain).

@bap14
Copy link
Author

bap14 commented Oct 13, 2022

Here's a screenshot of the new output.
Capto_Capture 2022-10-13_06-44-29_AM

@navarr
Copy link

navarr commented Oct 13, 2022

This doesn't appear to be working for me.

First off, versions. I'm running off your latest commit to this branch.

navarr@Navarrs-MBP-2 den % docker version;docker compose version
Client:
 Cloud integration: v1.0.29
 Version:           20.10.17
 API version:       1.41
 Go version:        go1.17.11
 Git commit:        100c701
 Built:             Mon Jun  6 23:04:45 2022
 OS/Arch:           darwin/arm64
 Context:           default
 Experimental:      true

Server: Docker Desktop 4.12.0 (85629)
 Engine:
  Version:          20.10.17
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.17.11
  Git commit:       a89b842
  Built:            Mon Jun  6 23:01:01 2022
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.6.8
  GitCommit:        9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
Docker Compose version v2.10.2
navarr@Navarrs-MBP-2 den % den status
Template parsing error: template: :1:46: executing "" at <slice $v.Name 0 12>: error calling slice: index out of range: 12
ERROR: Command `projectContainers=$(docker network inspect --format '{{ range $k,$v := .Containers }}{{ $prefix := slice $v.Name 0 '"${prefixLen}"' }}{{ if eq $prefix "'"${prefix}-"'" }}{{ println $v.Name }}{{end}}{{end}}' "${projectNetwork}")` at /Users/navarr/IdeaProjects/den/commands/status.cmd:22 failed with exit code 1
navarr@Navarrs-MBP-2 den % echo $projectNetworkList
gsg-current_default
gsg24_default
gsg_default
mwi_default
perforce_default
warden
znd-magento2_default
navarr@Navarrs-MBP-2 den % echo $prefix

navarr@Navarrs-MBP-2 den % echo $prefixLen
1
navarr@Navarrs-MBP-2 den % docker network inspect --format '{{ range $k,$v := .Containers }}{{ $prefix := slice $v.Name 0 '"${prefixLen}"' }}{{ if eq $prefix "'"${prefix}-"'" }}{{ println $v.Name }}{{end}}{{end}}' "${projectNetwork}"

Error: No such network:

Is what I try to get running it outside of den

Any additional things I can do to get more information for you?

@bap14
Copy link
Author

bap14 commented Oct 13, 2022

@navarr Submitted a fix. I use simple 3-letter environment names, so my "prefix" is always shorter than the den core container names (traefik, mailhog, etc.).

The issue was in longer names (e.g. znd-magento2) that prefix was longer than those core container names, causing the out of bounds error. I added a quick length check so only container names that are longer than the prefix are checked (which should be all the environment-specific containers).

There is still room for improvement (e.g. what if I specify the container name in a custom warden-env.yml file), but that adds to the complexity of this, and BASH is a limiting language (in some ways).

@navarr navarr merged commit befb7cc into swiftotter:main Oct 14, 2022
@ihor-sviziev
Copy link

Great idea, but 2 things I would improve:

  1. it's not showing not "running" enviroments
  2. there no mentions of this new command in https://github.com/swiftotter/den/blob/main/commands/usage.help#L23-L33

@navarr
Copy link

navarr commented Oct 17, 2022

@ihor-sviziev Thanks for the comment!

I've gone ahead and resolved improvement 2. I do think improvement 1 might be fairly difficult. One reason I like this command is because I'll commonly want to know which environments I have running so I can shut them down, so it remains useful to me with or without improvement 1.

@bap14
Copy link
Author

bap14 commented Oct 17, 2022

@ihor-sviziev Yeah, I was thinking about that. Initially I was going to say during the den env up and den env init a file would be created in the home directory keeping a tab of available environments and those that are running; however, that didn't feel clean to me (though may be the only way to do it).

@navarr
Copy link

navarr commented Oct 17, 2022

@bap14 Honestly I'm not a fan of that either. Far too many ways that it can get out-of-sync.

@bap14 bap14 deleted the feature/status-command branch October 17, 2022 17:12
navarr added a commit to wardenenv/warden that referenced this pull request Jun 19, 2023
Ported in from swiftotter#94

Co-authored-by: Brett Patterson <brett.patterson@classyllama.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
Archived in project
4 participants