15:30 pm

PragetX

InfinitiTalks

  • Frontend CI/CD pipeline setup for deployment on ec2 along with Het Vaghasiya

CI/CD pipeline with Github Action

  • Build react app
  • SSH and delete previous folders
  • SCP and copy the folders
  • SSH back and move the files
  • Here’s the Github Action Snippet
name: Deploy React App to EC2
 
on:
  push:
    branches:
      - main # Change this to the branch you want to deploy from
 
jobs:
  build:
    runs-on: ubuntu-latest
 
    steps:
      - name: Checkout repository
        uses: actions/checkout@v2
 
      - name: Install Node.js
        uses: actions/setup-node@v2
        with:
          node-version: '21' # Change this to match your project's Node.js version
 
      - name: Install dependencies
        run: npm install
 
      - name: Build React app
        run: CI=false npm run build
        
      - name: SSH into EC2 instance and delete previous files
        uses: appleboy/ssh-action@master
        with:
          host: ${{ secrets.EC2_HOST }}
          username: ${{ secrets.EC2_USERNAME }}
          key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
          port: 22 # Change if your SSH port is different
          script: |
            sudo rm -r /tmp/dist/*
            sudo rm -r /var/www/html/*
      - name: SCP to EC2 instance
        uses: appleboy/scp-action@master
        with:
          host: ${{ secrets.EC2_HOST }}
          username: ${{ secrets.EC2_USERNAME }}
          key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
          source: "dist/" # Change this to match your build output directory
          target: "/tmp" # Change this to a directory accessible by the SSH user on the EC2 instance
 
      - name: SSH into EC2 instance and deploy
        uses: appleboy/ssh-action@master
        with:
          host: ${{ secrets.EC2_HOST }}
          username: ${{ secrets.EC2_USERNAME }}
          key: ${{ secrets.EC2_SSH_PRIVATE_KEY }}
          port: 22 # Change if your SSH port is different
          script: |
            sudo mv /tmp/dist/* /var/www/html/
            sudo systemctl reload nginx

Backend Changes

Delete Listener will initiate Delete of that User as well.
    def destroy(self, request, *args, **kwargs):
	    # ...
        listener = self.get_object(request)
        user = listener.user
        user.delete()
        return delete_resp
Delete Media when Parent Content Deleted.

Implemented Media delete logic of all audios directly inside the BaseModel of Dehypnosis

class BaseDehypnosis(models.Model):
	# ...
    def delete(self, *args, **kwargs):
        audio = self.audio
        super().delete(*args, **kwargs)
        audio.delete(save=False)

Implemented Delete of Profile Picture for a listener from storage when listener is deleted.

### apps/talks/api/views.py
class ListenerApi(CustomViewSetMaster):
    def destroy(self, request, *args, **kwargs):
	    # ...
        listener = self.get_object(request)
        profile_pic = listener.profile_pic
        if profile_pic:
            profile_pic.delete()
		# ...

Found a way to make Fixtures as Well take Backups and Restore it in Django

Tried different methods including pg_dump and pg_restore Always stucking with migrate errors.

Found a trick to it. Initially tried

python manage.py dumpdata --indent=4 > dump.json
python manage.py loaddata dump.json

Fails when loading it to database.

Researched through: Errors due to contenttypes

python manage.py dumpdata --indent=4 -e contenttypes > dump.json

Different contentypes are referenced by other internal models on different devices.

Removed more internal models as auth and admin data by :

python manage.py dumpdata  -e contenttypes -e auth -e admin --indent 4 > local_dump.json

<<Yesterday Tomorrow>>


Links : Tags : Year : 2024 Month : March 24, March Date : 12th March, Tuesday, 2024, 12th March Category : Daily