Configurable IP address used to bind apps' ports

This commit is contained in:
Adam Štrauch 2021-01-09 22:32:52 +01:00
parent 35fcfc759a
commit 6c8f80b326
Signed by: cx
GPG Key ID: 018304FFA8988F8D
3 changed files with 11 additions and 5 deletions

View File

@ -8,7 +8,8 @@ import (
// Config keeps info about configuration of this daemon
type Config struct {
AppsPath string `envconfig:"APPS_PATH" default:"/srv"` // Where applications are located
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
}
// GetConfig return configuration created based on environment variables

View File

@ -33,7 +33,9 @@ const podmanSock = "/run/podman/podman.sock"
const dockerAPIVersion = "1.38"
// Driver keeps everything for connection to Docker
type Driver struct{}
type Driver struct {
BindIP string // IP to which containers are bound
}
func (d *Driver) getClient() (*dockerClient.Client, error) {
var connectTo string
@ -318,7 +320,7 @@ func (d *Driver) Create(name string, image string, volumePath string, HTTPPort i
portBindings := nat.PortMap{
"8000/tcp": []nat.PortBinding{
{
HostIP: "0.0.0.0",
HostIP: d.BindIP,
HostPort: strconv.Itoa(HTTPPort),
},
},
@ -327,7 +329,7 @@ func (d *Driver) Create(name string, image string, volumePath string, HTTPPort i
if SSHPort != 0 {
portBindings["22/tcp"] = []nat.PortBinding{
{
HostIP: "0.0.0.0",
HostIP: d.BindIP,
HostPort: strconv.Itoa(SSHPort),
},
}

View File

@ -25,7 +25,10 @@ type Container struct {
}
func (c *Container) getDriver() *Driver {
driver := &Driver{}
config := common.GetConfig()
driver := &Driver{
BindIP: config.AppsBindIP,
}
return driver
}