Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

break: disable reaper at config level #941

Merged
merged 37 commits into from
Mar 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
67613e2
chore: move TestContainers config to a separate file
mdelapenya Mar 14, 2023
69d5fff
chore: rename to readConfig
mdelapenya Mar 14, 2023
1e0a3fb
break: rename struct to honour project's name
mdelapenya Mar 14, 2023
f64f938
chore: add names to test table
mdelapenya Mar 14, 2023
7f45a61
chore: support for disabling Ryuk at the configuration layer
mdelapenya Mar 14, 2023
38e28b7
chore: rename to doReadConfig
mdelapenya Mar 14, 2023
d30e16e
chore: read tc config just once
mdelapenya Mar 14, 2023
1b7e3d6
chore: deprecate SkipReaper
mdelapenya Mar 14, 2023
7704d76
chore: add a pipeline for tests without Ryuk
mdelapenya Mar 14, 2023
cbdb265
docs: document Ryuk
mdelapenya Mar 14, 2023
76e6986
chore: use same message when disabling Ryuk
mdelapenya Mar 14, 2023
1935912
chore: print reaper banner when reading properties for first time
mdelapenya Mar 15, 2023
e01ad91
chore: expose reading TC config
mdelapenya Mar 15, 2023
9f27165
break: do not return the config when retrieving a Docker client
mdelapenya Mar 15, 2023
e754c24
break: do not return the Docker Host when retrieving a Docker client
mdelapenya Mar 15, 2023
068974c
chore: simplify reaper-off pipeline
mdelapenya Mar 15, 2023
bfaafe7
chore: skip reaper test when it's disabled
mdelapenya Mar 15, 2023
9532872
fix: update tests
mdelapenya Mar 15, 2023
560672a
fix: default for docker host
mdelapenya Mar 15, 2023
adcd422
fix: create the Docker provider properly
mdelapenya Mar 15, 2023
b1d41b0
fix: rename GH check for reaper-off
mdelapenya Mar 15, 2023
44e9d42
chore: remove old static-analysis checks
mdelapenya Mar 15, 2023
7c22bc2
fix: remove containers in tests
mdelapenya Mar 15, 2023
d053727
fix: remove more containers in tests
mdelapenya Mar 15, 2023
0bd383f
chore: extract to constants
mdelapenya Mar 15, 2023
e9048f3
chore: enable Ryuk using env vars at GH workflow
mdelapenya Mar 15, 2023
f52657b
fix: reset test environment
mdelapenya Mar 15, 2023
d1d8caa
fix: typo
mdelapenya Mar 15, 2023
e652d2a
chore: log when the properties file is found
mdelapenya Mar 15, 2023
acf23a1
fix: reset config's syncOnce in tests
mdelapenya Mar 15, 2023
dda07cf
chore: proper config state in tests
mdelapenya Mar 15, 2023
1f2e835
chore: do not reset the sync
mdelapenya Mar 16, 2023
dd628e7
fix: remove containers in tests
mdelapenya Mar 16, 2023
fdca162
chore: remove duplicated test
mdelapenya Mar 16, 2023
b981a9e
docs: document the config
mdelapenya Mar 20, 2023
e22dafc
fix: remove paragraph
mdelapenya Mar 20, 2023
ee9a640
fix: proper escaping message
mdelapenya Mar 20, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions .github/workflows/ci-reaper-off.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Reaper-Off pipeline

on: [push, pull_request]

concurrency:
group: "${{ github.workflow }}-${{ github.head_ref || github.sha }}"
cancel-in-progress: true

jobs:
test-reaper-off:
strategy:
matrix:
go-version: [1.19.x, 1.x]
runs-on: ubuntu-latest
env:
TESTCONTAINERS_RYUK_DISABLED: "true"

steps:
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go-version }}
id: go

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

- name: gotestsum
# only run tests on linux, there are a number of things that won't allow the tests to run on anything else
# many (maybe, all?) images used can only be build on Linux, they don't have Windows in their manifest, and
# we can't put Windows Server in "Linux Mode" in Github actions
# another, host mode is only available on Linux, and we have tests around that, do we skip them?
run: make test-unit

- name: Run checker
run: |
./scripts/check_environment.sh

- name: Test Summary
uses: test-summary/action@4ee9ece4bca777a38f05c8fc578ac2007fe266f7
with:
paths: "**/TEST-*.xml"
if: always()
2 changes: 2 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ jobs:
go-version: [1.19.x, 1.x]
platform: [ubuntu-latest, windows-latest, macos-latest]
runs-on: ${{ matrix.platform }}
env:
TESTCONTAINERS_RYUK_DISABLED: "false"
steps:

- name: Set up Go
Expand Down
101 changes: 101 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
package testcontainers

import (
"fmt"
"os"
"path/filepath"
"strconv"
"sync"

"github.com/magiconair/properties"
)

var tcConfig TestcontainersConfig
var tcConfigOnce *sync.Once = new(sync.Once)

// TestcontainersConfig represents the configuration for Testcontainers
// testcontainersConfig {
type TestcontainersConfig struct {
Host string `properties:"docker.host,default="`
TLSVerify int `properties:"docker.tls.verify,default=0"`
CertPath string `properties:"docker.cert.path,default="`
RyukDisabled bool `properties:"ryuk.disabled,default=false"`
RyukPrivileged bool `properties:"ryuk.container.privileged,default=false"`
}

// }

// ReadConfig reads from testcontainers properties file, storing the result in a singleton instance
// of the TestcontainersConfig struct
func ReadConfig() TestcontainersConfig {
tcConfigOnce.Do(func() {
tcConfig = readConfig()

if tcConfig.RyukDisabled {
ryukDisabledMessage := `
**********************************************************************************************
Ryuk has been disabled for the current execution. This can cause unexpected behavior in your environment.
More on this: https://golang.testcontainers.org/features/garbage_collector/
**********************************************************************************************`
Logger.Printf(ryukDisabledMessage)
Logger.Printf("\n%+v", tcConfig)
}
})

return tcConfig
}

// readConfig reads from testcontainers properties file, if it exists
// it is possible that certain values get overridden when set as environment variables
func readConfig() TestcontainersConfig {
config := TestcontainersConfig{}

applyEnvironmentConfiguration := func(config TestcontainersConfig) TestcontainersConfig {
if dockerHostEnv := os.Getenv("DOCKER_HOST"); dockerHostEnv != "" {
config.Host = dockerHostEnv
}
if config.Host == "" {
config.Host = "unix:///var/run/docker.sock"
}

ryukDisabledEnv := os.Getenv("TESTCONTAINERS_RYUK_DISABLED")
if parseBool(ryukDisabledEnv) {
config.RyukDisabled = ryukDisabledEnv == "true"
}

ryukPrivilegedEnv := os.Getenv("TESTCONTAINERS_RYUK_CONTAINER_PRIVILEGED")
if parseBool(ryukPrivilegedEnv) {
config.RyukPrivileged = ryukPrivilegedEnv == "true"
}

return config
}

home, err := os.UserHomeDir()
if err != nil {
return applyEnvironmentConfiguration(config)
}

tcProp := filepath.Join(home, ".testcontainers.properties")
// init from a file
properties, err := properties.LoadFile(tcProp, properties.UTF8)
if err != nil {
return applyEnvironmentConfiguration(config)
}

if err := properties.Decode(&config); err != nil {
fmt.Printf("invalid testcontainers properties file, returning an empty Testcontainers configuration: %v\n", err)
return applyEnvironmentConfiguration(config)
}

fmt.Printf("Testcontainers properties file has been found: %s\n", tcProp)

return applyEnvironmentConfiguration(config)
}

func parseBool(input string) bool {
if _, err := strconv.ParseBool(input); err == nil {
return true
}
return false
}
Loading