Skip to content

Commit 9362ca6

Browse files
Created CI/CD github actions
1 parent 2699f2a commit 9362ca6

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

.github/workflows/main.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: CI/CD Pipeline
2+
3+
on:
4+
push:
5+
branches:
6+
- ms/Scrun-130-Project-Deployment-dockerfiles
7+
8+
jobs:
9+
test:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout Code
14+
uses: actions/checkout@v3
15+
16+
- name: Install Node.js
17+
uses: actions/setup-node@v3
18+
with:
19+
node-version: 18
20+
21+
- name: Install Dependencies
22+
run: npm install
23+
24+
- name: Run Tests
25+
run: npm test
26+
27+
deploy:
28+
needs: test
29+
runs-on: ubuntu-latest
30+
31+
steps:
32+
- name: Checkout Code
33+
uses: actions/checkout@v3
34+
35+
- name: Setup SSH Connection
36+
run: |
37+
echo "${{ secrets.GCP_SSH_PRIVATE_KEY }}" > private_key
38+
chmod 600 private_key
39+
40+
- name: Deploy to Google Cloud VM
41+
run: |
42+
ssh -i private_key -o StrictHostKeyChecking=no ${{ secrets.GCP_USERNAME }}@${{ secrets.GCP_VM_IP }} << 'EOF'
43+
cd /var/www/myapp || (mkdir -p /var/www/myapp && cd /var/www/myapp)
44+
git pull origin ms/Scrun-130-Project-Deployment-dockerfiles
45+
docker-compose down
46+
docker-compose build
47+
docker-compose up -d --remove-orphans
48+
EOF

0 commit comments

Comments
 (0)