{"id":15055500,"url":"https://github.com/courtsite/gitlab-environments-gc","last_synced_at":"2026-01-02T10:03:16.952Z","repository":{"id":118551256,"uuid":"327768314","full_name":"Courtsite/gitlab-environments-gc","owner":"Courtsite","description":"[Unmaintained] 🗑️ A simple Google Cloud Function in Go to clean up stale Environments in GitLab - it can be triggered regularly using Cloud Scheduler.","archived":false,"fork":false,"pushed_at":"2021-01-18T22:10:15.000Z","size":61,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-04-17T17:19:51.453Z","etag":null,"topics":["gitlab","gitlab-ci","google-cloud","google-cloud-functions","google-cloud-scheduler"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Courtsite.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":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-01-08T01:36:41.000Z","updated_at":"2024-06-19T10:27:32.480Z","dependencies_parsed_at":null,"dependency_job_id":"ea448ec8-9d55-4c54-b7ed-d2a755c7a959","html_url":"https://github.com/Courtsite/gitlab-environments-gc","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Courtsite%2Fgitlab-environments-gc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Courtsite%2Fgitlab-environments-gc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Courtsite%2Fgitlab-environments-gc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Courtsite%2Fgitlab-environments-gc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Courtsite","download_url":"https://codeload.github.com/Courtsite/gitlab-environments-gc/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243523209,"owners_count":20304557,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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":["gitlab","gitlab-ci","google-cloud","google-cloud-functions","google-cloud-scheduler"],"created_at":"2024-09-24T21:43:25.249Z","updated_at":"2026-01-02T10:03:16.896Z","avatar_url":"https://github.com/Courtsite.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gitlab-environments-gc\n\n🗑️ A simple Google Cloud Function in Go to clean up stale [Environments in GitLab](https://docs.gitlab.com/ee/ci/environments/) - it can be triggered regularly using [Cloud Scheduler](https://cloud.google.com/scheduler).\n\n![Clean Up Logs in Cloud Function](screenshot.jpg \"Clean Up Logs in Cloud Function\")\n\n\n---\n\n\n**What environments are considered \"stale\"?**\n\n- Its name does not contain protected words like `main`, `master`, `production`, and `protect` (we are only targetting preview / review environments)\n- The last deployment was updated over 2 weeks ago\n\nBoth constraints are currently hardcoded, but we are open to making them configurable - pull requests welcomed.\n\n**How does this work?**\n\nThis function does not clean up the actual environment (e.g. Kubernetes resources), you must define `on_stop` to achieve this (https://docs.gitlab.com/ee/ci/yaml/README.html#environmenton_stop).\n\nBehind the scenes, the function will STOP the environment, and DELETE it.\n\nTo avoid hitting rate limits, and also timing out, this function currently only handles up to 200 environments at a time. If you have lots of environments, consider running this function more regularly.\n\n**Why is this needed?**\n\nAt the time of writing, you can use `auto_stop_in` to automatically \"stop\" environments.\nBut, there is currently no automated / quick way to clean up stopped environments or environments started without `auto_stop_in`.\nThis project is essentially a stop-gap to help you achieve that.\n\n\n## Getting Started\n\n### Prerequisites\n\n- Ensure you have `gcloud` installed:\n    - MacOS: `brew cask install google-cloud-sdk`\n    - Others: https://cloud.google.com/sdk/gcloud\n- Ensure you have authenticated with Google Cloud: `gcloud init`\n- (Optional) Set your current working project: `gcloud config set project \u003cproject\u003e`\n\n### Deployment\n\n1. Clone / download a copy of this repository\n2. Copy `.env.sample.yaml` to `.env.yaml`, and modify the environment variables declared in the file\n3. Run `./deploy.sh` _(recommendation: do not allow unauthenticated requests, see section on Cloud Scheduler below for more information)_\n\n### Setting Up Cloud Scheduler\n\nOptionally, if you would like to run the clean up regularly (cron), modify, and run `./create_scheduler.sh` to create the necessary resources.\nUnlike `./deploy.sh` which you can run multiple times, you should only run `./create_scheduler.sh` once.\nThis script will also set-up a service account which will be used to securely invoke the Cloud Function, without exposing it to the internet (specifically, preventing unauthenticated requests).\n\nAlternatively, you can also set-up Cloud Scheduler manually via the [web UI](https://console.cloud.google.com/cloudscheduler) or through _infrastructure-as-code_, e.g. [Terraform](https://registry.terraform.io/providers/hashicorp/google/latest/docs).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcourtsite%2Fgitlab-environments-gc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcourtsite%2Fgitlab-environments-gc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcourtsite%2Fgitlab-environments-gc/lists"}