Skip to content

Commit

Permalink
Merge branch 'main' into patch-1
Browse files Browse the repository at this point in the history
* main: (44 commits)
  feat: expose JSON representation of a container with Inspect (testcontainers#2534)
  chore(deps): bump test-summary action to v2.3 (testcontainers#2535)
  chore(deps): bump jinja2 from 3.1.3 to 3.1.4 (testcontainers#2533)
  Update devcontainer image (testcontainers#2531)
  chore(influxdb): include more characters in wait for log regex (testcontainers#2532)
  fix(compose): avoid race conditions when caching services (testcontainers#2528)
  chore(deps): bump golangci/golangci-lint-action from 3.7.0 to 5.1.0 (testcontainers#2525)
  chore(deps): bump mkdocs-material from 8.2.7 to 9.1.21 (testcontainers#2524)
  chore(compose): return error in options (testcontainers#2520)
  chore(deps): bump github.com/compose-spec/compose-go/v2 from v2.0.0-rc8 to v2.1.0 (testcontainers#2519)
  chore(deps): bump github.com/containerd/containerd from 1.7.12 to 1.7.15 (testcontainers#2517)
  break: return error from Customize request option (testcontainers#2267)
  fix: wrong copy paste (testcontainers#2515)
  docs: add documentation for Exec method (testcontainers#2451)
  docs: document the SSHd tunnel (testcontainers#2514)
  fix: enhance host configuration port binding (testcontainers#2512)
  feat: forward host ports to a container using an SSH tunnel (testcontainers#2471)
  Update follow_logs.md with adding missing package (testcontainers#2513)
  fix: don't retry on permanent APIClient errors (testcontainers#2506)
  feat: support overriding the default recreate options for compose (testcontainers#2511)
  ...
  • Loading branch information
mdelapenya committed May 7, 2024
2 parents 459e58d + 5fa6548 commit d86e692
Show file tree
Hide file tree
Showing 242 changed files with 6,423 additions and 3,143 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// README at: https://github.com/devcontainers/templates/tree/main/src/go
{
"name": "Go",
"image": "mcr.microsoft.com/devcontainers/go:0-1.21-bullseye",
"image": "mcr.microsoft.com/devcontainers/go:1.21-bookworm",

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},
Expand Down
3 changes: 3 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# These are supported funding model platforms

github: [testcontainers]
6 changes: 4 additions & 2 deletions .github/workflows/ci-test-go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ jobs:
continue-on-error: ${{ !inputs.fail-fast }}
env:
TESTCONTAINERS_RYUK_DISABLED: "${{ inputs.ryuk-disabled }}"
RYUK_CONNECTION_TIMEOUT: "${{ inputs.project-directory == 'modules/compose' && '5m' || '60s' }}"
RYUK_RECONNECTION_TIMEOUT: "${{ inputs.project-directory == 'modules/compose' && '30s' || '10s' }}"
steps:
- name: Setup rootless Docker
if: ${{ inputs.rootless-docker }}
Expand All @@ -72,7 +74,7 @@ jobs:
- 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' }}
uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3
uses: golangci/golangci-lint-action@9d1e0624a798bb64f6c3cea93db47765312263dc # v5
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.55.2
Expand Down Expand Up @@ -121,7 +123,7 @@ jobs:
./scripts/check_environment.sh
- name: Test Summary
uses: test-summary/action@fee35d7df20790255fe6aa92cf0f6d28092ecf2f # v2
uses: test-summary/action@032c8a9cec6aaa3c20228112cae6ca10a3b29336 # v2.3
with:
paths: "**/${{ inputs.project-directory }}/TEST-unit*.xml"
if: always()
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ jobs:
matrix:
go-version: [1.21.x, 1.x]
platform: [ubuntu-latest]
module: [artemis, cassandra, chroma, clickhouse, cockroachdb, compose, consul, couchbase, elasticsearch, gcloud, inbucket, influxdb, k3s, k6, kafka, localstack, mariadb, milvus, minio, mockserver, mongodb, mssql, mysql, nats, neo4j, ollama, openfga, openldap, opensearch, postgres, pulsar, qdrant, rabbitmq, redis, redpanda, registry, surrealdb, vault, weaviate]
module: [artemis, cassandra, chroma, clickhouse, cockroachdb, compose, consul, couchbase, dolt, elasticsearch, gcloud, inbucket, influxdb, k3s, k6, kafka, localstack, mariadb, milvus, minio, mockserver, mongodb, mssql, mysql, nats, neo4j, ollama, openfga, openldap, opensearch, postgres, pulsar, qdrant, rabbitmq, redis, redpanda, registry, surrealdb, vault, weaviate]
uses: ./.github/workflows/ci-test-go.yml
with:
go-version: ${{ matrix.go-version }}
Expand Down
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ linters:
- misspell
- nonamedreturns
- testifylint
- errcheck

linters-settings:
errorlint:
Expand Down
4 changes: 4 additions & 0 deletions .vscode/.testcontainers-go.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
"name": "module / couchbase",
"path": "../modules/couchbase"
},
{
"name": "module / dolt",
"path": "../modules/dolt"
},
{
"name": "module / elasticsearch",
"path": "../modules/elasticsearch"
Expand Down
2 changes: 1 addition & 1 deletion Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ verify_ssl = true
mkdocs = "==1.5.3"
mkdocs-codeinclude-plugin = "==0.2.1"
mkdocs-include-markdown-plugin = "==6.0.4"
mkdocs-material = "==9.5.13"
mkdocs-material = "==9.5.18"
mkdocs-markdownextradata-plugin = "==0.2.5"

[requires]
Expand Down
233 changes: 110 additions & 123 deletions Pipfile.lock

Large diffs are not rendered by default.

28 changes: 20 additions & 8 deletions container.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ type Container interface {
Endpoint(context.Context, string) (string, error) // get proto://ip:port string for the first exposed port
PortEndpoint(context.Context, nat.Port, string) (string, error) // get proto://ip:port string for the given exposed port
Host(context.Context) (string, error) // get host where the container port is exposed
Inspect(context.Context) (*types.ContainerJSON, error) // get container info
MappedPort(context.Context, nat.Port) (nat.Port, error) // get externally mapped port for a container port
Ports(context.Context) (nat.PortMap, error) // get all exposed ports
Ports(context.Context) (nat.PortMap, error) // Deprecated: Use c.Inspect(ctx).NetworkSettings.Ports instead
SessionID() string // get session id
IsRunning() bool
Start(context.Context) error // start the container
Expand All @@ -50,7 +51,7 @@ type Container interface {
FollowOutput(LogConsumer) // Deprecated: it will be removed in the next major release
StartLogProducer(context.Context, ...LogProductionOption) error // Deprecated: Use the ContainerRequest instead
StopLogProducer() error // Deprecated: it will be removed in the next major release
Name(context.Context) (string, error) // get container name
Name(context.Context) (string, error) // Deprecated: Use c.Inspect(ctx).Name instead
State(context.Context) (*types.ContainerState, error) // returns container's running state
Networks(context.Context) ([]string, error) // get container networks
NetworkAliases(context.Context) (map[string][]string, error) // get container network aliases for a network
Expand Down Expand Up @@ -122,6 +123,7 @@ func (c *ContainerFile) validate() error {
// ContainerRequest represents the parameters used to get a running container
type ContainerRequest struct {
FromDockerfile
HostAccessPorts []int
Image string
ImageSubstitutors []ImageSubstitutor
Entrypoint []string
Expand Down Expand Up @@ -222,13 +224,17 @@ func (c *ContainerRequest) GetContext() (io.Reader, error) {
}
c.Context = abs

excluded, err := parseDockerIgnore(abs)
dockerIgnoreExists, excluded, err := parseDockerIgnore(abs)
if err != nil {
return nil, err
}

dockerIgnoreLocation := filepath.Join(abs, ".dockerignore")
includes = append(includes, dockerIgnoreLocation, c.GetDockerfile())
if dockerIgnoreExists {
// only add .dockerignore if it exists
includes = append(includes, ".dockerignore")
}

includes = append(includes, c.GetDockerfile())

buildContext, err := archive.TarWithOptions(
c.Context,
Expand All @@ -241,18 +247,24 @@ func (c *ContainerRequest) GetContext() (io.Reader, error) {
return buildContext, nil
}

func parseDockerIgnore(targetDir string) ([]string, error) {
// parseDockerIgnore returns if the file exists, the excluded files and an error if any
func parseDockerIgnore(targetDir string) (bool, []string, error) {
// based on https://github.com/docker/cli/blob/master/cli/command/image/build/dockerignore.go#L14
fileLocation := filepath.Join(targetDir, ".dockerignore")
var excluded []string
exists := false
if f, openErr := os.Open(fileLocation); openErr == nil {
defer f.Close()

exists = true

var err error
excluded, err = ignorefile.ReadAll(f)
if err != nil {
return excluded, fmt.Errorf("error reading .dockerignore: %w", err)
return true, excluded, fmt.Errorf("error reading .dockerignore: %w", err)
}
}
return excluded, nil
return exists, excluded, nil
}

// GetBuildArgs returns the env args to be used when creating from Dockerfile
Expand Down
11 changes: 10 additions & 1 deletion container_ignore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,32 @@ import (
func TestParseDockerIgnore(t *testing.T) {
testCases := []struct {
filePath string
exists bool
expectedErr error
expectedExcluded []string
}{
{
filePath: "./testdata/dockerignore",
expectedErr: nil,
exists: true,
expectedExcluded: []string{"vendor", "foo", "bar"},
},
{
filePath: "./testdata",
expectedErr: nil,
exists: true,
expectedExcluded: []string{"Dockerfile", "echo.Dockerfile"},
},
{
filePath: "./testdata/data",
expectedErr: nil,
expectedExcluded: nil, // it's nil because the parseDockerIgnore function uses the zero value of a slice
},
}

for _, testCase := range testCases {
excluded, err := parseDockerIgnore(testCase.filePath)
exists, excluded, err := parseDockerIgnore(testCase.filePath)
assert.Equal(t, testCase.exists, exists)
assert.Equal(t, testCase.expectedErr, err)
assert.Equal(t, testCase.expectedExcluded, excluded)
}
Expand Down
Loading

0 comments on commit d86e692

Please sign in to comment.