detached 0fbbe4d

Minor fixes to FromInputsToCmdParams function

commit
0fbbe4d84966baa53bfa3671f3679a721c1c69f2
author
bnema · · 2023-09-26 19:01 UTC
parent
4e0dac8
signature
unsigned
2 files · +15 -9
M internal/gotemplate/render/cmdparams.go +13 -7
@@ -2,14 +2,17 @@ package render
22
33 import (
44 "fmt"
5+ "strings"
56
67 "github.com/bnema/gordon/pkg/utils/docker"
78 )
89
9-// FromInputsToCmdParams transforms a map to a ContainerCommandParams struct
10+// FromInputsToCmdParams transforms the inputs map into a ContainerCommandParams struct
1011 func FromInputsToCmdParams(inputs map[string]string) (docker.ContainerCommandParams, error) {
11- fmt.Println("FromInputsToCmdParams:", inputs)
12- // Populate the ContainerCommandParams struct directly from the map
12+
13+ volumeStr := inputs["volumes"]
14+ volumeSlice := strings.Split(volumeStr, ",")
15+
1316 params := docker.ContainerCommandParams{
1417 IsSSL: inputs["container_protocol"] == "https",
1518 ContainerName: inputs["container_name"],
@@ -19,23 +22,26 @@ func FromInputsToCmdParams(inputs map[string]string) (docker.ContainerCommandPar
1922 ImageID: inputs["image_id"],
2023 Ports: inputs["ports"],
2124 Restart: inputs["restart"],
22- Volumes: inputs["volumes"],
25+ Volumes: volumeSlice,
2326 Network: ("traefik"),
2427 }
2528
29+ // Retain the port number for the container host for the load balancer
30+ exposedPort := strings.Split(params.Ports, ":")[1]
31+
2632 entryPoint := "web"
2733 if params.IsSSL {
2834 entryPoint = "websecure"
2935 }
3036
31- baseRouter := "traefik.http.routers." + params.ContainerName + "-router"
32- baseService := "traefik.http.services." + params.ContainerName + "-service"
37+ baseRouter := "traefik.http.routers." + params.ContainerName
38+ baseService := "traefik.http.services." + params.ContainerName
3339
3440 params.Labels = []string{
3541 "traefik.enable=true",
3642 fmt.Sprintf("%s.rule=Host(`%s.%s`)", baseRouter, params.ServiceName, params.Domain),
3743 fmt.Sprintf("%s.entrypoints=%s", baseRouter, entryPoint),
38- fmt.Sprintf("%s.loadbalancer.server.port=%s", baseService, params.Ports),
44+ fmt.Sprintf("%s.loadbalancer.server.port=%s", baseService, exposedPort),
3945 }
4046
4147 if params.IsSSL {
@@ -2,14 +2,17 @@ package render
2 2
3 import (3 import (
4 "fmt"4 "fmt"
5+ "strings"
5 6
6 "github.com/bnema/gordon/pkg/utils/docker"7 "github.com/bnema/gordon/pkg/utils/docker"
7 )8 )
8 9
9-// FromInputsToCmdParams transforms a map to a ContainerCommandParams struct10+// FromInputsToCmdParams transforms the inputs map into a ContainerCommandParams struct
10 func FromInputsToCmdParams(inputs map[string]string) (docker.ContainerCommandParams, error) {11 func FromInputsToCmdParams(inputs map[string]string) (docker.ContainerCommandParams, error) {
11- fmt.Println("FromInputsToCmdParams:", inputs)12+
12- // Populate the ContainerCommandParams struct directly from the map13+ volumeStr := inputs["volumes"]
14+ volumeSlice := strings.Split(volumeStr, ",")
15+
13 params := docker.ContainerCommandParams{16 params := docker.ContainerCommandParams{
14 IsSSL: inputs["container_protocol"] == "https",17 IsSSL: inputs["container_protocol"] == "https",
15 ContainerName: inputs["container_name"],18 ContainerName: inputs["container_name"],
@@ -19,23 +22,26 @@ func FromInputsToCmdParams(inputs map[string]string) (docker.ContainerCommandPar
19 ImageID: inputs["image_id"],22 ImageID: inputs["image_id"],
20 Ports: inputs["ports"],23 Ports: inputs["ports"],
21 Restart: inputs["restart"],24 Restart: inputs["restart"],
22- Volumes: inputs["volumes"],25+ Volumes: volumeSlice,
23 Network: ("traefik"),26 Network: ("traefik"),
24 }27 }
25 28
29+ // Retain the port number for the container host for the load balancer
30+ exposedPort := strings.Split(params.Ports, ":")[1]
31+
26 entryPoint := "web"32 entryPoint := "web"
27 if params.IsSSL {33 if params.IsSSL {
28 entryPoint = "websecure"34 entryPoint = "websecure"
29 }35 }
30 36
31- baseRouter := "traefik.http.routers." + params.ContainerName + "-router"37+ baseRouter := "traefik.http.routers." + params.ContainerName
32- baseService := "traefik.http.services." + params.ContainerName + "-service"38+ baseService := "traefik.http.services." + params.ContainerName
33 39
34 params.Labels = []string{40 params.Labels = []string{
35 "traefik.enable=true",41 "traefik.enable=true",
36 fmt.Sprintf("%s.rule=Host(`%s.%s`)", baseRouter, params.ServiceName, params.Domain),42 fmt.Sprintf("%s.rule=Host(`%s.%s`)", baseRouter, params.ServiceName, params.Domain),
37 fmt.Sprintf("%s.entrypoints=%s", baseRouter, entryPoint),43 fmt.Sprintf("%s.entrypoints=%s", baseRouter, entryPoint),
38- fmt.Sprintf("%s.loadbalancer.server.port=%s", baseService, params.Ports),44+ fmt.Sprintf("%s.loadbalancer.server.port=%s", baseService, exposedPort),
39 }45 }
40 46
41 if params.IsSSL {47 if params.IsSSL {
M pkg/utils/docker/containers.go +2 -2
@@ -22,7 +22,7 @@ type ContainerCommandParams struct {
2222 ImageName string
2323 ImageID string
2424 Ports string
25- Volumes string
25+ Volumes []string
2626 Labels []string
2727 Network string
2828 Restart string
@@ -140,7 +140,7 @@ func CreateContainer(cmdParams ContainerCommandParams) error {
140140 },
141141 &container.HostConfig{
142142 PortBindings: portBindings,
143- Binds: []string{cmdParams.Volumes},
143+ Binds: cmdParams.Volumes,
144144 RestartPolicy: container.RestartPolicy{
145145 Name: cmdParams.Restart,
146146 },
@@ -22,7 +22,7 @@ type ContainerCommandParams struct {
22 ImageName string22 ImageName string
23 ImageID string23 ImageID string
24 Ports string24 Ports string
25- Volumes string25+ Volumes []string
26 Labels []string26 Labels []string
27 Network string27 Network string
28 Restart string28 Restart string
@@ -140,7 +140,7 @@ func CreateContainer(cmdParams ContainerCommandParams) error {
140 },140 },
141 &container.HostConfig{141 &container.HostConfig{
142 PortBindings: portBindings,142 PortBindings: portBindings,
143- Binds: []string{cmdParams.Volumes},143+ Binds: cmdParams.Volumes,
144 RestartPolicy: container.RestartPolicy{144 RestartPolicy: container.RestartPolicy{
145 Name: cmdParams.Restart,145 Name: cmdParams.Restart,
146 },146 },

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