-
Notifications
You must be signed in to change notification settings - Fork 0
153 lines (135 loc) · 4.84 KB
/
deploy-docker.yml
File metadata and controls
153 lines (135 loc) · 4.84 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
# ==============================================
# PyrenzAI Pipeline
# ==============================================
# This pipeline automatically handles:
#
# Building of the Application:
# - Uses Docker Buildx to build the latest image
# - Supports semantic versioning via Git tags
# - Caches Docker layers for faster builds
#
# Publishing Docker Images:
# - Pushes both `latest` and tagged versions to Docker Hub
#
# Discord Notifications:
# - Notifies on successful deploy with full metadata
# - Alerts on failure with error step, time, and message
# - Uses rich Discord embeds for clean UI/UX
#
# Trigger:
# - Runs automatically on push to the `main` branch
#
# ==============================================
name: PyrenzAI Pipeline
on:
push:
branches:
- main
env:
IMAGE_NAME: ${{ secrets.DOCKERHUB_USERNAME }}/pyrenzai
IMAGE_TAG_LATEST: latest
jobs:
PyrenzAI-Pipeline:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Cache Docker layers
uses: actions/cache@v3
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-docker-${{ github.sha }}
restore-keys: |
${{ runner.os }}-docker-
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Log in to Docker Hub
run: |
echo "${{ secrets.DOCKERHUB_TOKEN }}" | docker login -u "${{ secrets.DOCKERHUB_USERNAME }}" --password-stdin
- name: Build and push Docker image
run: |
docker buildx build \
--cache-from=type=local,src=/tmp/.buildx-cache \
--cache-to=type=local,dest=/tmp/.buildx-cache-new,mode=max \
-t $IMAGE_NAME:$IMAGE_TAG_LATEST \
--push \
.
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache
- name: Print Docker Image Link
run: |
echo "🚀 Image deployed at: https://hub.docker.com/r/$IMAGE_NAME:$IMAGE_TAG_LATEST"
- name: Send Discord notification on success
if: success()
run: |
echo "Sending Discord success embed..."
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
DOCKER_USER="${{ secrets.DOCKERHUB_USERNAME }}"
REPO="$IMAGE_NAME"
TAG="$IMAGE_TAG_LATEST"
URL="https://hub.docker.com/r/$IMAGE_NAME:$TAG"
PAYLOAD=$(jq -n \
--arg ts "$TIMESTAMP" \
--arg user "$DOCKER_USER" \
--arg repo "$REPO" \
--arg tag "$TAG" \
--arg url "$URL" \
'{
embeds: [
{
title: "✅ PyrenzAI Docker Deploy Successful",
color: 5763719,
fields: [
{ name: "Time", value: $ts, inline: false },
{ name: "Publisher", value: $user, inline: true },
{ name: "Version", value: $tag, inline: true },
{ name: "Docker Image", value: $url, inline: false }
],
footer: { text: "PyrenzAI CI" },
timestamp: $ts
}
]
}')
curl -H "Content-Type: application/json" \
-X POST \
-d "$PAYLOAD" \
${{ secrets.DISCORD_WEBHOOK_URL }}
- name: Send Discord notification on failure
if: failure()
run: |
echo "Sending Discord error embed..."
TIMESTAMP=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
DOCKER_USER="${{ secrets.DOCKERHUB_USERNAME }}"
REPO="$IMAGE_NAME"
BUILD_STEP="${{ github.job }}"
ERROR_MSG="Deployment failed on job $BUILD_STEP."
TAG="$IMAGE_TAG_LATEST"
PAYLOAD=$(jq -n \
--arg ts "$TIMESTAMP" \
--arg user "$DOCKER_USER" \
--arg repo "$REPO" \
--arg step "$BUILD_STEP" \
--arg err "$ERROR_MSG" \
--arg ver "$TAG" \
'{
embeds: [
{
title: "🚨 ERROR ON DEPLOYMENT",
color: 15158332,
fields: [
{ name: "Time", value: $ts, inline: false },
{ name: "Publisher", value: $user, inline: true },
{ name: "Repo", value: $repo, inline: true },
{ name: "Build Step", value: $step, inline: false },
{ name: "Version", value: $ver, inline: true },
{ name: "Error Message", value: $err, inline: false }
],
footer: { text: "PyrenzAI CI" },
timestamp: $ts
}
]
}')
curl -H "Content-Type: application/json" \
-X POST \
-d "$PAYLOAD" \
${{ secrets.DISCORD_WEBHOOK_URL }}