update message telegram and add message when start deploy #56
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy to Kubernetes | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
send-notification-started: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Send Telegram Notification | |
env: | |
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} | |
TELEGRAM_CHAT_ID: "${{ secrets.TELEGRAM_GROUP_DEPLOYMENTS }}" | |
run: | | |
curl -X POST \ | |
https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage \ | |
-d chat_id=${TELEGRAM_CHAT_ID} \ | |
-d text="π <b>Kubernetes Engine CI-CD Template</b> Deployment has started! | |
Your deployment process is in progress. π οΈπ" \ | |
-d parse_mode=HTML | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v2 | |
- name: Set up Google Cloud SDK | |
run: | | |
curl -o google-cloud-sdk.tar.gz https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-372.0.0-linux-x86_64.tar.gz | |
tar -xf google-cloud-sdk.tar.gz | |
./google-cloud-sdk/install.sh --quiet | |
echo "${{ secrets.GCLOUD_AUTH }}" > /tmp/gcloud.json | |
./google-cloud-sdk/bin/gcloud auth activate-service-account --key-file=/tmp/gcloud.json | |
./google-cloud-sdk/bin/gcloud config set project ${{ secrets.GCP_PROJECT_ID }} | |
- name: Configure Docker CLI | |
run: | | |
./google-cloud-sdk/bin/gcloud auth configure-docker | |
- name: Build and push Docker image | |
run: | | |
docker build -t gcr.io/${{ secrets.GCP_PROJECT_ID }}/kubernetes-engine-ci-cd-template . | |
docker push gcr.io/${{ secrets.GCP_PROJECT_ID }}/kubernetes-engine-ci-cd-template | |
- name: Install kubectl plugin | |
run: | | |
./google-cloud-sdk/bin/gcloud components install kubectl | |
- name: Set kubectl context | |
run: | | |
./google-cloud-sdk/bin/gcloud container clusters get-credentials ${{ secrets.GCP_CLUSTER_NAME }} --zone ${{ secrets.GCP_CLUSTER_ZONE }} --project ${{ secrets.GCP_PROJECT_ID }} | |
- name: Configure kubectl | |
run: | | |
gcloud auth activate-service-account --key-file=/tmp/gcloud.json | |
kubectl config set-credentials gke-cluster-user --token=$(gcloud auth print-access-token) | |
kubectl config set-context gke-cluster --cluster=${{ secrets.GCP_CLUSTER_CONTEXT }} --user=gke-cluster-user | |
kubectl config use-context gke-cluster | |
- name: Deploy to Kubernetes | |
run: | | |
kubectl apply -f deployment.yaml | |
send-notification-successful: | |
needs: deploy | |
runs-on: ubuntu-latest | |
if: ${{ success() && needs.deploy.result == 'success' }} | |
steps: | |
- name: Send Telegram Notification | |
env: | |
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} | |
TELEGRAM_CHAT_ID: "${{ secrets.TELEGRAM_GROUP_DEPLOYMENTS }}" | |
run: | | |
curl -X POST \ | |
https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage \ | |
-d chat_id=${TELEGRAM_CHAT_ID} \ | |
-d text="π <b>Kubernetes Engine CI-CD Template</b> Deployment was successful! | |
Your amazing tool is now available for everyone! πβ¨" \ | |
-d parse_mode=HTML | |
send-notification-failed: | |
needs: deploy | |
runs-on: ubuntu-latest | |
if: ${{ failure() && needs.deploy.result == 'failure' }} | |
steps: | |
- name: Send Telegram Notification | |
env: | |
TELEGRAM_BOT_TOKEN: ${{ secrets.TELEGRAM_BOT_TOKEN }} | |
TELEGRAM_CHAT_ID: "${{ secrets.TELEGRAM_GROUP_DEPLOYMENTS }}" | |
run: | | |
curl -X POST \ | |
https://api.telegram.org/bot${TELEGRAM_BOT_TOKEN}/sendMessage \ | |
-d chat_id=${TELEGRAM_CHAT_ID} \ | |
-d text="β Oh no! <b>Kubernetes Engine CI-CD Template</b> Deployment failed! | |
There might be something wrong with the process. | |
Please check it out! π οΈπ" \ | |
-d parse_mode=HTML |