Skip to content

Commit

Permalink
docs: use code snippets
Browse files Browse the repository at this point in the history
  • Loading branch information
mdelapenya committed Aug 28, 2023
1 parent ae3ecfc commit f32ba9f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 23 deletions.
2 changes: 2 additions & 0 deletions container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ func Test_BuildImageWithContexts(t *testing.T) {
testCases := []TestCase{
{
Name: "test build from context archive",
// fromDockerfileWithContextArchive {
ContextArchive: func() (io.Reader, error) {
var buf bytes.Buffer
tarWriter := tar.NewWriter(&buf)
Expand Down Expand Up @@ -179,6 +180,7 @@ func Test_BuildImageWithContexts(t *testing.T) {

return reader, nil
},
// }
ExpectedEchoOutput: "this is from the archive",
},
{
Expand Down
5 changes: 4 additions & 1 deletion docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1070,9 +1070,11 @@ func Test_BuildContainerFromDockerfileWithBuildArgs(t *testing.T) {
t.Log("getting ctx")
ctx := context.Background()

t.Log("got ctx, creating container request")

// fromDockerfileWithBuildArgs {
ba := "build args value"

t.Log("got ctx, creating container request")
req := ContainerRequest{
FromDockerfile: FromDockerfile{
Context: filepath.Join(".", "testdata"),
Expand All @@ -1084,6 +1086,7 @@ func Test_BuildContainerFromDockerfileWithBuildArgs(t *testing.T) {
ExposedPorts: []string{"8080/tcp"},
WaitingFor: wait.ForLog("ready"),
}
// }

genContainerReq := GenericContainerRequest{
ProviderType: providerType,
Expand Down
29 changes: 7 additions & 22 deletions docs/features/build_from_dockerfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,9 @@ You can do so by specifying a `Context` (the filepath to the build context on
your local filesystem) and optionally a `Dockerfile` (defaults to "Dockerfile")
like so:

```go
req := ContainerRequest{
FromDockerfile: testcontainers.FromDockerfile{
Context: "/path/to/build/context",
Dockerfile: "CustomDockerfile",
Repo: "myrepo",
Tag: "mytag",
},
}
```
<!--codeinclude-->
[Building From a Dockerfile including Repository and Tag](../../from_dockerfile_test.go) inside_block:fromDockerfileIncludingRepo
<!--/codeinclude-->

As you can see, you can also specify the `Repo` and `Tag` optional fields to use for the image. If not passed, the
image will be built with a random name and tag.
Expand All @@ -31,18 +24,10 @@ ARG FOO
```
You can specify them like:

```go
val := "BAR"
req := ContainerRequest{
FromDockerfile: testcontainers.FromDockerfile{
Context: "/path/to/build/context",
Dockerfile: "CustomDockerfile",
BuildArgs: map[string]*string {
"FOO": &val,
},
},
}
```
<!--codeinclude-->
[Building From a Dockerfile including build arguments](../../docker_test.go) inside_block:fromDockerfileWithBuildArgs
<!--/codeinclude-->

## Dynamic Build Context

If you would like to send a build context that you created in code (maybe you have a dynamic Dockerfile), you can
Expand Down
2 changes: 2 additions & 0 deletions from_dockerfile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ func TestBuildImageFromDockerfile(t *testing.T) {
ctx := context.Background()

tag, err := provider.BuildImage(ctx, &ContainerRequest{
// fromDockerfileIncludingRepo {
FromDockerfile: FromDockerfile{
Context: filepath.Join("testdata"),
Dockerfile: "echo.Dockerfile",
Repo: "test-repo",
Tag: "test-tag",
},
// }
})
assert.Nil(t, err)
assert.Equal(t, "test-repo:test-tag", tag)
Expand Down

0 comments on commit f32ba9f

Please sign in to comment.