{"id":15161773,"url":"https://github.com/bkosm/gompose","last_synced_at":"2026-02-11T20:35:33.387Z","repository":{"id":65471073,"uuid":"592748529","full_name":"bkosm/gompose","owner":"bkosm","description":"Use docker-compose programatically in Go tests. No third-party dependencies.","archived":false,"fork":false,"pushed_at":"2024-03-11T15:13:43.000Z","size":106,"stargazers_count":3,"open_issues_count":7,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-10-24T22:32:37.695Z","etag":null,"topics":["docker","docker-compose","go","golang","testing"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bkosm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-01-24T13:00:45.000Z","updated_at":"2023-10-20T19:01:37.000Z","dependencies_parsed_at":"2024-06-21T01:07:29.960Z","dependency_job_id":"11e63fa3-c8f0-480c-8dd0-5e9977da5d2b","html_url":"https://github.com/bkosm/gompose","commit_stats":{"total_commits":64,"total_committers":5,"mean_commits":12.8,"dds":0.5625,"last_synced_commit":"bdcc394d2c2362ce8b9fb8a3a19006ddd2478422"},"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"purl":"pkg:github/bkosm/gompose","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bkosm%2Fgompose","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bkosm%2Fgompose/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bkosm%2Fgompose/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bkosm%2Fgompose/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bkosm","download_url":"https://codeload.github.com/bkosm/gompose/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bkosm%2Fgompose/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29344099,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-11T20:11:40.865Z","status":"ssl_error","status_checked_at":"2026-02-11T20:10:41.637Z","response_time":97,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["docker","docker-compose","go","golang","testing"],"created_at":"2024-09-27T00:44:55.757Z","updated_at":"2026-02-11T20:35:33.360Z","avatar_url":"https://github.com/bkosm.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gompose\n[![Coverage Status](https://coveralls.io/repos/github/bkosm/gompose/badge.svg)](https://coveralls.io/github/bkosm/gompose)\n[![GoDoc](https://godoc.org/github.com/bkosm/gompose/v2?status.svg)](https://godoc.org/github.com/bkosm/gompose/v2)\n[![CI](https://github.com/bkosm/gompose/actions/workflows/ci.yml/badge.svg)](https://github.com/bkosm/gompose/actions/workflows/ci.yml)\n[![CodeQL](https://github.com/bkosm/gompose/actions/workflows/codeql.yml/badge.svg)](https://github.com/bkosm/gompose/actions/workflows/codeql.yml)\n[![Go Report](https://goreportcard.com/badge/github.com/bkosm/gompose/v2)](https://goreportcard.com/report/github.com/bkosm/gompose/v2)\n\nStraightforward library to use `docker-compose` programmatically in Go tests.\n\nUnlike other (deprecated) libraries, this one relies on `os/exec` instead of\nheavy docker libraries and others.\n\nIt's just enough so that you can set up and clean your environment for some automated tests.\n\nThe only hard requirement is `docker-compose` executable on system path.\n\n## example\n\n```go\npackage main\n\nimport (\n\t\"log\"\n\t\"os\"\n\t\"testing\"\n\n\tg \"github.com/bkosm/gompose/v2\"\n)\n\nfunc TestMain(m *testing.M) {\n\t// Let's say we have a postgres container in the spec\n\terr := g.Up(\n\t\tg.Wait(\n\t\t\tg.ReadyOnLog(\"database system is ready to accept connections\", g.Times(2)),\n\t\t),\n\t\tg.SignalCallback(func(_ os.Signal) { // any action to be taken on SIGINT, SIGTERM\n\t\t\t_ = g.Down()\n\t\t}),\n\t)\n\tif err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tcode := m.Run()\n\n\tif err = g.Down(); err != nil {\n\t\tlog.Fatal(err)\n\t}\n\n\tos.Exit(code)\n}\n```\n\nWhen you run `go test ./...` you will see that the container is starting and running before any tests.\nAfter the tests conclude, `compose down` is performed.\n\nIn case of a system interrupt (`SIGINT`, `SIGTERM`), the library allows for custom callbacks to ensure that no dangling\ncontainers are left after the user requested a stop.\n\n#### but I have things to do in the meantime\n\nWaiting is done the idiomatic way - you can await the ready channel without passing it to `Up` whenever:\n\n```go\n//...\nerr := g.Up(g.SignalCallback(func(_ os.Signal) { _ = g.Down() }))\nif err != nil {\n\tlog.Fatal(err)\n}\n\n// do stuff\n\nreadyOrErr := g.ReadyOnLog(\"database system is ready to accept connections\", g.Times(2))\nif err := \u003c-readyOrErr; err != nil {\n\tlog.Fatal(err)\n}\n\ncode := m.Run()\n//...\n```\n\n#### but I want to wait until service passes health-checks\n\nThis can be done by using the `ReadyOnHttp` wait channel:\n\n```go\nhc, _ := http.NewRequest(http.MethodGet, \"http://localhost:5432\", nil)\n\nerr := g.Up(g.Wait(g.ReadyOnHttp(*hc)))\n```\n\nAnd you can customize what it means to be healthy too:\n\n```go\nerr := g.Up(g.Wait(\n    g.ReadyOnHttp(\n        *hc,\n        g.ResponseVerifier(func (r *http.Response) (bool, error) {\n            return r.StatusCode == http.StatusUnauthorized, nil\n        })\n    ),\n))\n```\n\n#### miscellaneous\n\n##### skip down non-programmatically\n\nWhen an environment variable of `GOMPOSE_SKIP` is set with a value including `down`\n(as a comma delimited string), the invocation of `docker-compose down` is skipped, leaving out the\nenvironment in the state it was during the tests. This can be helpful while debugging and\nduring development, in cases where the services needed require significant effort to start.\n\n##### all the commands with all their options - as examples\n\n```go\npackage main\n\nimport (\n\t\"bytes\"\n\t\"fmt\"\n\t\"net/http\"\n\t\"os\"\n\t\"os/exec\"\n\t\"time\"\n\n\tg \"github.com/bkosm/gompose/v2\"\n)\n\nfunc main() {\n\t// ready on stdout\n\tcmd := exec.Command(\"echo\", \"1\")\n\twait := g.Wait(\n\t\tg.ReadyOnStdout(\n\t\t\tcmd,\n\t\t\t\"1\",\n\t\t\tg.Times(1),\n\t\t\tg.Timeout(time.Minute),\n\t\t\tg.PollInterval(time.Second),\n\t\t),\n\t)\n\n\t// ready on log\n\twait = g.Wait(\n\t\tg.ReadyOnLog(\n\t\t\t\"log line\",\n\t\t\tg.CustomFile(\"other/compose.yaml\"),\n\t\t\tg.Times(3),\n\t\t\tg.Timeout(2*time.Minute),\n\t\t\tg.PollInterval(3*time.Second),\n\t\t),\n\t)\n\n\t// ready on http\n\tpayload := `{\n            \"is_fine\": true\n        }`\n\treq, _ := http.NewRequest(\n\t\thttp.MethodPut,\n\t\t\"http://myservice/api\",\n\t\tbytes.NewReader([]byte(payload)),\n\t)\n\twait = g.Wait(\n\t\tg.ReadyOnHttp(\n\t\t\t*req,\n\t\t\tg.Times(1),\n\t\t\tg.Timeout(time.Minute),\n\t\t\tg.PollInterval(time.Second),\n\t\t\tg.ResponseVerifier(func(_ *http.Response) (bool, error) {\n\t\t\t\treturn true, nil\n\t\t\t}),\n\t\t),\n\t)\n\n\t// Up\n\t_ = g.Up(\n\t\tg.CustomFile(\"other/compose.yaml\"),\n\t\tg.CustomServices(\"s1\", \"s2\"),\n\t\tg.SignalCallback(func(s os.Signal) {\n\t\t\tfmt.Println(\"interrupt!\")\n\t\t}),\n\t\tg.RetryCommand(3, time.Second*10),\n\t\twait,\n\t)\n\n\t// Down\n\t_ = g.Down(\n\t\tg.CustomFile(\"other/compose.yaml\"),\n\t)\n}\n```\n\n## contributing\n\nThis is the absolute bare-bone of a library and contributions are welcome.\n\nList of things to do in priority:\n\n1. Covering a larger portion of CLI's capabilities\n1. More wait conditions\n\nWhen contributing, be mindful that the purpose of this library is to be\nself-contained, lean and easy to use.\n\n## licensing\n\nThis software is open-source. See [license](LICENSE).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbkosm%2Fgompose","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbkosm%2Fgompose","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbkosm%2Fgompose/lists"}