简介
简单的介绍下家里的代码发布流程
步骤
目前CI使用的是gitea action
CD 使用的是argocd
然后最终项目会在k8s上跑起来
下面是gitea action 的yaml,可以参考下
name: ci
on:
push:
branches:
- 'master'
env:
APP_NAME: app
DING_SECRET: xxxx
DING_BASE_URL: xxxx
YAML_REPO: git.xxxxx.com/xxxxx/kubernetes-yaml
YAML_PATH: kubernetes-yaml/k8s/${{ env.APP_NAME }}
REGISTRY_URL: git.xxxxx.com
REGISTRY_USER: xxxxx
REGISTRY_PASSWORD: xxxxx
IMAGE_NAME: ${{ env.REGISTRY_URL }}/${{ env.REGISTRY_USER }}/${{ env.APP_NAME }}
GIT_EMAIL: [email protected]
GIT_USER: xxxxxx
GIT_PASSWORD: xxxxxx
ARGOCD_USER: admin
ARGOCD_PASS: xxxx
ARGOCD_URL: argocd.xxxxx.com
jobs:
docker:
runs-on: docker
steps:
# Set up Docker Buildx
- name: Set up Docker Buildx
uses: bboysoul/setup-buildx-action@v2
# Login to Docker Hub
- name: Login to Docker Hub
uses: bboysoul/login-action@v2
with:
registry: ${{ env.REGISTRY_URL }}
username: ${{ env.REGISTRY_USER }}
password: ${{ env.REGISTRY_PASSWORD }}
# Build and push
- name: Build and push
uses: bboysoul/build-push-action@v4
with:
push: true
tags: |
${{ env.IMAGE_NAME }}:latest
${{ env.IMAGE_NAME }}:${{ github.sha }}
cache-from: type=local,src=/root/.buildx-cache
cache-to: type=local,dest=/root/.buildx-cache,mode=max
# change images
- name: update images
run: |
git config --global user.email "${{ env.GIT_EMAIL }}"
git config --global user.name "${{ env.GIT_USER }}"
git clone https://${{ env.GIT_USER }}:${{ env.GIT_PASSWORD }}@${{ env.YAML_REPO }}.git
cd ${{ env.YAML_PATH }}
kustomize edit set image ${{ env.IMAGE_NAME }}:${{ github.sha }}
git add .
git commit -m "set image ${{ env.IMAGE_NAME }}:${{ github.sha }}"
git push
# argocd apply
- name: argocd apply
run: |
argocd login --insecure --username ${{ env.ARGOCD_USER }} --password ${{ env.ARGOCD_PASS }} ${{ env.ARGOCD_URL }}
argocd app sync ${{ env.APP_NAME }}
argocd app wait --timeout 300 ${{ env.APP_NAME }}
# dingtalk alert
- name: dingtalk alert success
uses: bboysoul/dingding-alert-action@main
if: ${{ success() }}
env:
DING_SECRET: ${{ env.DING_SECRET }}
DING_BASE_URL: ${{ env.DING_BASE_URL }}
TITLE: "镜像编译"
MSG: "镜像编译成功"
- name: dingtalk alert failed
uses: bboysoul/dingding-alert-action@main
if: ${{ failure() }}
env:
DING_SECRET: ${{ env.DING_SECRET }}
DING_BASE_URL: ${{ env.DING_BASE_URL }}
TITLE: "镜像编译"
MSG: "镜像编译失败"
APP_NAME其实就是项目的名字,其他的貌似也没有什么好说的,如果有好的优化点,可以留言
欢迎关注我的博客www.bboy.app
Have Fun