{"id":31727211,"url":"https://github.com/dingsheng-dev/gitlab-aliyun-runner","last_synced_at":"2026-04-17T09:32:16.735Z","repository":{"id":316039083,"uuid":"1041321710","full_name":"DingSheng-DEV/gitlab-aliyun-runner","owner":"DingSheng-DEV","description":"Gitlab阿里云弹性伸缩CI/CD脚本","archived":false,"fork":false,"pushed_at":"2025-09-22T09:12:03.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-22T11:24:57.331Z","etag":null,"topics":["aliyun","autoscale","cicd","gitlab"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DingSheng-DEV.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,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-08-20T10:10:53.000Z","updated_at":"2025-09-22T09:12:07.000Z","dependencies_parsed_at":null,"dependency_job_id":"91f6a2c4-b3c6-4521-9c38-afecef858fbe","html_url":"https://github.com/DingSheng-DEV/gitlab-aliyun-runner","commit_stats":null,"previous_names":["dingsheng-dev/gitlab-aliyun-runner"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/DingSheng-DEV/gitlab-aliyun-runner","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DingSheng-DEV%2Fgitlab-aliyun-runner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DingSheng-DEV%2Fgitlab-aliyun-runner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DingSheng-DEV%2Fgitlab-aliyun-runner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DingSheng-DEV%2Fgitlab-aliyun-runner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DingSheng-DEV","download_url":"https://codeload.github.com/DingSheng-DEV/gitlab-aliyun-runner/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DingSheng-DEV%2Fgitlab-aliyun-runner/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279000850,"owners_count":26082950,"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","status":"online","status_checked_at":"2025-10-09T02:00:07.460Z","response_time":59,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"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":["aliyun","autoscale","cicd","gitlab"],"created_at":"2025-10-09T06:19:14.603Z","updated_at":"2025-10-09T06:19:16.346Z","avatar_url":"https://github.com/DingSheng-DEV.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GitLab 阿里云弹性伸缩CI/CD脚本\n\n🚀 利用阿里云抢占式实例（Spot Instance）实现低成本、高性能的 GitLab CI/CD 构建流水线。\n\n## 项目背景\n  GitLab 原生的自动伸缩功能目前仅支持 Amazon AWS、Google Cloud Platform 和 Microsoft Azure 云平台，尚未官方支持阿里云（Alibaba Cloud）。这在一定程度上限制了国内用户或阿里云生态用户高效集成 GitLab CI/CD 的能力。\n本脚本项目旨在填补这一空白，为 GitLab 与阿里云的深度集成提供自动化支持。通过本方案，用户可便捷地在阿里云上实现项目存储管理及持续构建与部署，从而提升开发运维效率，降低云资源成本，打造更贴合本土云环境体验。\n\u003cimg width=\"1462\" height=\"950\" alt=\"image\" src=\"https://github.com/user-attachments/assets/e49daa88-cb78-445e-b7bf-1423fe9ba216\" /\u003e\n\n---\n## 项目简介\n\n本项目通过 GitLab CI/CD 流水线动态调用阿里云 API 创建**抢占式实例（Spot Instance）**，在创建的实例中执行代码构建与部署任务。构建完成后自动释放实例，实现资源按需使用、成本极低的持续集成/持续部署方案。\n\n\u003e 适用于构建任务重、对服务器性能要求高，但希望控制基础设施成本的团队。\n\n核心特点：**轻量 GitLab 服务 + 临时构建高性能实例 + 自定义 Runner 调度**\n\n---\n\n## 工作流程\n\n\u003cimg width=\"238\" height=\"514\" alt=\"image\" src=\"https://github.com/user-attachments/assets/d4cd7a89-b1dd-44e7-8c7a-e4822092df77\" /\u003e\n\n\n\u003e GitLab 本体服务器仅需承担调度职责，性能要求极低，所有繁重的构建任务由临时高性能实例完成。\n\n---\n\n## 核心优势\n\n✅ **成本极低**：抢占式实例价格可低至按量付费实例的 10%~30%  \n✅ **性能强劲**：可选择高配实例（如 8C16G、GPU 实例）快速完成构建  \n✅ **弹性伸缩**：每次构建独立运行，避免资源争用  \n✅ **自动化管理**：创建 → 构建 → 部署 → 销毁 全流程自动化  \n✅ **轻量 GitLab 服务**：无需高配服务器运行 GitLab 和 Runner\n\n---\n\n\n## 环境构建方法\n### 准备工作：\n1. 服务器：用于搭建Gitlab和Gitlab-runner基础环境\n2. 阿里云镜像：用来构建实例的镜像（docker，java23，gradle、kubectl）\n3. 密钥对：用于登录临时创建的实例\n### 具体实操：\n1. 搭建GitLab和Gitlab-runner完毕后，注册自定义执行器的runner：https://docs.gitlab.com/runner/register/\n  搭建gitlab-runner时，需要挂载目录到启动的容器中，以便后续脚本的放置：  \n\u003cimg width=\"381\" height=\"59\" alt=\"image\" src=\"https://github.com/user-attachments/assets/d4bcd45e-7bfc-4e26-9f73-aa52ed921a51\" /\u003e\n\n2. 配置注册的runner\n\n   配置后的runner配置详情如下：\u003cimg width=\"1025\" height=\"808\" alt=\"image\" src=\"https://github.com/user-attachments/assets/69da7b06-2c19-4f58-a5af-18d4167d7627\" /\u003e\n   **按照上图所示将项目中相关文件放到指定文件夹下。**\n3. 项目中脚本主要功能\n```\n   prepare.sh： 创建ecs实例\n   \n   run.sh：具体业务逻辑\n   \n   cleanup.sh：删除创建的ecs实例\n```   \n4. .gitlab-ci.yml配置样例\n   \n   \u003cimg width=\"710\" height=\"763\" alt=\"image\" src=\"https://github.com/user-attachments/assets/cae4c06f-1619-437b-a072-1effd3ce1c09\" /\u003e\n\n5. 按照上述配置完毕之后，触发流水线构建即可。\n\n---\n## 实际运行效果\n\n原单台虚拟机成本\n\u003cimg width=\"1578\" height=\"656\" alt=\"image\" src=\"https://github.com/user-attachments/assets/c4757a76-2992-45d1-9596-729e605b61b4\" /\u003e\n\n一次CI所需成本在0.02块，即两分左右。（以一个月构建1000次为例：1000*0.025=25块钱，一年25*12=300块）。对比之前准备一台 4核8G 包年计费实例，成本下降到了**1/10**\n\u003cimg width=\"1831\" height=\"256\" alt=\"image\" src=\"https://github.com/user-attachments/assets/7e96b927-6a4a-4afa-89c6-2fb5a01bca5d\" /\u003e\n\n---\n\n💡 **用更少的成本，跑更快的构建！**\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdingsheng-dev%2Fgitlab-aliyun-runner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdingsheng-dev%2Fgitlab-aliyun-runner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdingsheng-dev%2Fgitlab-aliyun-runner/lists"}