Skip to content

Commit

Permalink
Merge branch 'main' into ability_to_set_image_repo_tag
Browse files Browse the repository at this point in the history
* main: (26 commits)
  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)
  chore(deps): bump the all group in /modules/clickhouse with 1 update (testcontainers#1525)
  chore(deps): bump the all group in /examples/toxiproxy with 2 updates (testcontainers#1528)
  chore(deps): bump the all group in /examples/pubsub with 1 update (testcontainers#1531)
  chore(deps): bump the all group in /examples/datastore with 2 updates (testcontainers#1530)
  chore(deps): bump the all group in /modules/redpanda with 1 update (testcontainers#1527)
  chore: properly render mkdocs.yml (testcontainers#1521)
  modulegen: create internal/workflow (testcontainers#1520)
  modulegen: create internal/module (testcontainers#1505)
  modulegen: create internal/mkdocs (testcontainers#1504)
  fix: do not remove the file schema in docker.host property (testcontainers#1517)
  fix: reset config in tests (testcontainers#1516)
  ...
  • Loading branch information
mdelapenya committed Aug 28, 2023
2 parents 7629fc0 + 04a6083 commit a853d80
Show file tree
Hide file tree
Showing 165 changed files with 1,824 additions and 1,349 deletions.
3 changes: 2 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
2 changes: 1 addition & 1 deletion .github/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ branches:
# Required. Require branches to be up to date before merging.
strict: true
# Required. The list of status checks to require in order to merge into this branch
contexts: ["static-analysis", "test (1.x, ubuntu-latest) / ./ubuntu-latest/1.x"]
contexts: ["test (1.x, ubuntu-latest) / ./ubuntu-latest/1.x"]
# Required. Enforce all configured restrictions for administrators. Set to true to enforce required status checks for repository administrators. Set to null to disable.
enforce_admins: false
# Prevent merge commits from being pushed to matching branches
Expand Down
27 changes: 24 additions & 3 deletions .github/workflows/ci-test-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ on:
default: false
description: "Disable the ryuk container for the test."

permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
# pull-requests: read

jobs:
test-go-project:
name: "${{ inputs.project-directory }}/${{ inputs.platform }}/${{ inputs.go-version }}"
Expand All @@ -48,14 +53,30 @@ jobs:
if: ${{ inputs.rootless-docker }}
run: sudo rm -rf /var/run/docker.sock

- name: Check out code into the Go module directory
uses: actions/checkout@v3

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: ${{ inputs.go-version }}
go-version: '${{ inputs.go-version }}'
cache-dependency-path: '${{ inputs.project-directory }}/go.sum'
id: go

- name: Check out code into the Go module directory
uses: actions/checkout@v3
- name: golangci-lint
# TODO: Remove each example/module once it passes the golangci-lint
if: ${{ inputs.platform == 'ubuntu-latest' && inputs.go-version == '1.20.x' && !contains(fromJSON('["examples/cockroachdb", "examples/spanner", "examples/toxiproxy", "modules/compose", "modules/pulsar", "modules/redis"]'), inputs.project-directory) }}
uses: golangci/golangci-lint-action@v3
with:
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
version: v1.54.1
# Optional: working directory, useful for monorepos
working-directory: ${{ inputs.project-directory }}
# Optional: golangci-lint command line arguments.
args: --verbose
# Optional: if set to true then the all caching functionality will be complete disabled,
# takes precedence over all other caching options.
skip-cache: true

- name: modVerify
working-directory: ./${{ inputs.project-directory }}
Expand Down
16 changes: 10 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
# 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'
- 'mkdocs.yml'
- 'docs/**'
- 'README.md'
pull_request:
paths-ignore:
- 'mkdocs.yml'
- 'docs/**'
- 'README.md'
- 'mkdocs.yml'
- 'docs/**'
- 'README.md'

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref || github.sha }}
Expand Down
51 changes: 0 additions & 51 deletions .github/workflows/golangci-lint.yml

This file was deleted.

9 changes: 4 additions & 5 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
linters:
enable:
- gci
- gofmt
- gofumpt
- misspell


linters-settings:
gci:
sections:
- standard
- default
- prefix(github.com/testcontainters)
- standard
- default
- prefix(github.com/testcontainers)

run:
timeout: 5m
4 changes: 4 additions & 0 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"testing"

"github.com/stretchr/testify/assert"

"github.com/testcontainers/testcontainers-go/internal/config"
)

Expand All @@ -16,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
1 change: 1 addition & 0 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/docker/docker/api/types/registry"
"github.com/docker/docker/pkg/archive"
"github.com/docker/go-connections/nat"

tcexec "github.com/testcontainers/testcontainers-go/exec"
"github.com/testcontainers/testcontainers-go/internal/testcontainersdocker"
"github.com/testcontainers/testcontainers-go/wait"
Expand Down
20 changes: 11 additions & 9 deletions container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (
"time"

"github.com/stretchr/testify/assert"

"github.com/testcontainers/testcontainers-go/wait"
)

func Test_ContainerValidation(t *testing.T) {

type ContainerValidationTestCase struct {
Name string
ExpectedError error
Expand Down Expand Up @@ -71,13 +71,14 @@ func Test_ContainerValidation(t *testing.T) {
for _, testCase := range testTable {
t.Run(testCase.Name, func(t *testing.T) {
err := testCase.ContainerRequest.Validate()
if err == nil && testCase.ExpectedError == nil {
switch {
case err == nil && testCase.ExpectedError == nil:
return
} else if err == nil && testCase.ExpectedError != nil {
case err == nil && testCase.ExpectedError != nil:
t.Errorf("did not receive expected error: %s", testCase.ExpectedError.Error())
} else if err != nil && testCase.ExpectedError == nil {
case err != nil && testCase.ExpectedError == nil:
t.Errorf("received unexpected error: %s", err.Error())
} else if err.Error() != testCase.ExpectedError.Error() {
case err.Error() != testCase.ExpectedError.Error():
t.Errorf("errors mismatch: %s != %s", err.Error(), testCase.ExpectedError.Error())
}
})
Expand Down Expand Up @@ -155,7 +156,7 @@ func Test_BuildImageWithContexts(t *testing.T) {
for _, f := range files {
header := tar.Header{
Name: f.Name,
Mode: 0777,
Mode: 0o777,
Size: int64(len(f.Contents)),
Typeflag: tar.TypeReg,
Format: tar.FormatGNU,
Expand Down Expand Up @@ -271,13 +272,14 @@ func Test_BuildImageWithContexts(t *testing.T) {
ContainerRequest: req,
Started: true,
})
if testCase.ExpectedError != nil && err != nil {
switch {
case testCase.ExpectedError != nil && err != nil:
if testCase.ExpectedError.Error() != err.Error() {
t.Fatalf("unexpected error: %s, was expecting %s", err.Error(), testCase.ExpectedError.Error())
}
} else if err != nil {
case err != nil:
t.Fatal(err)
} else {
default:
terminateContainerOnEnd(t, ctx, c)
}
})
Expand Down
14 changes: 4 additions & 10 deletions docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"os"
"path/filepath"
"strings"
"sync"
"time"

"github.com/cenkalti/backoff/v4"
Expand All @@ -31,6 +30,7 @@ import (
"github.com/google/uuid"
"github.com/moby/term"
specs "github.com/opencontainers/image-spec/specs-go/v1"

tcexec "github.com/testcontainers/testcontainers-go/exec"
"github.com/testcontainers/testcontainers-go/internal"
"github.com/testcontainers/testcontainers-go/internal/testcontainersdocker"
Expand All @@ -42,7 +42,6 @@ var (
// Implement interfaces
_ Container = (*DockerContainer)(nil)

logOnce sync.Once
ErrDuplicateMountTarget = errors.New("duplicate mount target detected")
)

Expand Down Expand Up @@ -316,7 +315,6 @@ func (c *DockerContainer) inspectContainer(ctx context.Context) (*types.Containe
// Logs will fetch both STDOUT and STDERR from the current container. Returns a
// ReadCloser and leaves it up to the caller to extract what it wants.
func (c *DockerContainer) Logs(ctx context.Context) (io.ReadCloser, error) {

const streamHeaderSize = 8

options := types.ContainerLogsOptions{
Expand All @@ -334,7 +332,7 @@ func (c *DockerContainer) Logs(ctx context.Context) (io.ReadCloser, error) {
r := bufio.NewReader(rc)

go func() {
var lineStarted = true
lineStarted := true
for err == nil {
line, isPrefix, err := r.ReadLine()

Expand Down Expand Up @@ -773,10 +771,6 @@ func (p *DockerProvider) SetClient(c client.APIClient) {

var _ ContainerProvider = (*DockerProvider)(nil)

func NewDockerClient() (cli *client.Client, err error) {
return testcontainersdocker.NewClient(context.Background())
}

// BuildImage will build and image from context and Dockerfile, then return the tag
func (p *DockerProvider) BuildImage(ctx context.Context, img ImageBuildInfo) (string, error) {
repoTag := fmt.Sprintf("%s:%s", img.GetRepo(), img.GetTag())
Expand Down Expand Up @@ -1188,9 +1182,9 @@ func (p *DockerProvider) attemptToPullImage(ctx context.Context, tag string, pul
}

// Health measure the healthiness of the provider. Right now we leverage the
// docker-client ping endpoint to see if the daemon is reachable.
// docker-client Info endpoint to see if the daemon is reachable.
func (p *DockerProvider) Health(ctx context.Context) (err error) {
_, err = p.client.Ping(ctx)
_, err = p.client.Info(ctx)
defer p.Close()

return err
Expand Down
3 changes: 2 additions & 1 deletion docker_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/cpuguy83/dockercfg"
"github.com/docker/docker/api/types/registry"

"github.com/testcontainers/testcontainers-go/internal/testcontainersdocker"
)

Expand All @@ -34,7 +35,7 @@ func DockerImageAuth(ctx context.Context, image string) (string, registry.AuthCo
// It will use the docker daemon to get the default registry, returning "https://index.docker.io/v1/" if
// it fails to get the information from the daemon
func defaultRegistry(ctx context.Context) string {
client, err := testcontainersdocker.NewClient(ctx)
client, err := NewDockerClientWithOpts(ctx)
if err != nil {
return testcontainersdocker.IndexDockerIO
}
Expand Down
3 changes: 2 additions & 1 deletion docker_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/docker/docker/client"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/testcontainers/testcontainers-go/internal/testcontainersdocker"
"github.com/testcontainers/testcontainers-go/wait"
)
Expand Down Expand Up @@ -137,7 +138,7 @@ func TestBuildContainerFromDockerfile(t *testing.T) {
func removeImageFromLocalCache(t *testing.T, image string) {
ctx := context.Background()

testcontainersClient, err := testcontainersdocker.NewClient(ctx, client.WithVersion(daemonMaxVersion))
testcontainersClient, err := NewDockerClientWithOpts(ctx, client.WithVersion(daemonMaxVersion))
if err != nil {
t.Log("could not create client to cleanup registry: ", err)
}
Expand Down
Loading

0 comments on commit a853d80

Please sign in to comment.