{"id":15790554,"url":"https://github.com/ericklv/gcp-schedule-resource","last_synced_at":"2025-03-31T18:43:19.371Z","repository":{"id":248209221,"uuid":"828078156","full_name":"ericklv/gcp-schedule-resource","owner":"ericklv","description":"Schedule cloud sql resource using API ","archived":false,"fork":false,"pushed_at":"2024-07-16T21:34:56.000Z","size":19,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-10-11T22:16:51.863Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ericklv.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2024-07-13T04:15:34.000Z","updated_at":"2024-07-16T21:34:59.000Z","dependencies_parsed_at":"2024-10-26T04:08:30.568Z","dependency_job_id":"92703f83-5e5a-4c1d-9054-273b3688ed8a","html_url":"https://github.com/ericklv/gcp-schedule-resource","commit_stats":{"total_commits":15,"total_committers":1,"mean_commits":15.0,"dds":0.0,"last_synced_commit":"01f118e71c0a46b6baad85d88872bfda30dd1849"},"previous_names":["ericklv/gcp-schedule-resource"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericklv%2Fgcp-schedule-resource","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericklv%2Fgcp-schedule-resource/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericklv%2Fgcp-schedule-resource/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ericklv%2Fgcp-schedule-resource/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ericklv","download_url":"https://codeload.github.com/ericklv/gcp-schedule-resource/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246521685,"owners_count":20791179,"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":[],"created_at":"2024-10-04T22:21:50.700Z","updated_at":"2025-03-31T18:43:19.344Z","avatar_url":"https://github.com/ericklv.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# API for start/stop/restart/resize Cloud SQL instance\nThis API allows to execute GCloud SDK commands (gcloud) to change the status of a Cloud SQL instance.\n\nUsing goroutines the command is executed in the background, some commands can take up to 5min to complete.\n\n---\n**NOTE**\n\nIf you want to use the API synchronously you can use `api-sync` branch\n\n---\n\n# Requirements\nTo run needs golang \u003e= 1.22 and Gcloud SDK. Your account must have Cloud SQL Admin permissions.\n\nTo run in local use (default port is 5432): \n```bash\ngo mod tidy\ngo run main.go\n```\n\n# API\n- `/health` : check if API is enabled.\n- `/:action/:inst_name`: Has 2 params\n  - action: can be \"start\", \"stop\" , \"restart\"\n  - inst_name: cloud sql instance name.\n- `/:action/:inst_name/:resize`: Has 3 params.\n  - action: set \"resize\"\n  - inst_name: cloud sql instance name. \n  - resize: can be \"up\" or \"down\".\n  - Configure `resize.json` with valid machine-types for your instance. \n  `up` for work hours and `down` for non work hours. Example:\n  ```json\n    {\n    \"machines\": [\n        {\n            \"name\": \"awesome-machine\",\n            \"up\": \"db-n1-standard-32\",\n            \"down\": \"db-n1-standard-2\"\n        }\n    ]}\n  ```\n  To see list valid machines types and specs run:\n  ```bash\n    gcloud alpha sql tiers list\n  ```\n\n# Create a Cloud Run\n1. Configure a google account service in GCP and add Cloud SQL Admin permissions.\n2. Generate a key file as JSON [Ref](https://cloud.google.com/sdk/gcloud/reference/auth/activate-service-account). \n3. Update Dockerfile with this values.  \n   - `key-file` is your JSON  \n   - `project` is project-id of instances.\n   - `activate-service-account` is your google account service.\n4. Generate image with (see logs if your account service has any permissions problem):\n```bash\ndocker build -t {your_name}/{image_name} -f Dockerfile . --progress plain --no-cache\n```\n5. Upload image to Docker Hub or Artifact Registry in GCP\n6. Make a cloud run with docker image o create a cloudbuild to generate image and deploy. \n  - Remmember enable `CPU is always allocated` in cloud run configuration if use `main` branch (for goroutines works correctly). \n7. Use Cloud Scheduler to consume the service.\n \nGood luck, have fun.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericklv%2Fgcp-schedule-resource","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fericklv%2Fgcp-schedule-resource","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fericklv%2Fgcp-schedule-resource/lists"}