factorycontainerfromremoteserver

package
v0.0.0-...-947c8b3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2021 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewContainerCreateExposePortsAutomaticallyAndStart

func NewContainerCreateExposePortsAutomaticallyAndStart(
	newImageName,
	newContainerName,
	serverPath string,
	imageTags []string,
	buildStatus *chan iotmakerdocker.ContainerPullStatusSendToChannel,
) (
	imageId string,
	containerId string,
	err error,
)

NewContainerCreateExposePortsAutomaticallyAndStart (English): Create a image and create and start a container from project inside into server

NewContainerCreateExposePortsAutomaticallyAndStart (Português): Cria uma imagem e inicializa o container baseado no conteúdo do servidor

Example

Before run this example, you must create a file [windows: C:]/static/index.html and put "It's alive!" inside file, without html tags and line breaks.

var err error
var pullStatusChannel = iotmakerdocker.NewImagePullStatusChannel()

go func(c chan iotmakerdocker.ContainerPullStatusSendToChannel) {

	for {
		select {
		case status := <-c:
			//fmt.Printf("image pull status: %+v\n", status)

			if status.Closed == true {
				//fmt.Println("image pull complete!")
			}
		}
	}

}(*pullStatusChannel)

err = toolsgarbagecollector.RemoveAllByNameContains("delete")
if err != nil {
	panic(err)
}

_, _, err = NewContainerCreateExposePortsAutomaticallyAndStart(
	"server_delete_before_test:latest",
	"container_delete_before_test",
	"https://github.com/helmutkemper/iotmaker.docker.util.whaleAquarium.sample.git",
	[]string{},
	pullStatusChannel,
)
if err != nil {
	panic(err)
}

var resp *http.Response
var site []byte
resp, err = http.Get("http://localhost:3000")
if err != nil {
	panic(err)
}

site, err = ioutil.ReadAll(resp.Body)
if err != nil {
	panic(err)
}

err = resp.Body.Close()
if err != nil {
	panic(err)
}

err = toolsgarbagecollector.RemoveAllByNameContains("delete")
if err != nil {
	panic(err)
}

fmt.Printf("%s\n", site)
Output:

It's alive!

func NewContainerFromRemoteServerChangeExposedPortAndVolumes

func NewContainerFromRemoteServerChangeExposedPortAndVolumes(
	newImageName,
	newContainerName,
	serverPath string,
	imageTags []string,
	portList nat.PortMap,
	containersVolumes []mount.Mount,
	buildStatus *chan iotmakerdocker.ContainerPullStatusSendToChannel,
) (
	imageId,
	containerId string,
	err error,
)

NewContainerFromRemoteServerChangeExposedPortAndVolumes (English): Create a image and create and start a container from project inside into server

NewContainerFromRemoteServerChangeExposedPortAndVolumes (Português): Cria uma imagem e inicializa o container baseado no conteúdo do servidor

Example

Before run this example, you must create a file [windows: C:]/static/index.html and put "It's alive!" inside file, without html tags and line breaks.

var err error
var pullStatusChannel = iotmakerdocker.NewImagePullStatusChannel()
var volumesList []mount.Mount

go func(c chan iotmakerdocker.ContainerPullStatusSendToChannel) {

	for {
		select {
		case status := <-c:
			//fmt.Printf("image pull status: %+v\n", status)

			if status.Closed == true {
				//fmt.Println("image pull complete!")
			}
		}
	}

}(*pullStatusChannel)

err = tools_garbage_collector.RemoveAllByNameContains("delete")
if err != nil {
	panic(err)
}

serverPort := nat.PortMap{
	// container port number/protocol [tpc/udp]
	"3000/tcp": []nat.PortBinding{ // server original port
		{
			// server output port number
			HostPort: "8080",
		},
	},
}

volumesList, err = iotmakerdocker.NewVolumeMount(
	[]iotmakerdocker.Mount{
		{
			MountType:   iotmakerdocker.KVolumeMountTypeBind,
			Source:      "C:\\static", //absolute or relative to this code
			Destination: "/static",    //folder inside container
		},
	},
)
if err != nil {
	panic(err)
}

_, _, err = NewContainerFromRemoteServerChangeExposedPortAndVolumes(
	"server_delete_before_test:latest",
	"container_delete_before_test",
	"https://github.com/helmutkemper/iotmaker.docker.util.whaleAquarium.sample.git",
	[]string{},
	serverPort,
	volumesList,
	pullStatusChannel,
)
if err != nil {
	panic(err)
}

var resp *http.Response
var site []byte
resp, err = http.Get("http://localhost:8080")
if err != nil {
	panic(err)
}

site, err = ioutil.ReadAll(resp.Body)
if err != nil {
	panic(err)
}

err = resp.Body.Close()
if err != nil {
	panic(err)
}

err = tools_garbage_collector.RemoveAllByNameContains("delete")
if err != nil {
	panic(err)
}

fmt.Printf("%s\n", site)
Output:

It's alive!

func NewContainerFromRemoteServerChangeExposedPortAndVolumesWithNetworkConfiguration

func NewContainerFromRemoteServerChangeExposedPortAndVolumesWithNetworkConfiguration(
	newImageName,
	newContainerName string,
	newContainerRestartPolicy iotmakerdocker.RestartPolicy,
	networkAutoConfiguration *iotmakerdocker.NextNetworkAutoConfiguration,
	serverPath string,
	imageTags []string,
	portList nat.PortMap,
	containersVolumes []mount.Mount,
	buildStatus *chan iotmakerdocker.ContainerPullStatusSendToChannel,
) (
	imageId string,
	containerId,
	networkId string,
	err error,
)

NewContainerFromRemoteServerChangeExposedPortAndVolumesWithNetworkConfiguration (English): Create a image and create and start a container from project inside into server

NewContainerFromRemoteServerChangeExposedPortAndVolumesWithNetworkConfiguration (Português): Cria uma imagem e inicializa o container baseado no conteúdo do servidor

Example
var err error
var pullStatusChannel = iotmakerdocker.NewImagePullStatusChannel()
var volumesList []mount.Mount
var networkAutoConfiguration *iotmakerdocker.NextNetworkAutoConfiguration

go func(c chan iotmakerdocker.ContainerPullStatusSendToChannel) {

	for {
		select {
		case status := <-c:
			//fmt.Printf("image pull status: %+v\n", status)

			if status.Closed == true {
				//fmt.Println("image pull complete!")
			}
		}
	}

}(*pullStatusChannel)

err = tools_garbage_collector.RemoveAllByNameContains("delete")
if err != nil {
	panic(err)
}

serverPort := nat.PortMap{
	// container port number/protocol [tpc/udp]
	"3000/tcp": []nat.PortBinding{ // server original port
		{
			// server output port number
			HostPort: "8080",
		},
	},
}

volumesList, err = iotmakerdocker.NewVolumeMount(
	[]iotmakerdocker.Mount{
		{
			MountType:   iotmakerdocker.KVolumeMountTypeBind,
			Source:      "C:\\static", //absolute or relative to this code
			Destination: "/static",    //folder inside container
		},
	},
)
if err != nil {
	panic(err)
}

_, networkAutoConfiguration, err = iotmakerdocker.NewNetwork("network_delete_before_test")
if err != nil {
	panic(err)
}

_, _, _, err = NewContainerFromRemoteServerChangeExposedPortAndVolumesWithNetworkConfiguration(
	"server_delete_before_test:latest",
	"container_delete_before_test",
	iotmakerdocker.KRestartPolicyOnFailure,
	networkAutoConfiguration,
	"https://github.com/helmutkemper/iotmaker.docker.util.whaleAquarium.sample.git",
	[]string{},
	serverPort,
	volumesList,
	pullStatusChannel,
)
if err != nil {
	panic(err)
}

var resp *http.Response
var site []byte
resp, err = http.Get("http://localhost:8080")
if err != nil {
	panic(err)
}

site, err = ioutil.ReadAll(resp.Body)
if err != nil {
	panic(err)
}

err = resp.Body.Close()
if err != nil {
	panic(err)
}

err = tools_garbage_collector.RemoveAllByNameContains("delete")
if err != nil {
	panic(err)
}

fmt.Printf("%s\n", site)
Output:

It's alive!

func NewContainerFromRemoteServerChangeVolumes

func NewContainerFromRemoteServerChangeVolumes(
	newImageName,
	newContainerName,
	serverPath string,
	imageTags []string,
	containersVolumes []mount.Mount,
	buildStatus *chan iotmakerdocker.ContainerPullStatusSendToChannel,
) (
	imageId,
	containerId string,
	err error,
)

NewContainerFromRemoteServerChangeVolumes (English): Create a image and create and start a container from project inside into server

NewContainerFromRemoteServerChangeVolumes (Português): Cria uma imagem e inicializa o container baseado no conteúdo do servidor

Example

Before run this example, you must create a file [windows: C:]/static/index.html and put "It's alive!" inside file, without html tags and line breaks.

var err error
var pullStatusChannel = iotmakerdocker.NewImagePullStatusChannel()
var volumesList []mount.Mount

go func(c chan iotmakerdocker.ContainerPullStatusSendToChannel) {

	for {
		select {
		case status := <-c:
			//fmt.Printf("image pull status: %+v\n", status)

			if status.Closed == true {
				//fmt.Println("image pull complete!")
			}
		}
	}

}(*pullStatusChannel)

err = tools_garbage_collector.RemoveAllByNameContains("delete")
if err != nil {
	panic(err)
}

volumesList, err = iotmakerdocker.NewVolumeMount(
	[]iotmakerdocker.Mount{
		{
			MountType:   iotmakerdocker.KVolumeMountTypeBind,
			Source:      "C:\\static", //absolute or relative to this code
			Destination: "/static",    //folder inside container
		},
	},
)
if err != nil {
	panic(err)
}

_, _, err = NewContainerFromRemoteServerChangeVolumes(
	"server_delete_before_test:latest",
	"container_delete_before_test",
	"https://github.com/helmutkemper/iotmaker.docker.util.whaleAquarium.sample.git",
	[]string{},
	volumesList,
	pullStatusChannel,
)
if err != nil {
	panic(err)
}

var resp *http.Response
var site []byte
resp, err = http.Get("http://localhost:3000")
if err != nil {
	panic(err)
}

site, err = ioutil.ReadAll(resp.Body)
if err != nil {
	panic(err)
}

err = resp.Body.Close()
if err != nil {
	panic(err)
}

err = tools_garbage_collector.RemoveAllByNameContains("delete")
if err != nil {
	panic(err)
}

fmt.Printf("%s\n", site)
Output:

It's alive!

func NewContainerFromRemoteServerChangeVolumesWithNetworkConfiguration

func NewContainerFromRemoteServerChangeVolumesWithNetworkConfiguration(
	newImageName,
	newContainerName string,
	newContainerRestartPolicy iotmakerdocker.RestartPolicy,
	networkAutoConfiguration *iotmakerdocker.NextNetworkAutoConfiguration,
	serverPath string,
	imageTags []string,
	containersVolumes []mount.Mount,
	buildStatus *chan iotmakerdocker.ContainerPullStatusSendToChannel,
) (
	imageId,
	containerId,
	networkId string,
	err error,
)

NewContainerFromRemoteServerChangeVolumesWithNetworkConfiguration (English): Create a image and create and start a container from project inside into server

NewContainerFromRemoteServerChangeVolumesWithNetworkConfiguration (Português): Cria uma imagem e inicializa o container baseado no conteúdo do servidor

Example
var err error
var pullStatusChannel = iotmakerdocker.NewImagePullStatusChannel()
var volumesList []mount.Mount
var networkAutoConfiguration *iotmakerdocker.NextNetworkAutoConfiguration

go func(c chan iotmakerdocker.ContainerPullStatusSendToChannel) {

	for {
		select {
		case status := <-c:
			//fmt.Printf("image pull status: %+v\n", status)

			if status.Closed == true {
				//fmt.Println("image pull complete!")
			}
		}
	}

}(*pullStatusChannel)

err = tools_garbage_collector.RemoveAllByNameContains("delete")
if err != nil {
	panic(err)
}

volumesList, err = iotmakerdocker.NewVolumeMount(
	[]iotmakerdocker.Mount{
		{
			MountType:   iotmakerdocker.KVolumeMountTypeBind,
			Source:      "C:\\static", //absolute or relative to this code
			Destination: "/static",    //folder inside container
		},
	},
)
if err != nil {
	panic(err)
}

_, networkAutoConfiguration, err = iotmakerdocker.NewNetwork("network_delete_before_test")
if err != nil {
	panic(err)
}

_, _, _, err = NewContainerFromRemoteServerChangeVolumesWithNetworkConfiguration(
	"server_delete_before_test:latest",
	"container_delete_before_test",
	iotmakerdocker.KRestartPolicyOnFailure,
	networkAutoConfiguration,
	"https://github.com/helmutkemper/iotmaker.docker.util.whaleAquarium.sample.git",
	[]string{},
	volumesList,
	pullStatusChannel,
)
if err != nil {
	panic(err)
}

var resp *http.Response
var site []byte
resp, err = http.Get("http://localhost:3000")
if err != nil {
	panic(err)
}

site, err = ioutil.ReadAll(resp.Body)
if err != nil {
	panic(err)
}

err = resp.Body.Close()
if err != nil {
	panic(err)
}

err = tools_garbage_collector.RemoveAllByNameContains("delete")
if err != nil {
	panic(err)
}

fmt.Printf("%s\n", site)
Output:

It's alive!

func NewContainerFromRemoteServerWithNetworkConfiguration

func NewContainerFromRemoteServerWithNetworkConfiguration(
	newImageName,
	newContainerName string,
	newContainerRestartPolicy iotmakerdocker.RestartPolicy,
	networkAutoConfiguration *iotmakerdocker.NextNetworkAutoConfiguration,
	serverPath string,
	imageTags []string,
	buildStatus *chan iotmakerdocker.ContainerPullStatusSendToChannel,
) (
	imageId string,
	containerId string,
	networkId string,
	err error,
)

NewContainerFromRemoteServerWithNetworkConfiguration (English): Create a image and create and start a container from project inside into server

NewContainerFromRemoteServerWithNetworkConfiguration (Português): Cria uma imagem e inicializa o container baseado no conteúdo do servidor

Example
var err error
var pullStatusChannel = iotmakerdocker.NewImagePullStatusChannel()
var networkAutoConfiguration *iotmakerdocker.NextNetworkAutoConfiguration

go func(c chan iotmakerdocker.ContainerPullStatusSendToChannel) {

	for {
		select {
		case status := <-c:
			//fmt.Printf("image pull status: %+v\n", status)

			if status.Closed == true {
				//fmt.Println("image pull complete!")
			}
		}
	}

}(*pullStatusChannel)

err = tools_garbage_collector.RemoveAllByNameContains("delete")
if err != nil {
	panic(err)
}

_, networkAutoConfiguration, err = iotmakerdocker.NewNetwork("network_delete_before_test")
if err != nil {
	panic(err)
}

_, _, _, err = NewContainerFromRemoteServerWithNetworkConfiguration(
	"server_delete_before_test:latest",
	"container_delete_before_test",
	iotmakerdocker.KRestartPolicyOnFailure,
	networkAutoConfiguration,
	"https://github.com/helmutkemper/iotmaker.docker.util.whaleAquarium.sample.git",
	[]string{},
	pullStatusChannel,
)
if err != nil {
	panic(err)
}

var resp *http.Response
var site []byte
resp, err = http.Get("http://localhost:3000")
if err != nil {
	panic(err)
}

site, err = ioutil.ReadAll(resp.Body)
if err != nil {
	panic(err)
}

err = resp.Body.Close()
if err != nil {
	panic(err)
}

err = tools_garbage_collector.RemoveAllByNameContains("delete")
if err != nil {
	panic(err)
}

fmt.Printf("%s\n", site)
Output:

It's alive!

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL