Add a few configuration fields

Configurable path for application storage,
SSH IP and HTTP IP
This commit is contained in:
Adam Štrauch 2021-01-30 12:33:57 +01:00
parent 6c8f80b326
commit bc7969bcce
Signed by: cx
GPG Key ID: 018304FFA8988F8D
4 changed files with 14 additions and 6 deletions

5
.vscode/settings.json vendored Normal file
View File

@ -0,0 +1,5 @@
{
"cSpell.words": [
"Rostifile"
]
}

View File

@ -9,7 +9,8 @@ import (
// Config keeps info about configuration of this daemon
type Config struct {
AppsPath string `envconfig:"APPS_PATH" default:"/srv"` // Where applications are located
AppsBindIP string `envconfig:"APPS_BIND_IP" default:"0.0.0.0"` // On what IP apps gonna be bound
AppsBindIPHTTP string `envconfig:"APPS_BIND_IP_HTTP" default:"0.0.0.0"` // On what IP apps' HTTP port gonna be bound
AppsBindIPSSH string `envconfig:"APPS_BIND_IP_SSH" default:"0.0.0.0"` // On what IP apps' SSH ports gonna be bound
}
// GetConfig return configuration created based on environment variables

View File

@ -34,7 +34,8 @@ const dockerAPIVersion = "1.38"
// Driver keeps everything for connection to Docker
type Driver struct {
BindIP string // IP to which containers are bound
BindIPHTTP string // IP to which containers are bound
BindIPSSH string // IP to which containers are bound
}
func (d *Driver) getClient() (*dockerClient.Client, error) {
@ -320,7 +321,7 @@ func (d *Driver) Create(name string, image string, volumePath string, HTTPPort i
portBindings := nat.PortMap{
"8000/tcp": []nat.PortBinding{
{
HostIP: d.BindIP,
HostIP: d.BindIPHTTP,
HostPort: strconv.Itoa(HTTPPort),
},
},
@ -329,7 +330,7 @@ func (d *Driver) Create(name string, image string, volumePath string, HTTPPort i
if SSHPort != 0 {
portBindings["22/tcp"] = []nat.PortBinding{
{
HostIP: d.BindIP,
HostIP: d.BindIPSSH,
HostPort: strconv.Itoa(SSHPort),
},
}

View File

@ -27,7 +27,8 @@ type Container struct {
func (c *Container) getDriver() *Driver {
config := common.GetConfig()
driver := &Driver{
BindIP: config.AppsBindIP,
BindIPHTTP: config.AppsBindIPHTTP,
BindIPSSH: config.AppsBindIPSSH,
}
return driver
}