Update deploy.yml #5
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 via AWS SSM | |
on: | |
push: | |
branches: [main] # or 'main' depending on your branch name | |
jobs: | |
deploy: | |
name: Deploy via AWS CLI | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v2 | |
with: | |
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ secrets.AWS_REGION }} | |
- name: Get EC2 Instance ID by Tag | |
id: ec2 | |
run: | | |
INSTANCE_ID=$(aws ec2 describe-instances \ | |
--filters "Name=tag:Name,Values=php-website" \ | |
--query "Reservations[].Instances[].InstanceId" \ | |
--output text) | |
echo "INSTANCE_ID=$INSTANCE_ID" >> $GITHUB_ENV | |
- name: Send Deployment Command to EC2 via SSM | |
run: | | |
aws ssm send-command \ | |
--instance-ids "$INSTANCE_ID" \ | |
--document-name "AWS-RunShellScript" \ | |
--comment "Deploy Yii2 App using Docker" \ | |
--parameters 'commands=["cd /home/ubuntu/app","git pull origin master","docker compose down","docker compose up --build -d"]' \ | |
--output text |