Repository navigation
163 lines (142 loc) · 6.77 KB
/
Copy pathbuild.yml
File metadata and controls
163 lines (142 loc) · 6.77 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
name: Build and Push Docker Image to Docker Hub
on:
push:
tags:
- '[0-9]+.[0-9]+.[0-9]+'
env:
IMAGE_NAME: acrossoffwest/tmgr-ui
jobs:
build:
name: push docker image to hub
runs-on: ubuntu-latest
steps:
- name: check repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.ref }}
- name: login to docker registry
uses: docker/login-action@v3
with:
username: ${{secrets.DOCKERHUB_USERNAME}}
password: ${{secrets.DOCKERHUB_TOKEN}}
- name: Get the tag name
id: get_tag
run: echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Get commit list
id: get_commits
run: |
CURRENT_TAG="${{ env.TAG_NAME }}"
PREVIOUS_TAG=$(git tag --sort=-v:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | grep -v "^${CURRENT_TAG}$" | head -n 1)
if [ -z "$PREVIOUS_TAG" ]; then
COMMITS=$(git log --pretty=format:"- %s (%an)" -10)
else
COMMITS=$(git log "${PREVIOUS_TAG}..${CURRENT_TAG}" --pretty=format:"- %s (%an)")
fi
echo "COMMITS<<EOF" >> $GITHUB_ENV
echo "$COMMITS" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: build and push docker image to registry
uses: docker/build-push-action@v5
with:
context: ./
push: true
tags: |
${{ env.IMAGE_NAME }}:${{ env.TAG_NAME }}
${{ env.IMAGE_NAME }}:latest
build-args: |
APP_URL=${{ secrets.APP_URL }}
VITE_API_BASE_URL=${{ secrets.VITE_API_BASE_URL }}
VITE_PUSHER_APP_ID=${{ secrets.VITE_PUSHER_APP_ID }}
VITE_PUSHER_KEY=${{ secrets.VITE_PUSHER_KEY }}
VITE_PUSHER_SECRET=${{ secrets.VITE_PUSHER_SECRET }}
VITE_PUSHER_CLUSTER=${{ secrets.VITE_PUSHER_CLUSTER }}
VITE_PUSHER_HOST=${{ secrets.VITE_PUSHER_HOST }}
VITE_PUSHER_PORT=${{ secrets.VITE_PUSHER_PORT }}
VITE_PUSHER_SCHEME=${{ secrets.VITE_PUSHER_SCHEME }}
VITE_TELEGRAM_BOT_NAME=${{ secrets.VITE_TELEGRAM_BOT_NAME }}
VITE_NTFY_SERVER_URL=${{ secrets.VITE_NTFY_SERVER_URL }}
VITE_APP_VERSION=${{ env.TAG_NAME }}
- name: Send build failure notification
if: failure()
run: |
COMMITS_ESCAPED=$(echo "${{ env.COMMITS }}" | sed 's/"/\\"/g')
curl -X POST https://notifications.aow.space/ \
-H "Content-Type: application/json" \
-d '{
"message": "❌ tmgr-ui build failed!\n🔖 Version: ${{ env.TAG_NAME }}\n🕐 Time: '"$(date)"'\n📝 Commit: ${{ github.sha }}\n👤 Author: ${{ github.actor }}\n📋 Commits:\n'"$COMMITS_ESCAPED"'\n🔗 Check logs: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"receivers": [-1001837078387]
}'
deploy:
needs: [ build ]
if: success()
name: Deploy App
runs-on: ubuntu-latest
steps:
- name: check repository
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.ref }}
- name: Get the tag name
id: get_tag
run: echo "TAG_NAME=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
- name: Get commit list
id: get_commits_deploy
run: |
CURRENT_TAG="${{ env.TAG_NAME }}"
PREVIOUS_TAG=$(git tag --sort=-v:refname | grep -E '^[0-9]+\.[0-9]+\.[0-9]+$' | grep -v "^${CURRENT_TAG}$" | head -n 1)
if [ -z "$PREVIOUS_TAG" ]; then
COMMITS=$(git log --pretty=format:"- %s (%an)" -10)
else
COMMITS=$(git log "${PREVIOUS_TAG}..${CURRENT_TAG}" --pretty=format:"- %s (%an)")
fi
echo "COMMITS<<EOF" >> $GITHUB_ENV
echo "$COMMITS" >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Update deployment file
run: TAG=$(echo $GITHUB_SHA | head -c7) && sed -i 's|<IMAGE>|${{ env.IMAGE_NAME }}:'${{ env.TAG_NAME }}'|' $GITHUB_WORKSPACE/config/deployment.yml
- name: Create and save kube config for k8s
run: rm -rf ~/.kube && mkdir ~/.kube && cd ~/.kube && touch config && echo "${{ secrets.HETZNER_CLUSTER_CONFIG }}" > config
- name: Create Docker Hub Secret
continue-on-error: true
run: kubectl create secret docker-registry dockerhub-secret -n applications --docker-server=https://index.docker.io/v1/ --docker-username=${{secrets.DOCKERHUB_USERNAME}} --docker-password=${{secrets.DOCKERHUB_TOKEN}}
- name: Delete existing secret
run: kubectl delete secret tmgr-ui-secret -n applications
continue-on-error: true
- name: Create Kubernetes Secret
run: |
kubectl create secret generic tmgr-ui-secret -n applications \
--from-literal=APP_URL="${{ secrets.APP_URL }}" \
--from-literal=VITE_API_BASE_URL=${{ secrets.VITE_API_BASE_URL }} \
--from-literal=VITE_PUSHER_APP_ID="${{ secrets.VITE_PUSHER_APP_ID }}" \
--from-literal=VITE_PUSHER_KEY=${{ secrets.VITE_PUSHER_KEY }} \
--from-literal=VITE_PUSHER_SECRET=${{ secrets.VITE_PUSHER_SECRET }} \
--from-literal=VITE_PUSHER_CLUSTER=${{ secrets.VITE_PUSHER_CLUSTER }} \
--from-literal=VITE_TELEGRAM_BOT_NAME=${{ secrets.VITE_TELEGRAM_BOT_NAME }}
- name: Deploy to DigitalOcean Kubernetes
run: kubectl apply -f $GITHUB_WORKSPACE/config/deployment.yml
- name: Verify deployment
run: kubectl rollout status -n applications deployment/tmgr-ui
- name: Remove k8s configs
run: rm -rf ~/.kube
- name: Send success notification
if: success()
run: |
COMMITS_ESCAPED=$(echo "${{ env.COMMITS }}" | sed 's/"/\\"/g')
curl -X POST https://notifications.aow.space/ \
-H "Content-Type: application/json" \
-d '{
"message": "✅ tmgr-ui deployment successful!\n🔖 Version: ${{ env.TAG_NAME }}\n🕐 Time: '"$(date)"'\n📝 Commit: ${{ github.sha }}\n👤 Author: ${{ github.actor }}\n\n📋 Commits:\n'"$COMMITS_ESCAPED"'",
"receivers": [-1001837078387]
}'
- name: Send failure notification
if: failure()
run: |
COMMITS_ESCAPED=$(echo "${{ env.COMMITS }}" | sed 's/"/\\"/g')
curl -X POST https://notifications.aow.space/ \
-H "Content-Type: application/json" \
-d '{
"message": "❌ tmgr-ui deployment failed!\n🔖 Version: ${{ env.TAG_NAME }}\n🕐 Time: '"$(date)"'\n📝 Commit: ${{ github.sha }}\n👤 Author: ${{ github.actor }}\n📋 Commits:\n'"$COMMITS_ESCAPED"'\n🔗 Check logs: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}",
"receivers": [-1001837078387]
}'