From fa055a9fcc666463702e411fbd94bd6a0dc8d3a4 Mon Sep 17 00:00:00 2001 From: charles Date: Sat, 11 Jan 2025 14:54:42 -0500 Subject: [PATCH 1/2] ec2 --- .github/deploy.yml | 47 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/deploy.yml diff --git a/.github/deploy.yml b/.github/deploy.yml new file mode 100644 index 0000000..2880d6a --- /dev/null +++ b/.github/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 From 2d1677dba590005aed760c8e7ce49a6aff2c2ec3 Mon Sep 17 00:00:00 2001 From: charles Date: Sat, 11 Jan 2025 14:56:08 -0500 Subject: [PATCH 2/2] ec2 --- .github/deploy.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/deploy.yml b/.github/deploy.yml index 2880d6a..29039c2 100644 --- a/.github/deploy.yml +++ b/.github/deploy.yml @@ -3,7 +3,7 @@ name: Deploy HTML to EC2 on: push: branches: - - github-action # Change to your branch that has the .github/workflows folder + - githubaction # Change to your branch that has the .github/workflows folder jobs: deploy: