-
Notifications
You must be signed in to change notification settings - Fork 56
62 lines (51 loc) · 3.54 KB
/
main.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
name: Docker Build and Push
on:
push:
tags:
- 'v*' # 触发条件可以根据你的需求修改
jobs:
build-and-push:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Login to Docker Hub
run: echo "${{ secrets.REPO_PASS }}" | docker login -u "${{ secrets.REPO }}" --password-stdin
- name: Get the latest tag
id: get_latest_tag
run: |
latest_tag=$(git describe --tags --always)
echo "Latest tag is $latest_tag"
echo "::set-output name=latest_tag::$latest_tag"
- name: Build and push Docker image
run: |
chmod +x build_images.sh
./build_images.sh "${{ secrets.REPO }}"
env:
REPO: ${{ secrets.REPO }}
REPO_PASS: ${{ secrets.REPO_PASS }}
- name: Send Release Notification
if: success()
run: |
curl -X POST -H "Content-Type: application/json" -d '{"msg_type":"post","content":{"post":{"zh_cn":{"title":"moon项目更新通知","content":[[{"tag":"text","text":"palace项目有更新, 当前版本为: "},{"tag":"a","text":"${{ steps.get_latest_tag.outputs.latest_tag }}","href":"https://hub.docker.com/r/aidemoonio/palace/tags?name=${{ steps.get_latest_tag.outputs.latest_tag }}"}],[{"tag":"text","text":"houyi项目有更新, 当前版本为: "},{"tag":"a","text":"${{ steps.get_latest_tag.outputs.latest_tag }}","href":"https://hub.docker.com/r/aidemoonio/houyi/tags?name=${{ steps.get_latest_tag.outputs.latest_tag }}"}],[{"tag":"text","text":"rabbit项目有更新, 当前版本为: "},{"tag":"a","text":"${{ steps.get_latest_tag.outputs.latest_tag }}","href":"https://hub.docker.com/r/aidemoonio/rabbit/tags?name=${{ steps.get_latest_tag.outputs.latest_tag }}"}],[],[{"tag":"at","user_id":"all"}]]}}}}' ${{ secrets.HOOK }}
- name: Set up kubeconfig
run: |
mkdir -p $HOME/.kube
echo "${{ secrets.KUBECONFIG }}" > $HOME/.kube/config
env:
KUBECONFIG: $HOME/.kube/config
- name: Set up kubectl
uses: azure/setup-kubectl@v3
with:
version: 'latest'
- name: Deploy to Kubernetes
run: |
kubectl --insecure-skip-tls-verify set image deployment/palace palace=docker.cloudimages.asia/${{ secrets.REPO }}/palace:${{ steps.get_latest_tag.outputs.latest_tag }} -n ${{ secrets.K8S_NAMESPACE }}
kubectl --insecure-skip-tls-verify set image deployment/rabbit rabbit=docker.cloudimages.asia/${{ secrets.REPO }}/rabbit:${{ steps.get_latest_tag.outputs.latest_tag }} -n ${{ secrets.K8S_NAMESPACE }}
kubectl --insecure-skip-tls-verify set image deployment/houyi houyi=docker.cloudimages.asia/${{ secrets.REPO }}/houyi:${{ steps.get_latest_tag.outputs.latest_tag }} -n ${{ secrets.K8S_NAMESPACE }}
- name: verify deployment
run: |
kubectl --insecure-skip-tls-verify rollout status deployment/palace -n ${{ secrets.K8S_NAMESPACE }}
kubectl --insecure-skip-tls-verify rollout status deployment/rabbit -n ${{ secrets.K8S_NAMESPACE }}
kubectl --insecure-skip-tls-verify rollout status deployment/houyi -n ${{ secrets.K8S_NAMESPACE }}
curl -X POST -H "Content-Type: application/json" -d '{"msg_type":"post","content":{"post":{"zh_cn":{"title":"moon项目API部署通知","content":[[{"tag":"text","text":"moon项目API服务自动部署完成, 当前版本为: "},{"tag":"a","text":"${{ steps.get_latest_tag.outputs.latest_tag }}","href":"https://moon.aide-cloud.cn"}],[],[{"tag":"at","user_id":"all"}]]}}}}' ${{ secrets.HOOK }}