线上pipeline,(我使用是本地仓库的,你们使用切换成官网的即可)
name: Build and Push Docker Image deployment-k8s
on:push:branches:- main
jobs:build-and-push-image:runs-on: ubuntu-lateststeps:- name: Checkout Codeuses: http://192.168.0.20:3000/admins/checkout@main- name: Set up Docker Buildxid: buildxuses: http://192.168.0.20:3000/admins/setup-buildx-action@v2.6.0- name: Login to DockerHubuses: http://192.168.0.20:3000/admins/login-action@v3with:registry: ${{ secrets.REGISTRY }}username: ${{ secrets.DOCKER_USERNAME }}password: ${{ secrets.DOCKER_PASSWORD }}- name: Build Docker Image id: docker_builduses: http://192.168.0.20:3000/admins/build-push-action@v4with:push: truefile: ./Dockerfile-uattags: ${{ secrets.REGISTRY_PATH }}/www:${{ github.sha }}- name: deploy to clusteruses: http://192.168.0.20:3000/admins/kubectl@mainenv:KUBE_CONFIG: ${{ secrets.KUBE_CONFIG_DATA_160 }}with:args: set image deployment/www-web www-web=${{ secrets.REGISTRY_PATH }}/www:${{ github.sha }} -n test- name: verify deploymentuses: http://192.168.0.20:3000/admins/kubectl@mainenv:KUBE_CONFIG: ${{ secrets.KUBE_CONFIG_DATA_160 }}with:args: rollout status deployment/www-web -n test
流水线变量 — 设置>>>> Runner >>> 密钥(输入你的变量)
注意原生使用k8s,然后在加入变量中
cat $HOME/.kube/config | base64
如果你是AWS EKS如下简单配置使用专门EKS镜像:
- name: Deploy Applicationuses: statsig-io/kubectl-via-eksctl@mainenv:aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}region: ap-northeast-1cluster: ${{ secrets.CLUSTER_NAME }}with:args: get pods -n prometheus#args: set image deployment/my-app container=${{ github.repository}}:${{ github.sha }}
Gitea Action工具链更丰富以下是他的市场和工具链,大家可以自己选择自己喜欢的工具
#镜像包
https://github.com/actions/runner-images?tab=readme-ov-file#available-images#入门文档
https://docs.github.com/zh/actions/writing-workflows/quickstart#市场
https://github.com/marketplace?type=actions
最后还可以加入一个webhook,目前只找到一个飞书的
- name: Send Text Messageuses: http://192.168.0.20:3000/admins/feishu-action@v2with:url: ${{ secrets.FEISHU_BOT_WEBHOOK_URL }}msg_type: textcontent: |text: |发布者/项目名: ${{ github.repository }}项目状态: ${{ job.status }}