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

fix: add missing service container health check #2354

Merged
merged 4 commits into from
Jul 10, 2024

Conversation

ChristopherHX
Copy link
Contributor

@ChristopherHX ChristopherHX commented Jun 6, 2024

Some service container like mysql are slow to start, configuring the optional health check per GitHub Actions Docs can enshure they are ready

GitHub Docs Example based on postgres

@ChristopherHX ChristopherHX requested a review from a team as a code owner June 6, 2024 14:56
@ChristopherHX ChristopherHX changed the title Fix missing service container health check fix: add missing service container health check Jun 6, 2024
Copy link
Contributor

mergify bot commented Jun 6, 2024

@ChristopherHX this pull request has failed checks 🛠

@mergify mergify bot added the needs-work Extra attention is needed label Jun 6, 2024
Copy link
Contributor

github-actions bot commented Jun 6, 2024

🦙 MegaLinter status: ✅ SUCCESS

Descriptor Linter Files Fixed Errors Elapsed time
✅ EDITORCONFIG editorconfig-checker 5 0 0.03s
✅ REPOSITORY gitleaks yes no 2.33s
✅ REPOSITORY git_diff yes no 0.01s
✅ REPOSITORY grype yes no 8.01s
✅ REPOSITORY secretlint yes no 1.04s
✅ REPOSITORY trivy-sbom yes no 0.48s
✅ REPOSITORY trufflehog yes no 4.9s

See detailed report in MegaLinter reports
Set VALIDATE_ALL_CODEBASE: true in mega-linter.yml to validate all sources, not only the diff

MegaLinter is graciously provided by OX Security

MYSQL_RANDOM_ROOT_PASSWORD: yes
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- run: mysql -u dbuser -D dbname -pdbpass -h maindb -e "create table T(id INT NOT NULL AUTO_INCREMENT, val VARCHAR(255), PRIMARY KEY (id))"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

currently this workflow fails to run, because maindb is still starting.

The actions runner wait for it to be ready

@@ -169,6 +169,30 @@ func (cr *containerReference) Remove() common.Executor {
).IfNot(common.Dryrun)
}

func (cr *containerReference) GetHealth(ctx context.Context) ContainerHealth {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Uses docker inspect to poll container health like actions/runner

@@ -452,6 +452,10 @@ func (e *HostEnvironment) GetRunnerContext(_ context.Context) map[string]interfa
}
}

func (e *HostEnvironment) GetHealth(ctx context.Context) ContainerHealth {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Service container are not implemented for HostEnvironment, just a stub that is probably never called

Comment on lines +536 to +538
if delay > 10*time.Second {
delay = 10 * time.Second
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Never poll less than every 10s, not looked up anywhere.
"Fake exponential backoff"

Copy link

codecov bot commented Jun 6, 2024

Codecov Report

Attention: Patch coverage is 79.54545% with 9 lines in your changes missing coverage. Please review.

Project coverage is 76.34%. Comparing base (5a80a04) to head (52c3d0c).
Report is 87 commits behind head on master.

Files Patch % Lines
pkg/container/docker_run.go 66.66% 5 Missing and 1 partial ⚠️
pkg/container/host_environment.go 0.00% 2 Missing ⚠️
pkg/runner/run_context.go 95.83% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           master    #2354       +/-   ##
===========================================
+ Coverage   61.56%   76.34%   +14.78%     
===========================================
  Files          53       61        +8     
  Lines        9002     7859     -1143     
===========================================
+ Hits         5542     6000      +458     
+ Misses       3020     1303     -1717     
- Partials      440      556      +116     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@mergify mergify bot removed the needs-work Extra attention is needed label Jun 6, 2024
@mergify mergify bot merged commit 2ad5ff7 into master Jul 10, 2024
11 checks passed
@mergify mergify bot deleted the fix-missing-service-container-health-check branch July 10, 2024 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants