Skip to content

Commit 44f64b7

Browse files
committed
Merge branch 'main' into use-run-function
* main: chore: clarify image auth warning message for public images (testcontainers#3228) chore(deps): bump github.com/go-viper/mapstructure/v2 (testcontainers#3219) chore(deps): bump github/codeql-action from 3.28.16 to 3.29.2 (testcontainers#3222) chore(deps): bump mkdocs-include-markdown-plugin from 7.1.5 to 7.1.6 (testcontainers#3225) deps: update testcontainers/sshd image to 1.3.0 (testcontainers#3220) chore(deps): bump urllib3 from 2.2.2 to 2.5.0 (testcontainers#3214) deps: gopsutil and purego update (testcontainers#3217) docs: document copy from container (testcontainers#3215)
2 parents 4767617 + 295ba91 commit 44f64b7

130 files changed

Lines changed: 453 additions & 440 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/codeql.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353

5454
# Initializes the CodeQL tools for scanning.
5555
- name: Initialize CodeQL
56-
uses: github/codeql-action/init@28deaeda66b76a05916b6923827895f2b14ab387 # v3.28.16
56+
uses: github/codeql-action/init@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2
5757
with:
5858
languages: ${{ matrix.language }}
5959
# If you wish to specify custom queries, you can do so here or in a config file.
@@ -67,7 +67,7 @@ jobs:
6767
# Autobuild attempts to build any compiled languages (C/C++, C#, Go, Java, or Swift).
6868
# If this step fails, then you should remove it and run the build manually (see below)
6969
- name: Autobuild
70-
uses: github/codeql-action/autobuild@28deaeda66b76a05916b6923827895f2b14ab387 # v3.28.16
70+
uses: github/codeql-action/autobuild@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2
7171

7272
# ℹ️ Command-line programs to run using the OS shell.
7373
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
@@ -80,6 +80,6 @@ jobs:
8080
# ./location_of_script_within_repo/buildscript.sh
8181

8282
- name: Perform CodeQL Analysis
83-
uses: github/codeql-action/analyze@28deaeda66b76a05916b6923827895f2b14ab387 # v3.28.16
83+
uses: github/codeql-action/analyze@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2
8484
with:
8585
category: "/language:${{matrix.language}}"

.github/workflows/scorecards.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,6 @@ jobs:
5151

5252
# required for Code scanning alerts
5353
- name: "Upload SARIF results to code scanning"
54-
uses: github/codeql-action/upload-sarif@28deaeda66b76a05916b6923827895f2b14ab387 # v3.28.16
54+
uses: github/codeql-action/upload-sarif@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2
5555
with:
5656
sarif_file: results.sarif

Pipfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ verify_ssl = true
88
[packages]
99
mkdocs = "==1.5.3"
1010
mkdocs-codeinclude-plugin = "==0.2.1"
11-
mkdocs-include-markdown-plugin = "==7.1.5"
11+
mkdocs-include-markdown-plugin = "==7.1.6"
1212
mkdocs-material = "==9.5.18"
1313
mkdocs-markdownextradata-plugin = "==0.2.6"
1414

Pipfile.lock

Lines changed: 30 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1428,7 +1428,7 @@ func (p *DockerProvider) ReuseOrCreateContainer(ctx context.Context, req Contain
14281428
func (p *DockerProvider) attemptToPullImage(ctx context.Context, tag string, pullOpt image.PullOptions) error {
14291429
registry, imageAuth, err := DockerImageAuth(ctx, tag)
14301430
if err != nil {
1431-
p.Logger.Printf("Failed to get image auth for %s. Setting empty credentials for the image: %s. Error is: %s", registry, tag, err)
1431+
p.Logger.Printf("No image auth found for %s. Setting empty credentials for the image: %s. This is expected for public images. Details: %s", registry, tag, err)
14321432
} else {
14331433
// see https://github.com/docker/docs/blob/e8e1204f914767128814dca0ea008644709c117f/engine/api/sdk/examples.md?plain=1#L649-L657
14341434
encodedJSON, err := json.Marshal(imageAuth)

docs/features/files_and_mounts.md

Lines changed: 44 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,6 @@
22

33
Copying data of any type into a container is a very common practice when working with containers. This section will show you how to do it using _Testcontainers for Go_.
44

5-
## Volume mapping
6-
7-
It is possible to map a Docker volume into the container using the `Mounts` attribute at the `ContainerRequest` struct. For that, please pass an instance of the `GenericVolumeMountSource` type, which allows you to specify the name of the volume to be mapped, and the path inside the container where it should be mounted:
8-
9-
<!--codeinclude-->
10-
[Volume mounts](../../mounts_test.go) inside_block:volumeMounts
11-
<!--/codeinclude-->
12-
13-
!!!tip
14-
This ability of creating volumes is also available for remote Docker hosts.
15-
16-
!!!warning
17-
Bind mounts are not supported, as it could not work with remote Docker hosts.
18-
19-
!!!tip
20-
It is recommended to copy data from your local host machine to a test container using the file copy API
21-
described below, as it is much more portable.
22-
23-
## Mounting images
24-
25-
Since Docker v28, it is possible to mount the file system of an image into a container using the `Mounts` attribute at the `ContainerRequest` struct. For that, use the `DockerImageMountSource` type, which allows you to specify the name of the image to be mounted, and the subpath inside the container where it should be mounted, or simply call the `ImageMount` function, which does exactly that:
26-
27-
<!--codeinclude-->
28-
[Image mounts](../../lifecycle_test.go) inside_block:imageMounts
29-
<!--/codeinclude-->
30-
31-
!!!warning
32-
If the subpath is not a relative path, the creation of the container will fail.
33-
34-
!!!info
35-
Mounting images fails the creation of the container if the underlying container runtime does not support the `image mount` feature, which is available since Docker v28.
36-
375
## Copying files to a container
386

397
If you would like to copy a file to a container, you can do it in two different manners:
@@ -67,7 +35,7 @@ It's also possible to copy an entire directory to a container, and that can happ
6735

6836
It's important to notice that, when copying the directory to the container, the container path must exist in the Docker image. And this is a strong requirement for files to be copied _before_ the container is started, as we cannot create the full path at that time.
6937

70-
You can leverage the very same mechanism used for copying files to a container, but for directories.:
38+
You can leverage the very same mechanism used for copying files to a container, but for directories:
7139

7240
1. The first way is using the `Files` field in the `ContainerRequest` struct, as shown in the previous section, but using the path of a directory as `HostFilePath`. Like so:
7341

@@ -86,3 +54,46 @@ You can leverage the very same mechanism used for copying files to a container,
8654
<!--codeinclude-->
8755
[Copying a directory to a running container](../../docker_files_test.go) inside_block:copyDirectoryToRunningContainerAsDir
8856
<!--/codeinclude-->
57+
58+
## Copying files from a container
59+
60+
It's also possible to copy files from a container to the host machine. This can be done by using the `CopyFileFromContainer` method on the `Container` type, which will return an error and an `io.ReadCloser` that you can use to read the file content.
61+
62+
<!--codeinclude-->
63+
[Copying a file from a container](../../examples_test.go) inside_block:copyFileFromContainer
64+
<!--/codeinclude-->
65+
66+
In the above example, we previously copied the file `/tmp/file.txt` to the container, and then we copied it back to the host machine, reading the content of the file.
67+
68+
## Volume mapping
69+
70+
It is possible to map a Docker volume into the container using the `Mounts` attribute at the `ContainerRequest` struct. For that, please pass an instance of the `GenericVolumeMountSource` type, which allows you to specify the name of the volume to be mapped, and the path inside the container where it should be mounted:
71+
72+
<!--codeinclude-->
73+
[Volume mounts](../../mounts_test.go) inside_block:volumeMounts
74+
<!--/codeinclude-->
75+
76+
!!!tip
77+
This ability of creating volumes is also available for remote Docker hosts.
78+
79+
!!!warning
80+
Bind mounts are not supported, as it could not work with remote Docker hosts.
81+
82+
!!!tip
83+
It is recommended to copy data from your local host machine to a test container using the file copy API
84+
described below, as it is much more portable.
85+
86+
## Mounting images
87+
88+
Since Docker v28, it is possible to mount the file system of an image into a container using the `Mounts` attribute at the `ContainerRequest` struct. For that, use the `DockerImageMountSource` type, which allows you to specify the name of the image to be mounted, and the subpath inside the container where it should be mounted, or simply call the `ImageMount` function, which does exactly that:
89+
90+
<!--codeinclude-->
91+
[Image mounts](../../lifecycle_test.go) inside_block:imageMounts
92+
<!--/codeinclude-->
93+
94+
!!!warning
95+
If the subpath is not a relative path, the creation of the container will fail.
96+
97+
!!!info
98+
Mounting images fails the creation of the container if the underlying container runtime does not support the `image mount` feature, which is available since Docker v28.
99+

examples/nginx/go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ require (
2626
github.com/docker/docker v28.2.2+incompatible // indirect
2727
github.com/docker/go-connections v0.5.0 // indirect
2828
github.com/docker/go-units v0.5.0 // indirect
29-
github.com/ebitengine/purego v0.8.2 // indirect
29+
github.com/ebitengine/purego v0.8.4 // indirect
3030
github.com/felixge/httpsnoop v1.0.4 // indirect
3131
github.com/go-logr/logr v1.4.2 // indirect
3232
github.com/go-logr/stdr v1.2.2 // indirect
@@ -49,7 +49,7 @@ require (
4949
github.com/pkg/errors v0.9.1 // indirect
5050
github.com/pmezard/go-difflib v1.0.0 // indirect
5151
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
52-
github.com/shirou/gopsutil/v4 v4.25.4 // indirect
52+
github.com/shirou/gopsutil/v4 v4.25.5 // indirect
5353
github.com/sirupsen/logrus v1.9.3 // indirect
5454
github.com/tklauser/go-sysconf v0.3.12 // indirect
5555
github.com/tklauser/numcpus v0.6.1 // indirect

examples/nginx/go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ github.com/docker/go-connections v0.5.0 h1:USnMq7hx7gwdVZq1L49hLXaFtUdTADjXGp+uj
3131
github.com/docker/go-connections v0.5.0/go.mod h1:ov60Kzw0kKElRwhNs9UlUHAE/F9Fe6GLaXnqyDdmEXc=
3232
github.com/docker/go-units v0.5.0 h1:69rxXcBk27SvSaaxTtLh/8llcHD8vYHT7WSdRZ/jvr4=
3333
github.com/docker/go-units v0.5.0/go.mod h1:fgPhTUdO+D/Jk86RDLlptpiXQzgHJF7gydDDbaIK4Dk=
34-
github.com/ebitengine/purego v0.8.2 h1:jPPGWs2sZ1UgOSgD2bClL0MJIqu58nOmIcBuXr62z1I=
35-
github.com/ebitengine/purego v0.8.2/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
34+
github.com/ebitengine/purego v0.8.4 h1:CF7LEKg5FFOsASUj0+QwaXf8Ht6TlFxg09+S9wz0omw=
35+
github.com/ebitengine/purego v0.8.4/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ=
3636
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
3737
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
3838
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
@@ -93,8 +93,8 @@ github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c h1:ncq/mPwQF
9393
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c/go.mod h1:OmDBASR4679mdNQnz2pUhc2G8CO2JrUAVFDRBDP/hJE=
9494
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
9595
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
96-
github.com/shirou/gopsutil/v4 v4.25.4 h1:cdtFO363VEOOFrUCjZRh4XVJkb548lyF0q0uTeMqYPw=
97-
github.com/shirou/gopsutil/v4 v4.25.4/go.mod h1:xbuxyoZj+UsgnZrENu3lQivsngRR5BdjbJwf2fv4szA=
96+
github.com/shirou/gopsutil/v4 v4.25.5 h1:rtd9piuSMGeU8g1RMXjZs9y9luK5BwtnG7dZaQUJAsc=
97+
github.com/shirou/gopsutil/v4 v4.25.5/go.mod h1:PfybzyydfZcN+JMMjkF6Zb8Mq1A/VcogFFg7hj50W9c=
9898
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
9999
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
100100
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

examples_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@ func ExampleRun() {
103103
fmt.Println(ctrResp.Config.Labels["testcontainers.label"])
104104

105105
// files
106-
f, err := ctr.CopyFileFromContainer(ctx, "/tmp/file.txt")
106+
// copyFileFromContainer {
107+
f, err := ctr.CopyFileFromContainer(context.Background(), "/tmp/file.txt")
107108
if err != nil {
108109
log.Printf("failed to copy file from container: %s", err)
109110
return
@@ -114,6 +115,7 @@ func ExampleRun() {
114115
log.Printf("failed to read file: %s", err)
115116
return
116117
}
118+
// }
117119
fmt.Println(string(content))
118120

119121
// Output:

go.mod

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/moby/patternmatcher v0.6.0
1919
github.com/moby/term v0.5.0
2020
github.com/opencontainers/image-spec v1.1.1
21-
github.com/shirou/gopsutil/v4 v4.25.4
21+
github.com/shirou/gopsutil/v4 v4.25.5
2222
github.com/stretchr/testify v1.10.0
2323
golang.org/x/crypto v0.37.0
2424
golang.org/x/sys v0.32.0
@@ -32,7 +32,7 @@ require (
3232
github.com/davecgh/go-spew v1.1.1 // indirect
3333
github.com/distribution/reference v0.6.0 // indirect
3434
github.com/docker/go-units v0.5.0 // indirect
35-
github.com/ebitengine/purego v0.8.2 // indirect
35+
github.com/ebitengine/purego v0.8.4 // indirect
3636
github.com/felixge/httpsnoop v1.0.4 // indirect
3737
github.com/go-logr/logr v1.4.2 // indirect
3838
github.com/go-logr/stdr v1.2.2 // indirect

0 commit comments

Comments
 (0)