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

chore(ci): define a pipeline with multiple gates #1414

Merged
merged 18 commits into from
Aug 4, 2023

Conversation

mdelapenya
Copy link
Collaborator

@mdelapenya mdelapenya commented Aug 2, 2023

What does this PR do?

This PR refactors all the CI infrastructure, having one big workflow file instead of multiple ones. After these changes, the ci.yml file is the single source of truth in terms of CI pipelines, defining multiple what I call "quality gates", which is nothing than different gates in the pipeline that will have more importance depending on when they are run in the pipeline: those to the left in the diagram will run earlier because they have more priority.

In this big workflow we will define dependency relationships, leveraging the needs keyword from GH actions, therefore one "stage" o GH job, won't be triggered until its needed job has finished with success. The proposed pipeline defines:

flowchart TD
    Zero( Start )
    Zero --> Core
    Zero --> ModuleGen
    Core[Core Library] -->|ubuntu - macos\nGo 1.19.x, 1.20.x| B[Go Modules]
    Core[Core Library] -->|ubuntu\nGo 1.19.x, 1.20.x| Ryuk[Ryuk Disabled]
    Core[Core Library] -->|ubuntu\nGo 1.19.x, 1.20.x| Rootless[Docker Rootless]
    B[Core Library] --> |ubuntu - macos\nGo 1.19.x, 1.20.x| Examples[Example Modules]
    ModuleGen[Module Generator]
    ModuleGen --> |ubuntu - macos\nGo 1.19.x, 1.20.x| End( End )
    Ryuk --> |ubuntu\nGo 1.19.x, 1.20.x| End( End )
    Rootless --> |ubuntu\nGo 1.19.x, 1.20.x| End( End )
    Examples --> |ubuntu - macos\nGo 1.19.x, 1.20.x| End( End )

At the same time, we have created a reusable workflow to run the Go tests (see ci-test-go.yml file) to run the Go tests. It will receive certain input parameters to configure the execution:

Input param Required Type Default Description
go-version true string The version of Go to use for the test.
platform true string The platform to run the test on.
project-directory true string "." The directory where the Go project is located.
rootless-docker false boolean false Run the test with rootless docker, adding steps to configure rootless Docker.
ryuk-disabled false boolean false Disable the ryuk container for the test. Will set the TESTCONTAINERS_RYUK_DISABLED environment variable

An example usage of this reusable module:

  test-module-generator:
    strategy:
      matrix:
        go-version: [1.19.x, 1.x]
        platform: [ubuntu-latest, macos-latest]
    uses: ./.github/workflows/ci-test-go.yml
    with:
      go-version: ${{ matrix.go-version }}
      platform: ${{ matrix.platform }}
      project-directory: "modulegen"
      rootless-docker: false
      ryuk-disabled: false

As a result, we will be able to run the tests for the core library, the different Docker configs (e.g. rootless), tests for each Go module, with a single reusable workflow, which will define a proper visual name, based on the input parameters used to call it.

Finally, and because creating a new module using the module generator tool created a workflow for each module, we modified the code generator to generate the new pipeline file, adding a list of modules/examples to the matrix of modules/examples.

Why is it important?

We have experimented many situations where our CI jobs take a lot of time to be processed, mainly after an updates wave from @dependabot. This happens basically because the jobs get queued because the number of allocated CI workers is passing the limit of workers in the entire @testcontainers organisation!! AND THIS IS AN ISSUE AS WE WERE IMPACTING OTHER TC-LANG PROJECTS.

With this new approach, we will reduce the number of workers needed by each "gate", reducing the workers that are needed at the same time. From an initial ramp up of +90 workers, we will have:

  • a first gate with 8 workers
  • a second gate with 40-50
  • a third gate with 40-50

allowing more granularity when new PRs (in any repo of the org) come to grab a free worker.

How to test this PR

The result in the GH actions UI will be: https://github.com/testcontainers/testcontainers-go/actions/runs/5750784979?pr=1414

Screenshot 2023-08-03 at 18 25 46

@mdelapenya mdelapenya requested a review from a team as a code owner August 2, 2023 11:57
@mdelapenya mdelapenya self-assigned this Aug 2, 2023
@netlify
Copy link

netlify bot commented Aug 2, 2023

Deploy Preview for testcontainers-go ready!

Name Link
🔨 Latest commit 6767ce2
🔍 Latest deploy log https://app.netlify.com/sites/testcontainers-go/deploys/64cc303875180d00087fa0b7
😎 Deploy Preview https://deploy-preview-1414--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.

@mdelapenya mdelapenya added the chore Changes that do not impact the existing functionality label Aug 2, 2023
@mdelapenya mdelapenya marked this pull request as draft August 2, 2023 13:50
@mdelapenya mdelapenya marked this pull request as ready for review August 3, 2023 16:39
matrix:
go-version: [1.19.x, 1.x]
platform: [ubuntu-latest, macos-latest]
module: [compose, couchbase, k3s, localstack, mysql, neo4j, postgres, pulsar, redis, redpanda, vault]
Copy link
Member

Choose a reason for hiding this comment

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

I was wondering if we can auto discover the folders under modules to build the matrix automatically

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This file is autogenerated by the modules generator

.github/workflows/ci.yml Show resolved Hide resolved
@mdelapenya
Copy link
Collaborator Author

I need to adjust the repository settings for the gh check

* main:
  chore(deps): bump github.com/hashicorp/consul/api in /examples/consul (testcontainers#1381)
  chore(deps): bump github.com/twmb/franz-go in /modules/redpanda (testcontainers#1387)
  chore(deps): bump github.com/nats-io/nats.go in /examples/nats (testcontainers#1389)
  feat(redpanda): Add option to enable topic auto-creation (testcontainers#1360)
  chore(deps): bump golang.org/x/text from 0.9.0 to 0.11.0 in /modulegen (testcontainers#1388)
  chore(deps): bump google.golang.org/api from 0.125.0 to 0.134.0 in /examples (testcontainers#1412)
  chore(deps): bump golang.org/x/mod and github.com/aws/aws-sdk-go-v2/config in /modules/localstack (testcontainers#1410)
  test: fix TestGetDockerConfig (testcontainers#1413)
@sonarcloud
Copy link

sonarcloud bot commented Aug 3, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 1 Code Smell

No Coverage information No Coverage information
0.0% 0.0% Duplication

@mdelapenya mdelapenya merged commit dd61438 into testcontainers:main Aug 4, 2023
106 checks passed
@mdelapenya mdelapenya deleted the refactor-gh-workflows branch August 4, 2023 12:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
chore Changes that do not impact the existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants