Skip to content

Commit 1ad2f9f

Browse files
authored
Update deploy.yml
1 parent 135e180 commit 1ad2f9f

1 file changed

Lines changed: 18 additions & 4 deletions

File tree

.github/workflows/deploy.yml

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Checkout code
1414
uses: actions/checkout@v3
1515

16-
- name: Create SSH key from secret
16+
- name: Create SSH key to connect to EC2
1717
run: |
1818
echo "${{ secrets.EC2_SSH_KEY }}" | base64 -d > ec2_key.pem
1919
chmod 400 ec2_key.pem
@@ -25,7 +25,21 @@ jobs:
2525
username: ${{ secrets.EC2_USERNAME }}
2626
key_path: ec2_key.pem
2727
script: |
28+
# Create deploy key on EC2 for private repo access
29+
echo "${{ secrets.DEPLOY_KEY }}" | base64 -d > ~/.ssh/deploy-key
30+
chmod 600 ~/.ssh/deploy-key
31+
eval "$(ssh-agent -s)"
32+
ssh-add ~/.ssh/deploy-key
33+
34+
# Clone repo if not exists, otherwise pull
35+
if [ ! -d "/home/ubuntu/skribble-app/.git" ]; then
36+
git clone git@github.com:YOUR_USERNAME/YOUR_REPO_NAME.git /home/ubuntu/skribble-app
37+
else
38+
cd /home/ubuntu/skribble-app
39+
git pull origin main
40+
fi
41+
42+
# Run docker compose
2843
cd /home/ubuntu/skribble-app
29-
git pull origin main
30-
docker-compose down
31-
docker-compose up -d --build
44+
docker compose down
45+
docker compose up -d --build

0 commit comments

Comments
 (0)