forked from helmutkemper/iotmaker.docker.builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_funcSetGitPathPrivateRepository_test.go
More file actions
87 lines (73 loc) · 2.29 KB
/
_funcSetGitPathPrivateRepository_test.go
File metadata and controls
87 lines (73 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package iotmakerdockerbuilder
import (
"fmt"
"github.com/helmutkemper/util"
"io/ioutil"
"log"
"net/http"
"time"
)
// this test only work on my acount (sorry)
func ExampleContainerBuilder_SetGitPathPrivateRepository() {
var err error
SaGarbageCollector()
var container = ContainerBuilder{}
container.SetPrintBuildOnStrOut()
container.SetGitPathPrivateRepository("github.com/helmutkemper")
// new image name delete:latest
container.SetImageName("delete:latest")
// container name container_delete_server_after_test
container.SetContainerName("container_delete_server_after_test")
// git project to clone git@github.com:helmutkemper/iotmaker.docker.builder.private.example.git
container.SetGitCloneToBuild("git@github.com:helmutkemper/iotmaker.docker.builder.private.example.git")
container.MakeDefaultDockerfileForMeWithInstallExtras()
err = container.SetPrivateRepositoryAutoConfig()
if err != nil {
panic(err)
}
// set a waits for the text to appear in the standard container output to proceed [optional]
container.SetWaitStringWithTimeout("Stating server on port 3000", 10*time.Second)
// change and open port 3000 to 3030
container.AddPortToChange("3000", "3030")
// replace container folder /static to host folder ./test/static
err = container.AddFileOrFolderToLinkBetweenComputerHostAndContainer("./test/static", "/static")
if err != nil {
panic(err)
}
// inicialize container object
err = container.Init()
if err != nil {
panic(err)
}
// builder new image from git project
_, err = container.ImageBuildFromServer()
if err != nil {
panic(err)
}
// build a new container from image
err = container.ContainerBuildAndStartFromImage()
if err != nil {
panic(err)
}
// At this point, the container is ready for use on port 3030
// read server inside a container on address http://localhost:3030/
var resp *http.Response
resp, err = http.Get("http://localhost:3030/")
if err != nil {
util.TraceToLog()
log.Printf("http.Get().error: %v", err.Error())
panic(err)
}
var body []byte
body, err = ioutil.ReadAll(resp.Body)
if err != nil {
util.TraceToLog()
log.Printf("http.Get().error: %v", err.Error())
panic(err)
}
// print output
fmt.Printf("%s", body)
SaGarbageCollector()
// Output:
// <html><body><p>C is life! Golang is a evolution of C</p></body></html>
}