From 4971f431979185fc3075b714b94f8e181fe34bc0 Mon Sep 17 00:00:00 2001 From: charles Date: Sat, 11 Jan 2025 11:43:42 -0500 Subject: [PATCH 1/3] ghaction dploy --- .github/workflow/deploy.yml | 17 +++++++++++++++++ 1 file changed, 17 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..5d30ab2 --- /dev/null +++ b/.github/workflow/deploy.yml @@ -0,0 +1,17 @@ +name: Deploy HTML to EC2 + +on: + push: + branches: + - git-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 \ No newline at end of file From cf4b40886ae4c9cf8efce16e9513b26ba1829cd6 Mon Sep 17 00:00:00 2001 From: charles Date: Sat, 11 Jan 2025 12:48:58 -0500 Subject: [PATCH 2/3] ghaction --- .github/{workflow => workflows}/deploy.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/{workflow => workflows}/deploy.yml (100%) diff --git a/.github/workflow/deploy.yml b/.github/workflows/deploy.yml similarity index 100% rename from .github/workflow/deploy.yml rename to .github/workflows/deploy.yml From 351bde9cde11818c8b64c108a4665b5d9457eb64 Mon Sep 17 00:00:00 2001 From: charles Date: Sat, 11 Jan 2025 13:31:57 -0500 Subject: [PATCH 3/3] ec2 deploy --- .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..75c6c95 --- /dev/null +++ b/.github/workflow/deploy.yml @@ -0,0 +1,47 @@ +name: Deploy HTML to EC2 + +on: + push: + branches: + - git-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