Skip to content

Commit 21f8351

Browse files
send more messages to slack
1 parent 8868d40 commit 21f8351

File tree

1 file changed

+26
-11
lines changed

1 file changed

+26
-11
lines changed

.github/workflows/deploy.yml

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
- name: Send slack message with github commit url
2929
run: >
3030
curl -X POST -H 'Content-type: application/json'
31-
--data '{"text":"${{ github.event.head_commit.message }} - https://${{ github.repository }}/commit/${{ github.sha }}"}'
31+
--data '{"text":":rocket: Deployment started for commit: ${{ github.event.head_commit.message }} - https://${{ github.repository }}/commit/${{ github.sha }}"}'
3232
${{ env.SLACK_WEBHOOK_URL }}
3333
- name: JDK
3434
if: ${{ github.event.inputs.build_number == '' }}
@@ -41,9 +41,11 @@ jobs:
4141
if [ -n "${{ github.event.inputs.build_number }}" ]; then
4242
BUILD_NUMBER=${{ github.event.inputs.build_number }}
4343
echo "using provided build number: $BUILD_NUMBER"
44+
curl -X POST -H 'Content-type: application/json' --data '{"text":":package: Using provided build number: $BUILD_NUMBER"}' ${{ env.SLACK_WEBHOOK_URL }}
4445
else
4546
BUILD_NUMBER=$(date +'%d%m%Y%H%M%S')
4647
echo "using generated build number: $BUILD_NUMBER"
48+
curl -X POST -H 'Content-type: application/json' --data '{"text":":gear: Generated new build number: $BUILD_NUMBER"}' ${{ env.SLACK_WEBHOOK_URL }}
4749
fi
4850
echo "BUILD_NUMBER=$BUILD_NUMBER" >> $GITHUB_ENV
4951
- name: Login to Docker Hub
@@ -54,22 +56,29 @@ jobs:
5456
- name: Check if provided docker image exists
5557
if: ${{ github.event.inputs.build_number != '' }}
5658
run: |
57-
IMAGE_NAME="${{ env.DOCKER_USERNAME }}/${{ env.DOCKER_IMAGE_NAME }}:$BUILD_NUMBER"
58-
echo "checking if $IMAGE_NAME exists"
59-
if ! docker manifest inspect "$IMAGE_NAME" > /dev/null 2>&1; then
60-
echo "provided image $IMAGE_NAME does not exits. exiting..."
59+
IMAGE="${{ env.DOCKER_USERNAME }}/${{ env.DOCKER_IMAGE_NAME }}:$BUILD_NUMBER"
60+
echo "checking if $IMAGE exists"
61+
if ! docker manifest inspect "$IMAGE" > /dev/null 2>&1; then
62+
echo "provided image $IMAGE does not exist. exiting..."
63+
curl -X POST -H 'Content-type: application/json' --data '{"text":":x: :warning: Provided image $IMAGE does not exist! Exiting deployment..."}' ${{ env.SLACK_WEBHOOK_URL }}
6164
exit 1
6265
fi
63-
echo "provided image $IMAGE_NAME exits ✅"
66+
echo "provided image $IMAGE exists ✅"
67+
curl -X POST -H 'Content-type: application/json' --data '{"text":":white_check_mark: Image $IMAGE exists and ready for deployment"}' ${{ env.SLACK_WEBHOOK_URL }}
68+
echo "IMAGE=$IMAGE" >> $GITHUB_ENV
6469
- name: Maven Clean Verify
6570
if: ${{ github.event.inputs.build_number == '' }}
66-
run: mvn -B -ntp clean verify jib:build -Ddocker.image.tag=$BUILD_NUMBER
71+
run: |
72+
curl -X POST -H 'Content-type: application/json' --data '{"text":":hammer_and_wrench: Building and deploying $IMAGE to Docker Hub..."}' ${{ env.SLACK_WEBHOOK_URL }}
73+
mvn -B -ntp clean verify jib:build -Ddocker.image.tag=$BUILD_NUMBER
74+
curl -X POST -H 'Content-type: application/json' --data '{"text":":white_check_mark: Successfully built and pushed $IMAGE to Docker Hub"}' ${{ env.SLACK_WEBHOOK_URL }}
6775
- name: Setup SSH Agent
6876
uses: webfactory/[email protected]
6977
with:
7078
ssh-private-key: ${{ env.EC2_SSH_PRIVATE_KEY }}
7179
- name: SSH To EC2 and Deploy
7280
run: |
81+
curl -X POST -H 'Content-type: application/json' --data '{"text":":cloud: Deploying $IMAGE to AWS EC2..."}' ${{ env.SLACK_WEBHOOK_URL }}
7382
ssh -o StrictHostKeyChecking=no ec2-user@$EC2_PUBLIC_IP_ADDRESS << EOF
7483
cd ~
7584
sed -i 's|image: '"$DOCKER_USERNAME"'/'"$DOCKER_IMAGE_NAME"':.*$|image: '"$DOCKER_USERNAME"'/'"$DOCKER_IMAGE_NAME"':'"$BUILD_NUMBER"'|' docker-compose.yml
@@ -79,9 +88,15 @@ jobs:
7988
docker ps
8089
echo "$BUILD_NUMBER" > build-number.txt
8190
EOF
91+
curl -X POST -H 'Content-type: application/json' --data '{"text":":tada: Successfully deployed $IMAGE to AWS EC2"}' ${{ env.SLACK_WEBHOOK_URL }}
8292
- name: Send slack message with status
8393
if: always()
84-
run: >
85-
curl -X POST -H 'Content-type: application/json'
86-
--data '{"text":"Job status ${{ job.status }}"}'
87-
${{ env.SLACK_WEBHOOK_URL }}
94+
run: |
95+
if [ "${{ job.status }}" == "success" ]; then
96+
EMOJI=":tada:"
97+
MESSAGE="Deployment completed successfully!"
98+
else
99+
EMOJI=":x:"
100+
MESSAGE="Deployment failed!"
101+
fi
102+
curl -X POST -H 'Content-type: application/json' --data "{\"text\":\"$EMOJI $MESSAGE - Job status: ${{ job.status }}\"}" ${{ env.SLACK_WEBHOOK_URL }}

0 commit comments

Comments
 (0)