forked from helmutkemper/iotmaker.docker.builder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfuncContainerCopyFrom_test.go
More file actions
217 lines (180 loc) · 5.92 KB
/
funcContainerCopyFrom_test.go
File metadata and controls
217 lines (180 loc) · 5.92 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
package iotmakerdockerbuilder
import (
"fmt"
"github.com/docker/docker/api/types"
"log"
"os"
)
func ExampleContainerBuilder_ContainerCopyFrom() {
var err error
// English: Deletes all docker elements with the term `delete` in the name.
//
// Português: Apaga todos os elementos docker com o termo `delete` no nome.
// [optional/opcional]
SaGarbageCollector()
err = buildGoLintImageCopyFromExample()
if err != nil {
fmt.Printf("error: %v", err.Error())
SaGarbageCollector()
return
}
err = buildAlpineImageCopyFromExample()
if err != nil {
fmt.Printf("error: %v", err.Error())
SaGarbageCollector()
return
}
_ = os.Remove("./example/golint/golangci-lint")
// Output:
// image size: 510.9 MB
// image os: linux
// file name: golangci-lint
// image size: 281.8 MB
// image os: linux
}
func buildGoLintImageCopyFromExample() (err error) {
var imageInspect types.ImageInspect
var container = ContainerBuilder{}
// English: print the standard output of the container
//
// Português: imprime a saída padrão do container
// [optional/opcional]
container.SetPrintBuildOnStrOut()
// English: Name of the new image to be created.
//
// Português: Nome da nova imagem a ser criada.
container.SetImageName("golint_delete:latest")
// English: Golang project path to be turned into docker image
//
// Português: Caminho do projeto em Golang a ser transformado em imagem docker
container.SetBuildFolderPath("./example/golint/imageGolintBuild")
// English: Defines the name of the docker container to be created.
//
// Português: Define o nome do container docker a ser criado.
container.SetContainerName("container_golint_delete_after_test")
// English: Initializes the container manager object.
//
// Português: Inicializa o objeto gerenciador de container.
err = container.Init()
if err != nil {
fmt.Printf("error: %v", err.Error())
SaGarbageCollector()
return
}
// English: Creates an image from a project folder.
//
// Português: Cria uma imagem a partir de uma pasta de projeto.
imageInspect, err = container.ImageBuildFromFolder()
if err != nil {
fmt.Printf("error: %v", err.Error())
SaGarbageCollector()
return
}
fmt.Printf("image size: %v\n", container.SizeToString(imageInspect.Size))
fmt.Printf("image os: %v\n", imageInspect.Os)
// English: Creates and initializes the container based on the created image.
//
// Português: Cria e inicializa o container baseado na imagem criada.
err = container.ContainerBuildAndStartFromImage()
if err != nil {
log.Printf("error: %v", err.Error())
SaGarbageCollector()
return
}
var copyResponse []types.ContainerPathStat
copyResponse, err = container.ContainerCopyFrom(
[]string{"/go/pkg/mod/github.com/golangci/golangci-lint@v1.23.6/bin/golangci-lint"},
[]string{"./example/golint/golangci-lint"},
)
if err != nil {
log.Printf("error: %v", err.Error())
SaGarbageCollector()
return
}
// English: Deletes all docker elements with the term `delete` in the name.
//
// Português: Apaga todos os elementos docker com o termo `delete` no nome.
// [optional/opcional]
SaGarbageCollector()
fmt.Printf("file name: %v\n", copyResponse[0].Name)
return
}
func buildAlpineImageCopyFromExample() (err error) {
var imageInspect types.ImageInspect
var container = ContainerBuilder{}
// English: print the standard output of the container
//
// Português: imprime a saída padrão do container
// [optional/opcional]
container.SetPrintBuildOnStrOut()
// English: Name of the new image to be created.
//
// Português: Nome da nova imagem a ser criada.
container.SetImageName("alpine_delete:latest")
// English: Golang project path to be turned into docker image
//
// Português: Caminho do projeto em Golang a ser transformado em imagem docker
container.SetBuildFolderPath("./example/golint/imageAlpineBuild")
// English: Defines the name of the docker container to be created.
//
// Português: Define o nome do container docker a ser criado.
container.SetContainerName("container_alpine_delete_after_test")
// English: Initializes the container manager object.
//
// Português: Inicializa o objeto gerenciador de container.
err = container.Init()
if err != nil {
fmt.Printf("error: %v", err.Error())
SaGarbageCollector()
return
}
// English: Creates an image from a project folder.
//
// Português: Cria uma imagem a partir de uma pasta de projeto.
imageInspect, err = container.ImageBuildFromFolder()
if err != nil {
fmt.Printf("error: %v", err.Error())
SaGarbageCollector()
return
}
fmt.Printf("image size: %v\n", container.SizeToString(imageInspect.Size))
fmt.Printf("image os: %v\n", imageInspect.Os)
// English: Creates and initializes the container based on the created image.
//
// Português: Cria e inicializa o container baseado na imagem criada.
err = container.ContainerBuildAndStartFromImage()
if err != nil {
log.Printf("error: %v", err.Error())
SaGarbageCollector()
return
}
err = container.ContainerCopyTo(
[]string{"./example/golint/golangci-lint"},
[]string{"/go"},
)
if err != nil {
log.Printf("error: %v", err.Error())
SaGarbageCollector()
return
}
var exitCode int
var running bool
var stdOutput []byte
var stdError []byte
exitCode, running, stdOutput, stdError, err = container.ContainerExecCommand([]string{"ls", "-l"})
log.Printf("exitCode: %v", exitCode)
log.Printf("running: %v", running)
log.Printf("stdOutput: %v", string(stdOutput))
log.Printf("stdError: %v", string(stdError))
exitCode, running, stdOutput, stdError, err = container.ContainerExecCommand([]string{"./golangci-lint"})
log.Printf("exitCode: %v", exitCode)
log.Printf("running: %v", running)
log.Printf("stdOutput: %v", string(stdOutput))
log.Printf("stdError: %v", string(stdError))
// English: Deletes all docker elements with the term `delete` in the name.
//
// Português: Apaga todos os elementos docker com o termo `delete` no nome.
// [optional/opcional]
SaGarbageCollector()
return
}