Skip to content

Commit 3178d39

Browse files
committed
Refactor CI workflow and update documentation for Azure VM deployment; remove emoji from step names, enhance clarity, and add detailed deployment instructions.
1 parent fe5fc67 commit 3178d39

File tree

2 files changed

+106
-9
lines changed

2 files changed

+106
-9
lines changed

.github/workflows/ci_week7.yml

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@ jobs:
1010
runs-on: ubuntu-latest
1111

1212
steps:
13-
- name: 📥 Checkout code
13+
- name: Checkout code
1414
uses: actions/checkout@v4
1515

16-
- name: 🔧 Build Docker containers
16+
- name: Build Docker containers
1717
run: docker compose build
1818
working-directory: week7
1919

20-
- name: 🚀 Start containers
20+
- name: Start containers
2121
run: docker compose up -d
2222
working-directory: week7
2323

24-
- name: 💤 Wait for DB healthcheck
24+
- name: Wait for DB healthcheck
2525
run: |
2626
timeout=30
2727
for i in $(seq 1 $timeout); do
@@ -32,7 +32,7 @@ jobs:
3232
done
3333
working-directory: week7
3434

35-
- name: 💤 Wait for backend to become healthy
35+
- name: Wait for backend to become healthy
3636
run: |
3737
timeout=30
3838
for i in $(seq 1 $timeout); do
@@ -43,25 +43,55 @@ jobs:
4343
done
4444
working-directory: week7
4545

46-
- name: 🧪 Test API endpoints
46+
- name: Test API endpoints
4747
run: |
4848
curl --fail http://localhost:3000/health
4949
curl --fail http://localhost:3000/api/users
5050
working-directory: week7
5151

52-
- name: 📜 Capture logs on failure
52+
- name: Capture logs on failure
5353
if: failure()
5454
run: docker compose logs > full_logs.txt
5555
working-directory: week7
5656

57-
- name: 📤 Upload logs
57+
- name: Upload logs
5858
if: always()
5959
uses: actions/upload-artifact@v4
6060
with:
6161
name: docker-compose-logs
6262
path: week7/full_logs.txt
6363

64-
- name: 🧹 Shut down containers
64+
- name: Shut down containers
6565
if: always()
6666
run: docker compose down --volumes
6767
working-directory: week7
68+
69+
70+
deploy:
71+
needs: e2e
72+
runs-on: ubuntu-latest
73+
74+
steps:
75+
- name: Checkout code
76+
uses: actions/checkout@v4
77+
78+
- name: Set up SSH key
79+
run: |
80+
mkdir -p ~/.ssh
81+
echo "${{ secrets.AZURE_VM_KEY }}" > ~/.ssh/myDockerVM_key.pem
82+
chmod 600 ~/.ssh/myDockerVM_key.pem
83+
84+
- name: Copy files to Azure VM (excluding frontend)
85+
run: |
86+
rsync -av --exclude=frontend -e "ssh -i ~/.ssh/myDockerVM_key.pem -o StrictHostKeyChecking=no" week7/ ${{ secrets.AZURE_VM_USER }}@${{ secrets.AZURE_VM_HOST }}:~/week7/
87+
88+
- name: Deploy with Docker Compose on Azure VM
89+
run: |
90+
ssh -i ~/.ssh/myDockerVM_key.pem -o StrictHostKeyChecking=no ${{ secrets.AZURE_VM_USER }}@${{ secrets.AZURE_VM_HOST }} "
91+
cd ~/week7 && docker-compose up --build -d
92+
"
93+
94+
- name: Check service health on Azure VM
95+
run: |
96+
ssh -i ~/.ssh/myDockerVM_key.pem -o StrictHostKeyChecking=no ${{ secrets.AZURE_VM_USER }}@${{ secrets.AZURE_VM_HOST }} "
97+
curl -f http://localhost:3000/health

week7/Docker Compose & Azure+VM.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,73 @@ In this example we **Defined a `docker-compose.yml` file** with a basic multi-se
7373
docker-compose logs backend
7474
```
7575

76+
# Azure VM Setup and Manual Deployment
7677

78+
1. **Created an Azure Virtual Machine (VM):**
79+
- Used the Azure Portal or Azure CLI to create a Linux VM (Ubuntu) with a public IP and an admin username (`azureuser`).
80+
- Downloaded the private SSH key (`myDockerVM_key.pem`) for secure access.
81+
- Store the key in ~/.ssh/ folder.
7782

83+
2. **Configured SSH Access:**
84+
- Set permissions on the key file using `chmod 600 ~/.ssh/myDockerVM_key.pem`.
85+
- Connected to the VM using:
86+
```bash
87+
ssh -i ~/.ssh/myDockerVM_key.pem azureuser@<vm-public-ip>
88+
```
89+
90+
3. **Installed Docker and Docker Compose on the VM:**
91+
- Updated the package list and installed Docker:
92+
```bash
93+
sudo apt-get update
94+
sudo apt-get install -y docker.io
95+
sudo systemctl enable --now docker
96+
sudo usermod -aG docker $USER
97+
```
98+
- Installed Docker Compose:
99+
```bash
100+
sudo apt-get install -y docker-compose
101+
```
102+
- Logged out and back in (or used `newgrp docker`) to apply Docker group permissions.
103+
104+
4. **Deployed the Application:**
105+
- Copied the application files (excluding the `frontend` folder) from the local machine to the VM using `rsync`:
106+
```bash
107+
rsync -av --exclude=frontend -e "ssh -i ~/.ssh/myDockerVM_key.pem" /home/yosef/Documents/github/DevOps-Linux/DevOps-Linux/week7/ azureuser@<vm-public-ip>:~/week7/
108+
```
109+
- Navigated to the app directory on the VM:
110+
```bash
111+
cd ~/week7
112+
```
113+
114+
5. **Started the Application with Docker Compose:**
115+
- Built and started the containers:
116+
```bash
117+
docker-compose up --build -d
118+
```
119+
- Verified that the containers are running:
120+
```bash
121+
docker-compose ps
122+
```
123+
124+
6. **Exposed the Application on a Public Port:**
125+
- Ensured port 3000 was open in Azure Network Security Group settings.
126+
- Accessed the running application from a browser or with `curl`:
127+
```
128+
http://<vm-public-ip>:3000
129+
```
130+
131+
7. **Tested the API:**
132+
- Used `curl` to test the health endpoint and add users:
133+
```bash
134+
curl http://localhost:3000/health
135+
curl -X POST http://localhost:3000/api/users -H "Content-Type: application/json" -d '{"name": "Alice", "email": "alice@example.com"}'
136+
```
137+
138+
**Result:**
139+
The application is now running on the Azure VM, accessible from the public IP on port 3000, and can be managed using Docker Compose.
140+
141+
142+
# Deploy to Azure VM via CI/CD
78143

144+
insted of manuly we can use automte tool like github action
145+

0 commit comments

Comments
 (0)