From 520fdc918d233d004b8f0643621352de598967c7 Mon Sep 17 00:00:00 2001 From: charles Date: Sat, 11 Jan 2025 14:03:41 -0500 Subject: [PATCH] ec2 --- .github/workflow/deploy.yml | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflow/deploy.yml diff --git a/.github/workflow/deploy.yml b/.github/workflow/deploy.yml new file mode 100644 index 0000000..2880d6a --- /dev/null +++ b/.github/workflow/deploy.yml @@ -0,0 +1,47 @@ +name: Deploy HTML to EC2 + +on: + push: + branches: + - github-action # Change to your branch that has the .github/workflows folder + +jobs: + deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v3 + + - name: List working directory contents + run: ls -la + + - name: zip project + run: zip -r webapp.zip . + + - name: Connect to EC2 and copy docker compose file + uses: appleboy/scp-action@v0.1.7 # GitHub Action to SCP files to remote server + with: + host: ${{ secrets.EC2_PUBLIC_IP }} # Public IP of your EC2 instance + username: ${{ secrets.EC2_USERNAME }} # Adjust based on your EC2 AMI + key: ${{ secrets.EC2_PEM }} + port: 22 + source: "./webapp.zip" # Path to your artifact + target: "~/" + + - name: Connect to EC2 and apply docker-compose file + uses: appleboy/ssh-action@v0.1.7 + with: + host: ${{ secrets.EC2_PUBLIC_IP }} + username: ubuntu + key: ${{ secrets.EC2_PEM }} + port: 22 + script: | + # Check that zip is installed + sudo apt install zip -y + # Remove the existing files and directories + sudo rm -rf /var/www/html/ + # Create a new, empty directory at /var/www/html/ + sudo mkdir /var/www/html/ + # Extract the contents of "webapp.zip" into the /var/www/html/ directory + sudo unzip webapp.zip -d /var/www/html/ \ No newline at end of file