线上pipeline,(我使用是本地仓库的,你们使用切换成官网的即可)
name: Build and Push Docker Image deployment-k8s
on:
push:
branches:
- main
jobs:
build-and-push-image:
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: http://192.168.0.20:3000/admins/checkout@main
- name: Set up Docker Buildx
id: buildx
uses: http://192.168.0.20:3000/admins/setup-buildx-action@v2.6.0
- name: Login to DockerHub
uses: http://192.168.0.20:3000/admins/login-action@v3
with:
registry: ${{ secrets.REGISTRY }}
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Build Docker Image
id: docker_build
uses: http://192.168.0.20:3000/admins/build-push-action@v4
with:
push: true
file: ./Dockerfile-uat
tags: ${{ secrets.REGISTRY_PATH }}/www:${{ github.sha }}
- name: deploy to cluster
uses: http://192.168.0.20:3000/admins/kubectl@main
env:
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 deployment
uses: http://192.168.0.20:3000/admins/kubectl@main
env:
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 Application
uses: statsig-io/kubectl-via-eksctl@main
env:
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
region: ap-northeast-1
cluster: ${{ 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 Message
uses: http://192.168.0.20:3000/admins/feishu-action@v2
with:
url: ${{ secrets.FEISHU_BOT_WEBHOOK_URL }}
msg_type: text
content: |
text: |
发布者/项目名: ${{ github.repository }}
项目状态: ${{ job.status }}