Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Githubaction #9

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Deploy HTML to EC2

on:
push:
branches:
- githubaction # 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/[email protected] # 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/[email protected]
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/