Skip to content

Commit

Permalink
Merge branch 'main' into session-ids
Browse files Browse the repository at this point in the history
* main: (32 commits)
  fix: remove wrong example from workspace (testcontainers#1556)
  chore(deps): bump the all group in /modules/localstack with 1 update (testcontainers#1552)
  modulegen: generate code-workspace with json marshal (testcontainers#1551)
  chore(deps): bump the all group in /modules/compose with 2 updates (testcontainers#1553)
  feat: add mariadb module (testcontainers#1548)
  feat(modulegen): print out VSCode workspace file if needed (testcontainers#1549)
  modulegen: generate md file inside internal/mkdocs (testcontainers#1543)
  modulegen: create internal/module and internal/modfile (testcontainers#1539)
  [Enhancement]: add ability to set repo:tag for ContainerRequest FromDockerfile (testcontainers#1508)
  Fix module generator for examples (testcontainers#1545)
  Update pulsar.md (testcontainers#1542)
  modulegen: create internal/make (testcontainers#1537)
  chore: fix workflow (testcontainers#1538)
  chore(deps): bump the all group in /examples/cockroachdb with 1 update (testcontainers#1522)
  chore(deps): bump the all group in /examples/bigtable with 1 update (testcontainers#1534)
  chore(deps): bump the all group in /modules/localstack with 4 updates (testcontainers#1535)
  chore(deps): bump the all group in /modules/k3s with 2 updates (testcontainers#1526)
  chore(deps): bump the all group in /examples/spanner with 2 updates (testcontainers#1532)
  chore(deps): bump the all group in /examples/firestore with 1 update (testcontainers#1523)
  chore(deps): bump the all group in /modules/redis with 1 update (testcontainers#1524)
  ...
  • Loading branch information
mdelapenya committed Aug 30, 2023
2 parents 9637fae + be661b2 commit 474b420
Show file tree
Hide file tree
Showing 96 changed files with 2,486 additions and 936 deletions.
14 changes: 13 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# This file is autogenerated by the modulegen code generator. Please look at the generator code when updating it.
# This file is autogenerated by the 'modulegen' tool.
# Please look at the generator code when updating it.
version: 2
updates:
- package-ecosystem: github-actions
Expand Down Expand Up @@ -213,6 +214,17 @@ updates:
all:
patterns:
- '*'
- package-ecosystem: gomod
directory: /modules/mariadb
schedule:
interval: monthly
day: sunday
open-pull-requests-limit: 3
rebase-strategy: disabled
groups:
all:
patterns:
- '*'
- package-ecosystem: gomod
directory: /modules/mongodb
schedule:
Expand Down
20 changes: 13 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
# This file is autogenerated by the 'modulegen' tool.
# Please update the 'ci.yml' template instead.
name: Main pipeline

on:
push:
branches:
- main
paths-ignore:
- 'mkdocs.yml'
- 'docs/**'
- 'README.md'
- '.vscode/**'
- 'mkdocs.yml'
- 'docs/**'
- 'README.md'
pull_request:
paths-ignore:
- 'mkdocs.yml'
- 'docs/**'
- 'README.md'
- '.vscode/**'
- 'mkdocs.yml'
- 'docs/**'
- 'README.md'

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.sha }}
Expand Down Expand Up @@ -86,7 +92,7 @@ jobs:
matrix:
go-version: [1.20.x, 1.x]
platform: [ubuntu-latest, macos-latest]
module: [artemis, clickhouse, compose, couchbase, k3s, localstack, mongodb, mysql, neo4j, postgres, pulsar, redis, redpanda, vault]
module: [artemis, clickhouse, compose, couchbase, k3s, localstack, mariadb, mongodb, mysql, neo4j, postgres, pulsar, redis, redpanda, vault]
uses: ./.github/workflows/ci-test-go.yml
with:
go-version: ${{ matrix.go-version }}
Expand Down
113 changes: 113 additions & 0 deletions .vscode/.testcontainers-go.code-workspace
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
// This file is autogenerated by the 'modulegen' tool.
{
"folders": [
{
"name": "testcontainers-go",
"path": "../"
},
{
"name": "example / bigtable",
"path": "../examples/bigtable"
},
{
"name": "example / cockroachdb",
"path": "../examples/cockroachdb"
},
{
"name": "example / consul",
"path": "../examples/consul"
},
{
"name": "example / datastore",
"path": "../examples/datastore"
},
{
"name": "example / firestore",
"path": "../examples/firestore"
},
{
"name": "example / nats",
"path": "../examples/nats"
},
{
"name": "example / nginx",
"path": "../examples/nginx"
},
{
"name": "example / pubsub",
"path": "../examples/pubsub"
},
{
"name": "example / spanner",
"path": "../examples/spanner"
},
{
"name": "example / toxiproxy",
"path": "../examples/toxiproxy"
},
{
"name": "module / artemis",
"path": "../modules/artemis"
},
{
"name": "module / clickhouse",
"path": "../modules/clickhouse"
},
{
"name": "module / compose",
"path": "../modules/compose"
},
{
"name": "module / couchbase",
"path": "../modules/couchbase"
},
{
"name": "module / k3s",
"path": "../modules/k3s"
},
{
"name": "module / localstack",
"path": "../modules/localstack"
},
{
"name": "module / mariadb",
"path": "../modules/mariadb"
},
{
"name": "module / mongodb",
"path": "../modules/mongodb"
},
{
"name": "module / mysql",
"path": "../modules/mysql"
},
{
"name": "module / neo4j",
"path": "../modules/neo4j"
},
{
"name": "module / postgres",
"path": "../modules/postgres"
},
{
"name": "module / pulsar",
"path": "../modules/pulsar"
},
{
"name": "module / redis",
"path": "../modules/redis"
},
{
"name": "module / redpanda",
"path": "../modules/redpanda"
},
{
"name": "module / vault",
"path": "../modules/vault"
},
{
"name": "modulegen",
"path": "../modulegen"
}
]
}
3 changes: 3 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ func resetTestEnv(t *testing.T) {

func TestReadConfig(t *testing.T) {
resetTestEnv(t)
t.Cleanup(func() {
config.Reset()
})

t.Run("Config is read just once", func(t *testing.T) {
t.Setenv("HOME", "")
Expand Down
28 changes: 27 additions & 1 deletion container.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"path/filepath"
"strings"
"time"

"github.com/docker/docker/api/types"
Expand All @@ -14,6 +15,7 @@ import (
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/pkg/archive"
"github.com/docker/go-connections/nat"
"github.com/google/uuid"

tcexec "github.com/testcontainers/testcontainers-go/exec"
"github.com/testcontainers/testcontainers-go/internal/testcontainersdocker"
Expand Down Expand Up @@ -63,6 +65,8 @@ type Container interface {
type ImageBuildInfo interface {
GetContext() (io.Reader, error) // the path to the build context
GetDockerfile() string // the relative path to the Dockerfile, including the fileitself
GetRepo() string // get repo label for image
GetTag() string // get tag label for image
ShouldPrintBuildLog() bool // allow build log to be printed to stdout
ShouldBuildImage() bool // return true if the image needs to be built
GetBuildArgs() map[string]*string // return the environment args used to build the from Dockerfile
Expand All @@ -72,9 +76,11 @@ type ImageBuildInfo interface {
// FromDockerfile represents the parameters needed to build an image from a Dockerfile
// rather than using a pre-built one
type FromDockerfile struct {
Context string // the path to the context of of the docker build
Context string // the path to the context of the docker build
ContextArchive io.Reader // the tar archive file to send to docker that contains the build context
Dockerfile string // the path from the context to the Dockerfile for the image, defaults to "Dockerfile"
Repo string // the repo label for image, defaults to UUID
Tag string // the tag label for image, defaults to UUID
BuildArgs map[string]*string // enable user to pass build args to docker daemon
PrintBuildLog bool // enable user to print build log
AuthConfigs map[string]registry.AuthConfig // Deprecated. Testcontainers will detect registry credentials automatically. Enable auth configs to be able to pull from an authenticated docker registry
Expand Down Expand Up @@ -205,6 +211,26 @@ func (c *ContainerRequest) GetDockerfile() string {
return f
}

// GetRepo returns the Repo label for image from the ContainerRequest, defaults to UUID
func (c *ContainerRequest) GetRepo() string {
r := c.FromDockerfile.Repo
if r == "" {
return uuid.NewString()
}

return strings.ToLower(r)
}

// GetTag returns the Tag label for image from the ContainerRequest, defaults to UUID
func (c *ContainerRequest) GetTag() string {
t := c.FromDockerfile.Tag
if t == "" {
return uuid.NewString()
}

return strings.ToLower(t)
}

// GetAuthConfigs returns the auth configs to be able to pull from an authenticated docker registry
func (c *ContainerRequest) GetAuthConfigs() map[string]registry.AuthConfig {
images, err := testcontainersdocker.ExtractImagesFromDockerfile(filepath.Join(c.Context, c.GetDockerfile()), c.GetBuildArgs())
Expand Down
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: 1 addition & 4 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,10 +773,7 @@ var _ ContainerProvider = (*DockerProvider)(nil)

// BuildImage will build and image from context and Dockerfile, then return the tag
func (p *DockerProvider) BuildImage(ctx context.Context, img ImageBuildInfo) (string, error) {
repo := uuid.New()
tag := uuid.New()

repoTag := fmt.Sprintf("%s:%s", repo, tag)
repoTag := fmt.Sprintf("%s:%s", img.GetRepo(), img.GetTag())

buildContext, err := img.GetContext()
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1059,9 +1059,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 @@ -1073,6 +1075,7 @@ func Test_BuildContainerFromDockerfileWithBuildArgs(t *testing.T) {
ExposedPorts: []string{"8080/tcp"},
WaitingFor: wait.ForLog("ready"),
}
// }

genContainerReq := GenericContainerRequest{
ProviderType: providerType,
Expand Down
30 changes: 10 additions & 20 deletions docs/features/build_from_dockerfile.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@ 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",
},
}
```
<!--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.

If your Dockerfile expects build args:

Expand All @@ -26,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
1 change: 1 addition & 0 deletions docs/modules/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ We have provided a command line tool to generate the scaffolding for the code of
- a new Nav entry for the module in the docs site, adding it to the `mkdocs.yml` file located at the root directory of the project.
- a GitHub workflow file in the .github/workflows directory to run the tests for the example.
- an entry in Dependabot's configuration file, in order to receive dependency updates.
- an entry in the VSCode workspace file, in order to include the new module in the project's workspace.

### Command line flags

Expand Down
Loading

0 comments on commit 474b420

Please sign in to comment.