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

feat(compose): select services via profiles #2758

Merged
merged 1 commit into from
Sep 2, 2024

Conversation

ngrash
Copy link
Contributor

@ngrash ngrash commented Aug 31, 2024

What does this PR do?

This PR adds the option to use Compose profiles to enable/disable services based on the profiles defined in the compose file:

func WithProfiles(profiles ...string) ComposeStackOption

The current behavior is not changed unless WithProfiles is used.

Why is it important?

We would like to use our existing Compose files with testcontainers-go/modules/compose to set up test environments locally and in our pipelines.

However, our workflow relies on Compose profiles, which currently makes the use of testcontainers-go/modules/compose impossible, as only services without profiles are enabled by default.

Our workaround is to set up the test environment via the Compose CLI, but we think this could be well automated if testcontainers-go supported Compose profiles.

Related issues

How to test this PR

To only run the tests for this individual feature, you can run go test -v -run TestDockerComposeAPIWithProfiles in modules/compose.

In addition to the unit tests, reviewers can try their own Compose files with profiles:

func ExampleWithProfiles() error {
    ctx := context.Background()

    filesOpt := compose.WithStackFiles("compose.yaml")
    profilesOpt := compose.WithProfiles("test", "dev")
    stack, err := compose.NewDockerComposeWith(filesOpt, profilesOpt)
    if err != nil {
       return fmt.Errorf("new docker compose: %w", err)
    }
    fmt.Println("stack up")
    if err := stack.Up(ctx); err != nil {
       return fmt.Errorf("stack up: %w", err)
    }
    fmt.Println("stack down")
    if err := stack.Down(ctx); err != nil {
       return fmt.Errorf("stack down: %w", err)
    }
    return nil
}

Follow-ups

From my perspective, this feature is self-contained.

If this gets merged and released, we will adapt our workflow to use testcontainers-go/modules/compose for setting up test environments. This might generate more insights and follow-ups.

@ngrash ngrash requested a review from a team as a code owner August 31, 2024 12:53
Copy link

netlify bot commented Aug 31, 2024

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit debea8e
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/66d5ba135d518200082fcc99
😎 Deploy Preview https://deploy-preview-2758--testcontainers-go.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

This commit allows users of the compose module to selectively enable services
by using Docker Compose profiles.

More about profiles: https://docs.docker.com/compose/profiles
Copy link
Member

@mdelapenya mdelapenya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks for adding this! The changes are easy to review and the test is always welcomed.

@mdelapenya mdelapenya self-assigned this Sep 2, 2024
@mdelapenya mdelapenya added chore Changes that do not impact the existing functionality feature New functionality or new behaviors on the existing one compose Docker Compose. and removed chore Changes that do not impact the existing functionality labels Sep 2, 2024
@mdelapenya mdelapenya merged commit 5cc104a into testcontainers:main Sep 2, 2024
111 checks passed
mdelapenya added a commit that referenced this pull request Sep 3, 2024
* main:
  feat(wait): for file (#2731)
  feat(compose): select services via profiles (#2758)
  chore(deps): bump mkdocs-markdownextradata-plugin from 0.2.5 to 0.2.6 (#2761)
  fix: update template too (#2763)
  chore(deps): bump actions/checkout from 4.1.1 to 4.1.7 (#2762)
  chore(deps): bump mkdocs-include-markdown-plugin from 6.0.4 to 6.2.2 (#2760)
  fix: check if the discovered docker socket responds (#2741)
  Upgrade milvus-io/milvus-sdk-go to avoid checksum mismatch. (#2753)
  Fix trailing slash on Image Prefix (#2747)
  chore: use new testcontainers/ryuk:0.9.0 image (#2750)
  chore(deps): bump minimal Go version from 1.21 to 1.22 (#2743)
mdelapenya added a commit to mdelapenya/testcontainers-go that referenced this pull request Sep 9, 2024
* main:
  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)
mdelapenya added a commit to mdelapenya/testcontainers-go that referenced this pull request Sep 11, 2024
* 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compose Docker Compose. feature New functionality or new behaviors on the existing one
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants