Version 2 #3
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy to EC2 | |
| on: | |
| push: | |
| branches: [main] | |
| workflow_dispatch: | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Deploy nginx to EC2 | |
| uses: appleboy/ssh-action@v1.0.3 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USER }} | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| script: | | |
| sudo apt-get install -y -q nginx | |
| sudo tee /var/www/html/index.html > /dev/null <<'EOF' | |
| <!DOCTYPE html> | |
| <html> | |
| <head><title>Hello World</title></head> | |
| <body> | |
| <h1>Hello World from EC2!</h1> | |
| <p>Deployed via GitHub Actions.</p> | |
| </body> | |
| </html> | |
| EOF | |
| sudo systemctl enable nginx | |
| sudo systemctl start nginx |