Skip to content

Commit 996745a

Browse files
authored
Update deploy.yml
1 parent 6c4d859 commit 996745a

File tree

1 file changed

+27
-34
lines changed

1 file changed

+27
-34
lines changed

.github/workflows/deploy.yml

Lines changed: 27 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,39 @@
1-
name: Deploy to EC2 via SSM
1+
name: Deploy Yii2 App to EC2 via AWS SSM
22

33
on:
44
push:
5-
branches: [ main ]
5+
branches: [main] # or 'main' depending on your branch name
66

77
jobs:
88
deploy:
9-
name: Deploy Yii2 App
9+
name: Deploy via AWS CLI
1010
runs-on: ubuntu-latest
1111

12-
env:
13-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
14-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
15-
AWS_REGION: ${{ secrets.AWS_REGION }}
16-
1712
steps:
18-
- name: Checkout repository
19-
uses: actions/checkout@v3
13+
- name: Checkout code
14+
uses: actions/checkout@v3
2015

21-
- name: Install AWS CLI
22-
run: |
23-
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
24-
unzip awscliv2.zip
25-
sudo ./aws/install
16+
- name: Configure AWS Credentials
17+
uses: aws-actions/configure-aws-credentials@v2
18+
with:
19+
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
20+
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
21+
aws-region: ${{ secrets.AWS_REGION }}
2622

27-
- name: Get EC2 Instance ID by Tag
28-
id: get_instance
29-
run: |
30-
INSTANCE_ID=$(aws ec2 describe-instances \
31-
--filters "Name=tag:Name,Values=${{ secrets.EC2_INSTANCE_NAME_TAG }}" \
32-
"Name=instance-state-name,Values=running" \
33-
--query "Reservations[].Instances[].InstanceId" \
34-
--output text)
35-
echo "INSTANCE_ID=$INSTANCE_ID" >> $GITHUB_ENV
36-
echo "Found instance: $INSTANCE_ID"
23+
- name: Get EC2 Instance ID by Tag
24+
id: ec2
25+
run: |
26+
INSTANCE_ID=$(aws ec2 describe-instances \
27+
--filters "Name=tag:Name,Values=php-website" \
28+
--query "Reservations[].Instances[].InstanceId" \
29+
--output text)
30+
echo "INSTANCE_ID=$INSTANCE_ID" >> $GITHUB_ENV
3731
38-
- name: Send deployment command via SSM
39-
run: |
40-
aws ssm send-command \
41-
--instance-ids "$INSTANCE_ID" \
42-
--document-name "AWS-RunShellScript" \
43-
--comment "Deploy Yii2 App using Docker" \
44-
--parameters 'commands=["cd /home/ubuntu/app", "git pull origin master", "docker compose down", "docker compose up --build -d"]' \
45-
--region $AWS_REGION \
46-
--output text
32+
- name: Send Deployment Command to EC2 via SSM
33+
run: |
34+
aws ssm send-command \
35+
--instance-ids "$INSTANCE_ID" \
36+
--document-name "AWS-RunShellScript" \
37+
--comment "Deploy Yii2 App using Docker" \
38+
--parameters 'commands=["cd /home/ubuntu/app","git pull origin master","docker compose down","docker compose up --build -d"]' \
39+
--output text

0 commit comments

Comments
 (0)