GitHub Actions:自动化发布
(部分: 技术和基础设施)
简短摘要
GitHub Actions是存储库中的本地"代码流水线"。对于iGaming,这些是后端,前端,ETL/DBT和ML/LLM服务的快速安全发布:测试矩阵,依赖性缓存,隔离的运行者池,用于统一标准的可重复工作流,OIDC代替长寿命的秘密,签名和SBOM,Tags和GitOps清单保险杠发行。关键是质量/安全模板和网关,以控制p99和成本。
1)建筑原则
Piplines作为代码(".github/workflows /.yml"),通过Reusable/Composite Actions DRY。
亚军池:托管(ubuntu-latest)+自主(K8s/VM,ML的GPU)。
星期三(环境):"dev/stage/prod",其中包含询问的审查员,时间表和周围环境的秘密。
策略:受保护的品牌/标签,CODEOWNERS,强制性检查。
可观察性:工作峰会,工件,拼写,持续时间度量。
2)基本模板CI → CD (backend)
yaml name: ci-cd-backend on:
pull_request:
branches: [ main ]
push:
tags: [ "v" ]
permissions:
contents: read id-token: write # для OIDC packages: write
env:
IMAGE: ghcr. io/${{ github. repository }}/api:${{ github. sha }}
jobs:
lint_test:
runs-on: ubuntu-latest steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5 with: { python-version: '3. 12' }
- name: Cache pip uses: actions/cache@v4 with:
path: ~/.cache/pip key: pip-${{ runner. os }}-${{ hashFiles('requirements. txt') }}
- run: pip install -r requirements. txt
- run: make lint && make test
- name: Build & push image (BuildKit)
uses: docker/build-push-action@v6 with:
push: ${{ github. event_name == 'push' }}
tags: ${{ env. IMAGE }}
cache-from: type=gha cache-to: type=gha,mode=max
security:
needs: [ lint_test ]
runs-on: ubuntu-latest steps:
- uses: actions/checkout@v4
- name: SCA/SAST/Secrets uses: your-org/security-composite@v3 # Composite Action вашей орг.
release_prod:
if: startsWith(github. ref, 'refs/tags/v')
needs: [ security ]
runs-on: ubuntu-latest environment: production steps:
- uses: actions/checkout@v4
- name: SBOM & Sign uses: your-org/sbom-sign-action@v2 with:
image: ${{ env. IMAGE }}
- name: GitOps bump manifests uses: your-org/gitops-bump@v2 with:
image: ${{ env. IMAGE }}
path: apps/api/values. yaml
想法:PR → lint/unit →大→安全性"v"-SBOM/签名和 GitOps-bamp清单。
3)重复使用: Reusable/Composite
Reusable Workflows:所有服务的单一管道模板(在单独的repo'.github'中)。
复合操作:重复步骤的拼写(lint/unit/scans)。
yaml jobs:
ci_template:
uses: your-org/ci-templates/.github/workflows/python. yml@v3 with:
python: '3. 12'
run-tests: true
4)矩阵、缓存和性能
`strategy.用于并行测试(语言/DB/OS)的矩阵。
缓存: 依赖关系的"操作/缓存";BuildKit с `cache-to: gha`;dependency proxies.
竞争力:'concurrency: group: api-${github.ref}},cancel-in-progress: true'-节省分钟。
文物:使用"retention-days"存储报告/覆盖/配置文件。
yaml strategy:
matrix:
py: [ '3. 10', '3. 12' ]
db: [ 'mysql', 'postgres' ]
5) Environments и approvals
为"制作"(手动门)配置请求的查看器。
环境的Per Secret:Deploy令牌,签名密钥,看台URL。
预览环境(auto-expire)的寿命以控制成本。
6)OIDC云访问(无长期秘密)
启用"id-token: write",在云中配置信任策略,并使用临时密钥。
适用于AWS/Azure/GCP/工件注册表/密码管理器。
Least privilege原则:"dev/stage/prod"上的单独角色。
yaml
- name: Assume cloud role via OIDC uses: your-org/oidc-assume@v1 with:
role: arn:aws:iam::123:role/gha-deploy-prod
7)发行版,标签和工件
通过tag发布:changelog,发布摘要,发布映像/软件包。
Immutability:"仅向前"标记,容器/图表签名。
SBOM (CycloneDX/SPDX)+签名(cosign/sigstore)-"无签名-无降级"门。
8) GitOps и progressive delivery
CD不是"来自Actions",而是通过PR/commit到manifest-repo(Argo CD/Flux)。
金丝雀/蓝绿色:GitOps-bump重量/版本步骤;根据SLO标准自动推广。
yaml
- uses: mikefarah/yq@v4 with:
cmd: yq -i '.image = strenv(IMAGE)' apps/api/values. yaml
- run:
git config user. name "gha-bot"
git commit -am "bump api -> $IMAGE" && git push
9) pipline和供应链安全
谁可以运行:仅来自受保护的分支机构/标签,并带有required检查。
扫描:SAST/SCA/秘密扫描,预览环境中的DAST。
标题:图像,Helm图表,二进制;在沉积时进行验证。
政策:仅来自值得信赖的锻炼者;第三方Actions的pin SHA。
10)可观察性,SLO和ChatOps
摘要报告(JUnit/coverage/scans),公关状态。
度量标准:阶段持续时间,成功/失败,"先发制人队列"。
ChatOps:公关中的机器人评论(指向行车记录仪、预览URL)、命令'/promote'、'/rollback'通过'workflow_dispatch'。
11) FinOps(分钟和资源成本)
Conccurency-cancel for PR,矩阵仅在更改的部分(paths-filter)上。
文物卫生:"retention-days",自动预览env。
重型装配/ML的自助托管池,夜间的"安静时钟"。
Dependency cache和BuildKit GHA缓存可节省大量资金。
12)单声道和父母/儿童编排
按文件夹/路径触发:每个组件的独立工作流。
可作为团队之间的标准化层(Payments/Risk/CRM/ETL/ML)。
按组件划分秘密/环境。
13) iGaming模板
A) Backend/API (Go/Node/Python)
yaml name: backend on: [ pull_request, push ]
jobs:
ci:
uses: your-org/ci-templates/.github/workflows/backend. yml@v3 release:
if: startsWith(github. ref, 'refs/tags/v')
uses: your-org/ci-templates/.github/workflows/release. yml@v3 secrets: inherit
Б) ETL/DBT
yaml name: etl-dbt on: [ pull_request ]
jobs:
dbt:
runs-on: ubuntu-latest steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5 with: { python-version: '3. 11' }
- run: pip install dbt-core dbt-bigquery
- run: dbt deps && dbt run && dbt test
- name: Publish docs run: dbt docs generate && tar czf docs. tgz target/
load artifact, retention period 3 days uses: actions/upload-artifact @ v4 with: {name: dbt-docs, path: docs. tgz, retention-days: 3 }
B) ML/LLM(地狱工件)
yaml name: ml-pack on:
push:
tags: [ "model-" ]
jobs:
build-engine:
runs-on: self-hosted-gpu steps:
- uses: actions/checkout@v4
- run: python export_onnx. py
- run: trtexec --onnx=model. onnx --saveEngine=model. plan
- uses: actions/upload-artifact@v4 with: { name: engine, path: model. plan, retention-days: 7 }
- name: Sign & SBOM uses: your-org/sbom-sign-action@v2 with: { file: model. plan }
14)实施支票
1.定义CI/CD模板(Reusable/Composite)并将其应用于所有回购。
2.启用Environments with approvals和单独的秘密。
3.转到OIDC到Cloud/Secret Manager,卸下持久密钥。
4.输入SAST/SCA/Secrets/DAST,SBOM和工件签名;关键漏洞门。
5.配置GitOps: manifor-repo、自动映像/版本保险杠、金丝雀/蓝绿色。
6.优化缓存/矩阵,"concurrency"。cancel-in-progress',文物清理。
7.展开具有极限和绝缘性的自托管跑步者池(包括GPU)。
8.启用paths-filter和rule设置,以免赛车额外的joba。
9.添加ChatOps:状态/命令;公关报告。
10.确定Actions安全使用策略(pin SHA,限制外部)。
15)反模式
在所有回购中,相同的步骤而不是Reusable/Composite →标准分步器。
变量中的长寿命云秘密代替OIDC。
缺少Environments/provals for prod。
第三方Actions的未压缩版本→供应链的风险。
没有SBOM/签名 → CD上没有验证。
总是发射的大容量矩阵→成本上升。
从Actions直接到prod的CD,而没有GitOps更改跟踪。
结果
GitHub Actions允许构建一个单一、安全和可播放的发布管道:通过Reusable/Composite标准化管道,使用OIDC和随行人员,实施SBOM/签名,通过渐进式交付将CD转换为GitOps,并通过缓存/矩阵/复制控制成本竞争力。这种方法可以扩展到iGaming产品的速度,保持质量并降低运营风险。