EC2 Deployment Exclusions

User
name: Deploy to EC2

on:
push:
branches:
– master # Trigger on push to master branch

jobs:
deploy:
runs-on: ubuntu-latest
steps:
– name: Checkout code
uses: actions/checkout@v2

– name: Set up SSH
env:
PEM_FILE: ${{ secrets.PEM_FILE }} # Store your PEM file content in GitHub secrets
run: |
echo "$PEM_FILE" > key.pem
chmod 600 key.pem

– name: Delete public/build folder from EC2
env:
EC2_USER: ${{ secrets.EC2_USER }} # Store your EC2 username in GitHub secrets
EC2_HOST: ${{ secrets.EC2_HOST }} # Store your EC2 host in GitHub secrets
run: |
ssh -i key.pem -o StrictHostKeyChecking=no $EC2_USER@$EC2_HOST "rm -rf /var/www/shareyourthoughts/public/build"

– name: Deploy to EC2
env:
EC2_USER: ${{ secrets.EC2_USER }} # Store your EC2 username in GitHub secrets
EC2_HOST: ${{ secrets.EC2_HOST }} # Store your EC2 host in GitHub secrets
run: |
rsync -avz –no-times -e "ssh -i key.pem -o StrictHostKeyChecking=no" ./ $EC2_USER@$EC2_HOST:/var/www/shareyourthoughts
rm key.pem # Clean up the PEM file after deployment
prevent some folder to push

Assistant
To prevent some folders from being pushed to your EC2 instance, you can use the `–exclude` option in the `rsync` command. This will allow you to specify folders or files that you don't want to deploy.

Here’s how you can modify the `Deploy to EC2` step:

- name: Deploy to EC2
  env:
    EC2_USER: ${{ secrets.EC2_USER }}
    EC2_HOST: ${{ secrets.EC2_HOST }}
  run: |
    rsync -avz --no-times --exclude 'folder_to_exclude/' --exclude 'another_folder/*' -e "ssh -i key.pem -o StrictHostKeyChecking=no" ./ $EC2_USER@$EC2_HOST:/var/www/shareyourthoughts
    rm key.pem  # Clean up the PEM file after deployment

In this case:
– Replace `'folder_to_exclude/'` with the folder you want to exclude.
– You can use wildcards to match files or subdirectories, e.g., `'*.log'` to exclude all log files.

This will ensure that those specified folders or files are not deployed to your EC2 instance.

Leave a Comment

Your email address will not be published. Required fields are marked *