Skip to content

Commit

Permalink
Merge branch 'main' into context-support
Browse files Browse the repository at this point in the history
* main:
  docs: better contribution guidelines (testcontainers#2893)
  fix(influxdb): Respect custom waitStrategy (testcontainers#2845)
  • Loading branch information
mdelapenya committed Nov 25, 2024
2 parents bc2f04b + 892cb08 commit dc571d3
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 101 deletions.
7 changes: 7 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
include ./commons-test.mk

.PHONY: lint-all
lint-all:
$(MAKE) lint
$(MAKE) -C modulegen lint
$(MAKE) -C examples lint-examples
$(MAKE) -C modules lint-modules

.PHONY: test-all
test-all: tools test-tools test-unit

Expand Down
105 changes: 91 additions & 14 deletions docs/contributing.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,93 @@
# Contributing

* Star the project on [Github](https://github.com/testcontainers/testcontainers-go) and help spread the word :)
* Join our [Slack workspace](http://slack.testcontainers.org)
* [Post an issue](https://github.com/testcontainers/testcontainers-go/issues) if you find any bugs
* Contribute improvements or fixes using a [Pull Request](https://github.com/testcontainers/testcontainers-go/pulls). If you're going to contribute, thank you! Please just be sure to:
* discuss with the authors on an issue ticket prior to doing anything big.
* follow the style, naming and structure conventions of the rest of the project.
* make commits atomic and easy to merge.
* when updating documentation, please see [our guidance for documentation contributions](contributing_docs.md).
* when updating the `go.mod` file, please run `make tidy-all` to ensure all modules are updated. It will run `golangci-lint` with the configuration set in the root directory of the project. Please be aware that the lint stage could fail if this is not done.
* apply format running `make lint`
* For examples: `make -C examples lint`
* For modules: `make -C modules lint`
* verify all tests are passing. Build and test the project with `make test-all` to do this.
* For a given module or example, go to the module or example directory and run `make test`.
`Testcontainers for Go` is open source, and we love to receive contributions from our community — you!

There are many ways to contribute, from writing tutorials or blog posts, improving the documentation, submitting bug reports and feature requests, or writing code for the core library or for a technology module.

In any case, if you like the project, please star the project on [Github](https://github.com/testcontainers/testcontainers-go/stargazers) and help spread the word :)
Also join our [Slack workspace](http://slack.testcontainers.org) to get help, share your ideas, and chat with the community.

## Questions

GitHub is reserved for bug reports and feature requests; it is not the place for general questions.
If you have a question or an unconfirmed bug, please visit our [Slack workspace](https://testcontainers.slack.com/);
feedback and ideas are always welcome.

## Code contributions

If you have a bug fix or new feature that you would like to contribute, please find or open an [issue](https://github.com/testcontainers/testcontainers-go/issues) first.
It's important to talk about what you would like to do, as there may already be someone working on it,
or there may be context to be aware of before implementing the change.

Next would be to fork the repository and make your changes in a feature branch. **Please do not commit changes to the `main` branch**,
otherwise we won't be able to contribute to your changes directly in the PR.

### Submitting your changes

Please just be sure to:

* follow the style, naming and structure conventions of the rest of the project.
* make commits atomic and easy to merge.
* use [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) for the PR title. This will help us to understand the nature of the changes, and to generate the changelog after all the commits in the PR are squashed.
* use [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) for your commit messages, as it improves the readability of the commit history, and the review process.
* unless necessary, please try to **avoid pushing --force** to the published branch you submitted a PR from, as it makes it harder to review the changes from a given previous state.
* apply format running `make lint-all`. It will run `golangci-lint` for the core and modules with the configuration set in the root directory of the project. Please be aware that the lint stage on CI could fail if this is not done.
* For linting just the modules: `make -C modules lint-modules`
* For linting just the examples: `make -C examples lint-examples`
* For linting just the modulegen: `make -C modulegen lint`
* verify all tests are passing. Build and test the project with `make test-all` to do this.
* For a given module or example, go to the module or example directory and run `make test`.
* If you find an `ld warning` message on MacOS, you can ignore it. It is a indeed a warning: https://github.com/golang/go/issues/61229
> === Errors
> ld: warning: '/private/var/folders/3y/8hbf585d4yl6f8j5yzqx6wz80000gn/T/go-link-2319589277/000018.o' has malformed LC_DYSYMTAB, expected 98 undefined symbols to start at index 1626, found 95 undefined symbols starting at index 1626
* when updating the `go.mod` file, please run `make tidy-all` to ensure all modules are updated.

## Documentation contributions

The _Testcontainers for Go_ documentation is a static site built with [MkDocs](https://www.mkdocs.org/).
We use the [Material for MkDocs](https://squidfunk.github.io/mkdocs-material/) theme, which offers a number of useful extensions to MkDocs.

We publish our documentation using Netlify.

### Adding code snippets

To include code snippets in the documentation, we use the [codeinclude plugin](https://github.com/rnorth/mkdocs-codeinclude-plugin), which uses the following syntax:

> &lt;!--codeinclude--&gt;<br/>
> &#91;Human readable title for snippet&#93;(./relative_path_to_example_code.go) targeting_expression<br/>
> &#91;Human readable title for snippet&#93;(./relative_path_to_example_code.go) targeting_expression<br/>
> &lt;!--/codeinclude--&gt;<br/>
Where each title snippet in the same `codeinclude` block would represent a new tab
in the snippet, and each `targeting_expression` would be:

- `block:someString` or
- `inside_block:someString`

Please refer to the [codeinclude plugin documentation](https://github.com/rnorth/mkdocs-codeinclude-plugin) for more information.

### Previewing rendered content

#### Using Python locally

From the root directory of the repository, you can use the following command to build and serve the documentation locally:

```shell
make serve-docs
```

It will use a Python's virtual environment to install the required dependencies and start a local server at `http://localhost:8000`.

Once finished, you can destroy the virtual environment with the following command:

```shell
make clean-docs
```

#### PR Preview deployments

Note that documentation for pull requests will automatically be published by Netlify as 'deploy previews'.
These deployment previews can be accessed via the `deploy/netlify` check that appears for each pull request.

Please check the Github comment Netlify posts on the PR for the URL to the deployment preview.
46 changes: 0 additions & 46 deletions docs/contributing_docs.md

This file was deleted.

4 changes: 1 addition & 3 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,7 @@ nav:
- system_requirements/ci/gitlab_ci.md
- system_requirements/ci/tekton.md
- system_requirements/ci/travis.md
- Contributing:
- contributing.md
- contributing_docs.md
- Contributing: contributing.md
- Getting help: getting_help.md
edit_uri: edit/main/docs/
extra:
Expand Down
2 changes: 1 addition & 1 deletion modulegen/internal/mkdocs/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Config struct {
Examples []string `yaml:"Examples,omitempty"`
Modules []string `yaml:"Modules,omitempty"`
SystemRequirements []interface{} `yaml:"System Requirements,omitempty"`
Contributing []string `yaml:"Contributing,omitempty"`
Contributing string `yaml:"Contributing,omitempty"`
GettingHelp string `yaml:"Getting help,omitempty"`
} `yaml:"nav"`
EditURI string `yaml:"edit_uri"`
Expand Down
61 changes: 24 additions & 37 deletions modules/influxdb/influxdb.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ package influxdb

import (
"context"
"encoding/json"
"fmt"
"io"
"path"
"strings"

"github.com/testcontainers/testcontainers-go"
"github.com/testcontainers/testcontainers-go/wait"
Expand Down Expand Up @@ -34,7 +35,7 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom
"INFLUXDB_HTTP_HTTPS_ENABLED": "false",
"INFLUXDB_HTTP_AUTH_ENABLED": "false",
},
WaitingFor: wait.ForListeningPort("8086/tcp"),
WaitingFor: waitForHttpHealth(),
}
genericContainerReq := testcontainers.GenericContainerRequest{
ContainerRequest: req,
Expand All @@ -47,38 +48,6 @@ func Run(ctx context.Context, img string, opts ...testcontainers.ContainerCustom
}
}

hasInitDb := false

for _, f := range genericContainerReq.Files {
if f.ContainerFilePath == "/" && strings.HasSuffix(f.HostFilePath, "docker-entrypoint-initdb.d") {
// Init service in container will start influxdb, run scripts in docker-entrypoint-initdb.d and then
// terminate the influxdb server, followed by restart of influxdb. This is tricky to wait for, and
// in this case, we are assuming that data was added by init script, so we then look for an
// "Open shard" which is the last thing that happens before the server is ready to accept connections.
// This is probably different for InfluxDB 2.x, but that is left as an exercise for the reader.
strategies := []wait.Strategy{
genericContainerReq.WaitingFor,
wait.ForLog("influxdb init process in progress..."),
wait.ForLog("Server shutdown completed"),
wait.ForLog("Opened shard"),
}
genericContainerReq.WaitingFor = wait.ForAll(strategies...)
hasInitDb = true
break
}
}

if !hasInitDb {
if lastIndex := strings.LastIndex(genericContainerReq.Image, ":"); lastIndex != -1 {
tag := genericContainerReq.Image[lastIndex+1:]
if tag == "latest" || tag[0] == '2' {
genericContainerReq.WaitingFor = wait.ForLog(`Listening log_id=[0-9a-zA-Z_~]+ service=tcp-listener transport=http`).AsRegexp()
}
} else {
genericContainerReq.WaitingFor = wait.ForLog("Listening for signals")
}
}

container, err := testcontainers.GenericContainer(ctx, genericContainerReq)
var c *InfluxDbContainer
if container != nil {
Expand Down Expand Up @@ -147,9 +116,8 @@ func WithConfigFile(configFile string) testcontainers.CustomizeRequestOption {
}
}

// WithInitDb will copy a 'docker-entrypoint-initdb.d' directory to the container.
// The secPath is the path to the directory on the host machine.
// The directory will be copied to the root of the container.
// WithInitDb returns a request customizer that initialises the database using the file `docker-entrypoint-initdb.d`
// located in `srcPath` directory.
func WithInitDb(srcPath string) testcontainers.CustomizeRequestOption {
return func(req *testcontainers.GenericContainerRequest) error {
cf := testcontainers.ContainerFile{
Expand All @@ -158,6 +126,25 @@ func WithInitDb(srcPath string) testcontainers.CustomizeRequestOption {
FileMode: 0o755,
}
req.Files = append(req.Files, cf)

req.WaitingFor = wait.ForAll(
wait.ForLog("Server shutdown completed"),
waitForHttpHealth(),
)
return nil
}
}

func waitForHttpHealth() *wait.HTTPStrategy {
return wait.ForHTTP("/health").
WithResponseMatcher(func(body io.Reader) bool {
decoder := json.NewDecoder(body)
r := struct {
Status string `json:"status"`
}{}
if err := decoder.Decode(&r); err != nil {
return false
}
return r.Status == "pass"
})
}

0 comments on commit dc571d3

Please sign in to comment.