From f32ba9f3d43ac9692803fec2587c80501a091d2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20de=20la=20Pe=C3=B1a?= Date: Mon, 28 Aug 2023 17:38:51 +0200 Subject: [PATCH] docs: use code snippets --- container_test.go | 2 ++ docker_test.go | 5 ++++- docs/features/build_from_dockerfile.md | 29 +++++++------------------- from_dockerfile_test.go | 2 ++ 4 files changed, 15 insertions(+), 23 deletions(-) diff --git a/container_test.go b/container_test.go index b417822986..c3c12dcbfe 100644 --- a/container_test.go +++ b/container_test.go @@ -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) @@ -179,6 +180,7 @@ func Test_BuildImageWithContexts(t *testing.T) { return reader, nil }, + // } ExpectedEchoOutput: "this is from the archive", }, { diff --git a/docker_test.go b/docker_test.go index dbc1030e9b..4a495bf7be 100644 --- a/docker_test.go +++ b/docker_test.go @@ -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"), @@ -1084,6 +1086,7 @@ func Test_BuildContainerFromDockerfileWithBuildArgs(t *testing.T) { ExposedPorts: []string{"8080/tcp"}, WaitingFor: wait.ForLog("ready"), } + // } genContainerReq := GenericContainerRequest{ ProviderType: providerType, diff --git a/docs/features/build_from_dockerfile.md b/docs/features/build_from_dockerfile.md index d1b5254ced..349c4a24c9 100644 --- a/docs/features/build_from_dockerfile.md +++ b/docs/features/build_from_dockerfile.md @@ -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", - }, - } -``` + +[Building From a Dockerfile including Repository and Tag](../../from_dockerfile_test.go) inside_block:fromDockerfileIncludingRepo + 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. @@ -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, - }, - }, - } -``` + +[Building From a Dockerfile including build arguments](../../docker_test.go) inside_block:fromDockerfileWithBuildArgs + + ## 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 diff --git a/from_dockerfile_test.go b/from_dockerfile_test.go index d9edcfcb9a..833ff451cd 100644 --- a/from_dockerfile_test.go +++ b/from_dockerfile_test.go @@ -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)