Skip to content

testing login cd 4

testing login cd 4 #7

name: CD - Deploy React Frontend
on:
workflow_dispatch:
push:
branches:
- main
paths:
- frontend/react/**
jobs:
deploy:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./frontend/react
steps:
- uses: actions/checkout@v3
- name: First message when CD workflow starts
run: >
curl -X POST -H 'Content-type: application/json'
--data '{"text":":start: :nyancat_big: Starting.....React deployment :react: :cool-doge:"}'
${{ secrets.SLACK_WEBHOOK_URL }}
- name: Send Slack Commit Message And SHA
run: >
curl -X POST -H 'Content-type: application/json'
--data '{"text":":github: ${{ github.server_url }}/${{ github.repository }}/commit/${{ github.sha }} - ${{ github.event.head_commit.message }}"}'
${{ secrets.SLACK_WEBHOOK_URL }}
- name: Send Slack Message
run: >
curl -X POST -H 'Content-type: application/json'
--data '{"text":"Deployment started :progress_bar: :fingerscrossed:"}'
${{ secrets.SLACK_WEBHOOK_URL }}
- name: Set build number
id: build-number
run: echo "BUILD_NUMBER=$(date '+%d.%m.%Y.%H.%M.%S')" >> $GITHUB_OUTPUT
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_ACCESS_TOKEN }}
- name: Docker Build and push
run: |
chmod +x ../../.ci/build-frontend-react-publish.sh
USERNAME=shreyas957 \
REPO=shreyas-full-stack-professional-react \
TAG=${{ steps.build-number.outputs.BUILD_NUMBER }} \
../../.ci/build-frontend-react-publish.sh . \
--build-arg api_base_url=http://spring-boot-full-stack-professio-env.eba-zwt8muqa.ap-south-1.elasticbeanstalk.com:8080
- name: Send Slack Message
run: >
curl -X POST -H 'Content-type: application/json'
--data '{"text":":docker: Image tag:${{ steps.build-number.outputs.BUILD_NUMBER }} pushed to DockerHub - https://hub.docker.com/repository/docker/shreyas957/shreyas-full-stack-professional-react"}'
${{ secrets.SLACK_WEBHOOK_URL }}
- name: Update Dockerrun.aws.json api image tag with new build number
run: |
echo "Dockerrun.aws.json before updating tag"
cat ../../Dockerrun.aws.json
sed -i -E 's_(shreyas957/shreyas-full-stack-professional-react:)([^"]*)_\1'${{steps.build-number.outputs.BUILD_NUMBER}}'_' ../../Dockerrun.aws.json
echo "Dockerrun.aws.json after updating tag"
cat ../../Dockerrun.aws.json
- name: Send Slack Message
run: >
curl -X POST -H 'Content-type: application/json'
--data '{"text":":aws: Starting Deployment to Elastic Beanstalk :progress_bar:"}'
${{ secrets.SLACK_WEBHOOK_URL }}
- name: Deploy to Elastic Beanstalk
uses: einaregilsson/beanstalk-deploy@v21
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: ${{ secrets.EB_APPLICATION_NAME }}
environment_name: ${{ secrets.EB_ENVIRONMENT_NAME }}
version_label: ${{ steps.build-number.outputs.BUILD_NUMBER }}
version_description: ${{ github.SHA }}
region: ${{ secrets.EB_REGION }}
deployment_package: Dockerrun.aws.json
wait_for_environment_recovery: 60
- name: Send Slack Message
run: >
curl -X POST -H 'Content-type: application/json'
--data '{"text":":githubloading: Committing to repo https://github.com/shreyas957/Spring-Boot-Full-Stack-Professional/"}'
${{ secrets.SLACK_WEBHOOK_URL }}
- name: commit and push Dockerrun.aws.json
run: |
git config user.name github-actions
git config user.email [email protected]
git add ../../Dockerrun.aws.json
git commit -m "Update Dockerrun.aws.json docker image with new tag ${{ steps.build-number.outputs.BUILD_NUMBER }}"
git push
- name: Send Slack Message
run: >
curl -X POST -H 'Content-type: application/json'
--data '{"text":"Deployment and commit completed :github-check-mark: :party_blob:"}'
${{ secrets.SLACK_WEBHOOK_URL }}
- name: Send Slack Message
if: always()
run: >
curl -X POST -H 'Content-type: application/json'
--data '{"text":"Job Status ${{ job.status }}"}'
${{ secrets.SLACK_WEBHOOK_URL }}