detached de5cd4b

Fix UI, Add Environment variables support for container creation process.

- Create textarea for environment variables in createcontainer.gohtml.
- Add backend support for processing environment variables from textarea in cmdparams.go.
- Include environment variables in the container creation process in containers.go.
- Refactor HTML classes for better readability in createcontainer.gohtml.
- Simplify select options for protocol in createcontainer.gohtml.
commit
de5cd4b3ca0a87b02968b6653d4c06d999230718
author
bnema · · 2023-10-04 15:08 UTC
parent
eb3ea65
signature
unsigned
3 files · +31 -13
M internal/templates/models/html/fragments/createcontainer.gohtml +19 -13
@@ -1,5 +1,6 @@
11 <div
2- class="flex flex-col md:flex-row space-y-4 md:space-y-0 md:space-x-4 flex-grow" hx-ext="response-targets"
2+ class="flex flex-col md:flex-row space-y-4 md:space-y-0 md:space-x-4 flex-grow"
3+ hx-ext="response-targets"
34 >
45 <!-- Left Side: Docker Run Options -->
56 <div class="flex-grow bg-slate-100 p-4 rounded-md">
@@ -54,12 +55,15 @@
5455 <!-- Protocol -->
5556 <div class="w-1/4">
5657 <label class="block">Protocol</label>
57- <select name="container_protocol" class="w-full p-4 rounded-md border-2 bg-slate-200 border-gray-300">
58- <option value="https" {{if eq .ContainerProtocol "https"}}selected{{end}}>https</option>
59- <option value="http" {{if eq .ContainerProtocol "http"}}selected{{end}}>http</option>
58+ <select
59+ name="container_protocol"
60+ class="w-full p-4 rounded-md border-2 bg-slate-200 border-gray-300"
61+ >
62+ <option value="https">https</option>
63+ <option value="http">http</option>
6064 </select>
6165 </div>
62-
66+
6367 <!-- Subdomain -->
6468 <div class="w-1/3">
6569 <label class="block">Subdomain</label>
@@ -70,7 +74,7 @@
7074 value="{{.ContainerSubdomain}}"
7175 />
7276 </div>
73-
77+
7478 <!-- Domain -->
7579 <div class="w-5/12">
7680 <label class="block">Domain</label>
@@ -108,17 +112,16 @@
108112 />
109113 </div>
110114
111- <!-- Environment Variables
112115 <div class="pb-4">
113116 <label class="block">Environment variables</label>
114117 <span class="text-gray-500">e.g. KEY=VALUE </span>
115- <input
116- type="text"
118+ <textarea
117119 name="environment_variables"
118120 class="w-full p-4 rounded-md"
119- value="{{.EnvironmentVariables}}"
120- /> -->
121-
121+ rows="4"
122+ >{{.EnvironmentVariables}}</textarea
123+ >
124+ </div>
122125 <!-- Restart: always/on-failure/only when stopped/never -->
123126 <div class="pb-4">
124127 <label class="block">Restart</label>
@@ -140,6 +143,9 @@
140143 class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
141144 />
142145 </form>
143- <div id="error-message-create-container-{{.ShortID}}" class="text-red-500"></div>
146+ <div
147+ id="error-message-create-container-{{.ShortID}}"
148+ class="text-red-500"
149+ ></div>
144150 </div>
145151 </div>
@@ -1,5 +1,6 @@
1 <div1 <div
2- class="flex flex-col md:flex-row space-y-4 md:space-y-0 md:space-x-4 flex-grow" hx-ext="response-targets"2+ class="flex flex-col md:flex-row space-y-4 md:space-y-0 md:space-x-4 flex-grow"
3+ hx-ext="response-targets"
3 >4 >
4 <!-- Left Side: Docker Run Options -->5 <!-- Left Side: Docker Run Options -->
5 <div class="flex-grow bg-slate-100 p-4 rounded-md">6 <div class="flex-grow bg-slate-100 p-4 rounded-md">
@@ -54,12 +55,15 @@
54 <!-- Protocol -->55 <!-- Protocol -->
55 <div class="w-1/4">56 <div class="w-1/4">
56 <label class="block">Protocol</label>57 <label class="block">Protocol</label>
57- <select name="container_protocol" class="w-full p-4 rounded-md border-2 bg-slate-200 border-gray-300">58+ <select
58- <option value="https" {{if eq .ContainerProtocol "https"}}selected{{end}}>https</option>59+ name="container_protocol"
59- <option value="http" {{if eq .ContainerProtocol "http"}}selected{{end}}>http</option>60+ class="w-full p-4 rounded-md border-2 bg-slate-200 border-gray-300"
61+ >
62+ <option value="https">https</option>
63+ <option value="http">http</option>
60 </select>64 </select>
61 </div>65 </div>
62- 66+
63 <!-- Subdomain -->67 <!-- Subdomain -->
64 <div class="w-1/3">68 <div class="w-1/3">
65 <label class="block">Subdomain</label>69 <label class="block">Subdomain</label>
@@ -70,7 +74,7 @@
70 value="{{.ContainerSubdomain}}"74 value="{{.ContainerSubdomain}}"
71 />75 />
72 </div>76 </div>
73- 77+
74 <!-- Domain -->78 <!-- Domain -->
75 <div class="w-5/12">79 <div class="w-5/12">
76 <label class="block">Domain</label>80 <label class="block">Domain</label>
@@ -108,17 +112,16 @@
108 />112 />
109 </div>113 </div>
110 114
111- <!-- Environment Variables
112 <div class="pb-4">115 <div class="pb-4">
113 <label class="block">Environment variables</label>116 <label class="block">Environment variables</label>
114 <span class="text-gray-500">e.g. KEY=VALUE </span>117 <span class="text-gray-500">e.g. KEY=VALUE </span>
115- <input118+ <textarea
116- type="text"
117 name="environment_variables"119 name="environment_variables"
118 class="w-full p-4 rounded-md"120 class="w-full p-4 rounded-md"
119- value="{{.EnvironmentVariables}}"121+ rows="4"
120- /> -->122+ >{{.EnvironmentVariables}}</textarea
121-123+ >
124+ </div>
122 <!-- Restart: always/on-failure/only when stopped/never -->125 <!-- Restart: always/on-failure/only when stopped/never -->
123 <div class="pb-4">126 <div class="pb-4">
124 <label class="block">Restart</label>127 <label class="block">Restart</label>
@@ -140,6 +143,9 @@
140 class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"143 class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded"
141 />144 />
142 </form>145 </form>
143- <div id="error-message-create-container-{{.ShortID}}" class="text-red-500"></div>146+ <div
147+ id="error-message-create-container-{{.ShortID}}"
148+ class="text-red-500"
149+ ></div>
144 </div>150 </div>
145 </div>151 </div>
M internal/templates/render/cmdparams.go +7 -0
@@ -13,6 +13,12 @@ func FromInputsToCmdParams(inputs map[string]string) (docker.ContainerCommandPar
1313 volumeStr := inputs["volumes"]
1414 volumeSlice := strings.Split(volumeStr, ",")
1515
16+ // Retreive the content of the textarea environment_variables and create a slice of strings
17+ environmentStr := inputs["environment_variables"]
18+ environmentSlice := strings.Split(environmentStr, "\n")
19+
20+ fmt.Println("environmentSlice", environmentSlice)
21+
1622 params := docker.ContainerCommandParams{
1723 IsSSL: inputs["container_protocol"] == "https",
1824 ContainerName: inputs["container_name"],
@@ -23,6 +29,7 @@ func FromInputsToCmdParams(inputs map[string]string) (docker.ContainerCommandPar
2329 Ports: inputs["ports"],
2430 Restart: inputs["restart"],
2531 Volumes: volumeSlice,
32+ Environment: environmentSlice,
2633 Network: ("traefik"),
2734 }
2835
@@ -13,6 +13,12 @@ func FromInputsToCmdParams(inputs map[string]string) (docker.ContainerCommandPar
13 volumeStr := inputs["volumes"]13 volumeStr := inputs["volumes"]
14 volumeSlice := strings.Split(volumeStr, ",")14 volumeSlice := strings.Split(volumeStr, ",")
15 15
16+ // Retreive the content of the textarea environment_variables and create a slice of strings
17+ environmentStr := inputs["environment_variables"]
18+ environmentSlice := strings.Split(environmentStr, "\n")
19+
20+ fmt.Println("environmentSlice", environmentSlice)
21+
16 params := docker.ContainerCommandParams{22 params := docker.ContainerCommandParams{
17 IsSSL: inputs["container_protocol"] == "https",23 IsSSL: inputs["container_protocol"] == "https",
18 ContainerName: inputs["container_name"],24 ContainerName: inputs["container_name"],
@@ -23,6 +29,7 @@ func FromInputsToCmdParams(inputs map[string]string) (docker.ContainerCommandPar
23 Ports: inputs["ports"],29 Ports: inputs["ports"],
24 Restart: inputs["restart"],30 Restart: inputs["restart"],
25 Volumes: volumeSlice,31 Volumes: volumeSlice,
32+ Environment: environmentSlice,
26 Network: ("traefik"),33 Network: ("traefik"),
27 }34 }
28 35
M pkg/docker/containers.go +5 -0
@@ -26,6 +26,7 @@ type ContainerCommandParams struct {
2626 Labels []string
2727 Network string
2828 Restart string
29+ Environment []string
2930 }
3031
3132 // ListRunningContainers lists all running containers
@@ -131,12 +132,16 @@ func CreateContainer(cmdParams ContainerCommandParams) error {
131132 }
132133 }
133134
135+ // Prepare environment variables
136+ envVars := append([]string{}, cmdParams.Environment...)
137+
134138 // Create container
135139 resp, err := dockerCli.ContainerCreate(
136140 context.Background(),
137141 &container.Config{
138142 Image: cmdParams.ImageName,
139143 Labels: labels,
144+ Env: envVars,
140145 },
141146 &container.HostConfig{
142147 PortBindings: portBindings,
@@ -26,6 +26,7 @@ type ContainerCommandParams struct {
26 Labels []string26 Labels []string
27 Network string27 Network string
28 Restart string28 Restart string
29+ Environment []string
29 }30 }
30 31
31 // ListRunningContainers lists all running containers32 // ListRunningContainers lists all running containers
@@ -131,12 +132,16 @@ func CreateContainer(cmdParams ContainerCommandParams) error {
131 }132 }
132 }133 }
133 134
135+ // Prepare environment variables
136+ envVars := append([]string{}, cmdParams.Environment...)
137+
134 // Create container138 // Create container
135 resp, err := dockerCli.ContainerCreate(139 resp, err := dockerCli.ContainerCreate(
136 context.Background(),140 context.Background(),
137 &container.Config{141 &container.Config{
138 Image: cmdParams.ImageName,142 Image: cmdParams.ImageName,
139 Labels: labels,143 Labels: labels,
144+ Env: envVars,
140 },145 },
141 &container.HostConfig{146 &container.HostConfig{
142 PortBindings: portBindings,147 PortBindings: portBindings,

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 7

Tags 106

↑↓ moveenter openesc close