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 Yii2 App to EC2 | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repo | |
uses: actions/checkout@v3 | |
- name: Setup SSH key | |
run: | | |
echo "${{ secrets.EC2_SSH_KEY }}" > ec2_key.pem | |
chmod 600 ec2_key.pem | |
- name: Deploy to EC2 | |
run: | | |
ssh -o StrictHostKeyChecking=no -i ec2_key.pem ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF' | |
# Setup repo if first time | |
cd ~/yii2-app-basic || (git clone https://github.com/harshit075/yii2-app-basic.git && cd yii2-app-basic) | |
git pull origin main | |
docker stop yii2 || true | |
docker rm yii2 || true | |
docker build -t yii2-app . | |
docker run -d -p 8080:80 --name yii2 yii2-app | |
EOF | |