Skip to content

Commit 6c71f27

Browse files
committed
Merge branch 'main' into windows-fixes
* main: ci: add generate for mocks (testcontainers#2774) fix: docker config error handling when config file does not exist (testcontainers#2772) docs: refine heading badges in README (testcontainers#2770) feat(wait): for file (testcontainers#2731) feat(compose): select services via profiles (testcontainers#2758) chore(deps): bump mkdocs-markdownextradata-plugin from 0.2.5 to 0.2.6 (testcontainers#2761) fix: update template too (testcontainers#2763) chore(deps): bump actions/checkout from 4.1.1 to 4.1.7 (testcontainers#2762) chore(deps): bump mkdocs-include-markdown-plugin from 6.0.4 to 6.2.2 (testcontainers#2760) fix: check if the discovered docker socket responds (testcontainers#2741) Upgrade milvus-io/milvus-sdk-go to avoid checksum mismatch. (testcontainers#2753) Fix trailing slash on Image Prefix (testcontainers#2747) chore: use new testcontainers/ryuk:0.9.0 image (testcontainers#2750)
2 parents 63722a8 + b4f8294 commit 6c71f27

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+1576
-356
lines changed

.github/workflows/ci-test-go.yml

+14-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
run: sudo rm -rf /var/run/docker.sock
6363

6464
- name: Check out code into the Go module directory
65-
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
65+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
6666

6767
- name: Set up Go
6868
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5
@@ -85,13 +85,25 @@ jobs:
8585
# takes precedence over all other caching options.
8686
skip-cache: true
8787

88+
- name: generate
89+
if: ${{ inputs.platform == 'ubuntu-latest' }}
90+
working-directory: ./${{ inputs.project-directory }}
91+
shell: bash
92+
run: |
93+
make generate
94+
git --no-pager diff && [[ 0 -eq $(git status --porcelain | wc -l) ]]
95+
8896
- name: modVerify
8997
working-directory: ./${{ inputs.project-directory }}
9098
run: go mod verify
9199

92100
- name: modTidy
101+
if: ${{ inputs.platform == 'ubuntu-latest' }}
93102
working-directory: ./${{ inputs.project-directory }}
94-
run: make tidy
103+
shell: bash
104+
run: |
105+
make tidy
106+
git --no-pager diff && [[ 0 -eq $(git status --porcelain | wc -l) ]]
95107
96108
- name: ensure compilation
97109
working-directory: ./${{ inputs.project-directory }}

.github/workflows/ci-windows.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
})
2525
2626
- name: Checkout
27-
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
27+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
2828
with:
2929
token: ${{ secrets.GITHUB_TOKEN }}
3030
repository: ${{ github.event.client_payload.pull_request.head.repo.full_name }}

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ jobs:
129129
runs-on: ubuntu-latest
130130
steps:
131131
- name: Check out code into the Go module directory
132-
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1
132+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
133133
with:
134134
# Disabling shallow clone is recommended for improving relevancy of reporting
135135
fetch-depth: 0

.github/workflows/codeql.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949

5050
steps:
5151
- name: Checkout repository
52-
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
52+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
5353

5454
# Initializes the CodeQL tools for scanning.
5555
- name: Initialize CodeQL

.github/workflows/docker-moby-latest.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
run: sudo rm -rf /var/run/docker.sock
2828

2929
- name: Check out code into the Go module directory
30-
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
30+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
3131

3232
- name: Set up Go
3333
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5

.github/workflows/scorecards.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020

2121
steps:
2222
- name: "Checkout code"
23-
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
23+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4
2424
with:
2525
persist-credentials: false
2626

.mockery.yaml

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
quiet: True
2+
disable-version-string: True
3+
with-expecter: True
4+
mockname: "mock{{.InterfaceName}}"
5+
filename: "{{ .InterfaceName | lower }}_mock_test.go"
6+
outpkg: "{{.PackageName}}_test"
7+
dir: "{{.InterfaceDir}}"
8+
packages:
9+
github.com/testcontainers/testcontainers-go/wait:
10+
interfaces:
11+
StrategyTarget:

Pipfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ verify_ssl = true
88
[packages]
99
mkdocs = "==1.5.3"
1010
mkdocs-codeinclude-plugin = "==0.2.1"
11-
mkdocs-include-markdown-plugin = "==6.2.1"
11+
mkdocs-include-markdown-plugin = "==6.2.2"
1212
mkdocs-material = "==9.5.18"
13-
mkdocs-markdownextradata-plugin = "==0.2.5"
13+
mkdocs-markdownextradata-plugin = "==0.2.6"
1414

1515
[requires]
1616
python_version = "3.8"

Pipfile.lock

+114-108
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+3-16
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,14 @@
11
# Testcontainers
22

3-
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=141451032&machine=standardLinux32gb&devcontainer_path=.devcontainer%2Fdevcontainer.json&location=EastUs)
4-
5-
**Builds**
6-
73
[![Main pipeline](https://github.com/testcontainers/testcontainers-go/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/testcontainers/testcontainers-go/actions/workflows/ci.yml)
8-
9-
**Documentation**
10-
114
[![GoDoc Reference](https://pkg.go.dev/badge/github.com/testcontainers/testcontainers-go.svg)](https://pkg.go.dev/github.com/testcontainers/testcontainers-go)
12-
13-
**Social**
14-
15-
[![Slack](https://img.shields.io/badge/Slack-4A154B?logo=slack)](https://testcontainers.slack.com/)
16-
17-
**Code quality**
18-
195
[![Go Report Card](https://goreportcard.com/badge/github.com/testcontainers/testcontainers-go)](https://goreportcard.com/report/github.com/testcontainers/testcontainers-go)
206
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=testcontainers_testcontainers-go&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=testcontainers_testcontainers-go)
7+
[![License](https://img.shields.io/badge/license-MIT-blue)](https://github.com/testcontainers/testcontainers-go/blob/main/LICENSE)
218

22-
**License**
9+
[![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=141451032&machine=standardLinux32gb&devcontainer_path=.devcontainer%2Fdevcontainer.json&location=EastUs)
2310

24-
[![License](https://img.shields.io/badge/license-MIT-blue)](https://github.com/testcontainers/testcontainers-go/blob/main/LICENSE)
11+
[![Join our Slack](https://img.shields.io/badge/Slack-4A154B?logo=slack)](https://testcontainers.slack.com/)
2512

2613
_Testcontainers for Go_ is a Go package that makes it simple to create and clean up container-based dependencies for
2714
automated integration/smoke tests. The clean, easy-to-use API enables developers to programmatically define containers

commons-test.mk

+13-2
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ $(GOBIN)/golangci-lint:
1111
$(GOBIN)/gotestsum:
1212
$(call go_install,gotest.tools/gotestsum@latest)
1313

14+
$(GOBIN)/mockery:
15+
$(call go_install,github.com/vektra/mockery/v2@v2.45)
16+
1417
.PHONY: install
15-
install: $(GOBIN)/golangci-lint $(GOBIN)/gotestsum
18+
install: $(GOBIN)/golangci-lint $(GOBIN)/gotestsum $(GOBIN)/mockery
1619

1720
.PHONY: clean
1821
clean:
1922
rm $(GOBIN)/golangci-lint
2023
rm $(GOBIN)/gotestsum
24+
rm $(GOBIN)/mockery
2125

2226
.PHONY: dependencies-scan
2327
dependencies-scan:
@@ -26,7 +30,11 @@ dependencies-scan:
2630

2731
.PHONY: lint
2832
lint: $(GOBIN)/golangci-lint
29-
golangci-lint run --out-format=github-actions --path-prefix=. --verbose -c $(ROOT_DIR)/.golangci.yml --fix
33+
golangci-lint run --out-format=colored-line-number --path-prefix=. --verbose -c $(ROOT_DIR)/.golangci.yml --fix
34+
35+
.PHONY: generate
36+
generate: $(GOBIN)/mockery
37+
go generate ./...
3038

3139
.PHONY: test-%
3240
test-%: $(GOBIN)/gotestsum
@@ -51,3 +59,6 @@ test-tools: $(GOBIN)/gotestsum
5159
.PHONY: tidy
5260
tidy:
5361
go mod tidy
62+
63+
.PHONY: pre-commit
64+
pre-commit: generate tidy lint

docker_auth.go

+20-29
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"encoding/json"
99
"errors"
1010
"fmt"
11-
"io"
1211
"net/url"
1312
"os"
1413
"sync"
@@ -137,24 +136,12 @@ func (c *credentialsCache) Get(hostname, configKey string) (string, string, erro
137136
return user, password, nil
138137
}
139138

140-
// configFileKey returns a key to use for caching credentials based on
139+
// configKey returns a key to use for caching credentials based on
141140
// the contents of the currently active config.
142-
func configFileKey() (string, error) {
143-
configPath, err := dockercfg.ConfigPath()
144-
if err != nil {
145-
return "", err
146-
}
147-
148-
f, err := os.Open(configPath)
149-
if err != nil {
150-
return "", fmt.Errorf("open config file: %w", err)
151-
}
152-
153-
defer f.Close()
154-
141+
func configKey(cfg *dockercfg.Config) (string, error) {
155142
h := md5.New()
156-
if _, err := io.Copy(h, f); err != nil {
157-
return "", fmt.Errorf("copying config file: %w", err)
143+
if err := json.NewEncoder(h).Encode(cfg); err != nil {
144+
return "", fmt.Errorf("encode config: %w", err)
158145
}
159146

160147
return hex.EncodeToString(h.Sum(nil)), nil
@@ -165,10 +152,14 @@ func configFileKey() (string, error) {
165152
func getDockerAuthConfigs() (map[string]registry.AuthConfig, error) {
166153
cfg, err := getDockerConfig()
167154
if err != nil {
155+
if errors.Is(err, os.ErrNotExist) {
156+
return map[string]registry.AuthConfig{}, nil
157+
}
158+
168159
return nil, err
169160
}
170161

171-
configKey, err := configFileKey()
162+
key, err := configKey(cfg)
172163
if err != nil {
173164
return nil, err
174165
}
@@ -195,7 +186,7 @@ func getDockerAuthConfigs() (map[string]registry.AuthConfig, error) {
195186
switch {
196187
case ac.Username == "" && ac.Password == "":
197188
// Look up credentials from the credential store.
198-
u, p, err := creds.Get(k, configKey)
189+
u, p, err := creds.Get(k, key)
199190
if err != nil {
200191
results <- authConfigResult{err: err}
201192
return
@@ -218,7 +209,7 @@ func getDockerAuthConfigs() (map[string]registry.AuthConfig, error) {
218209
go func(k string) {
219210
defer wg.Done()
220211

221-
u, p, err := creds.Get(k, configKey)
212+
u, p, err := creds.Get(k, key)
222213
if err != nil {
223214
results <- authConfigResult{err: err}
224215
return
@@ -260,20 +251,20 @@ func getDockerAuthConfigs() (map[string]registry.AuthConfig, error) {
260251
// 1. the DOCKER_AUTH_CONFIG environment variable, unmarshalling it into a dockercfg.Config
261252
// 2. the DOCKER_CONFIG environment variable, as the path to the config file
262253
// 3. else it will load the default config file, which is ~/.docker/config.json
263-
func getDockerConfig() (dockercfg.Config, error) {
264-
dockerAuthConfig := os.Getenv("DOCKER_AUTH_CONFIG")
265-
if dockerAuthConfig != "" {
266-
cfg := dockercfg.Config{}
267-
err := json.Unmarshal([]byte(dockerAuthConfig), &cfg)
268-
if err == nil {
269-
return cfg, nil
254+
func getDockerConfig() (*dockercfg.Config, error) {
255+
if env := os.Getenv("DOCKER_AUTH_CONFIG"); env != "" {
256+
var cfg dockercfg.Config
257+
if err := json.Unmarshal([]byte(env), &cfg); err != nil {
258+
return nil, fmt.Errorf("unmarshal DOCKER_AUTH_CONFIG: %w", err)
270259
}
260+
261+
return &cfg, nil
271262
}
272263

273264
cfg, err := dockercfg.LoadDefaultConfig()
274265
if err != nil {
275-
return cfg, err
266+
return nil, fmt.Errorf("load default config: %w", err)
276267
}
277268

278-
return cfg, nil
269+
return &cfg, nil
279270
}

0 commit comments

Comments
 (0)