Skip to content

Commit c3a8c97

Browse files
committed
Automate Azure VM deployment using GitHub Actions; add deployment steps and health check for improved CI/CD process.
1 parent 25c6bc9 commit c3a8c97

1 file changed

Lines changed: 45 additions & 4 deletions

File tree

week7/Docker Compose & Azure+VM.md

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,48 @@ In this example we **Defined a `docker-compose.yml` file** with a basic multi-se
139139
The application is now running on the Azure VM, accessible from the public IP on port 3000, and can be managed using Docker Compose.
140140

141141

142-
# Deploy to Azure VM via CI/CD
143-
144-
insted of manuly we can use automte tool like github action
145-
142+
# Deploy to Azure VM via CI/CD
143+
144+
Instead of deploying manually, we automated the deployment process using GitHub Actions. This allows us to build, test, and deploy our application to the Azure VM automatically whenever changes are pushed to the repository.
145+
146+
147+
**Key parts of the deploy job:**
148+
149+
```yaml
150+
deploy:
151+
needs: e2e
152+
runs-on: ubuntu-latest
153+
154+
steps:
155+
- name: Checkout code
156+
uses: actions/checkout@v4
157+
158+
- name: Set up SSH key
159+
run: |
160+
mkdir -p ~/.ssh
161+
echo "${{ secrets.AZURE_VM_KEY }}" > ~/.ssh/myDockerVM_key.pem
162+
chmod 600 ~/.ssh/myDockerVM_key.pem
163+
164+
- name: Copy files to Azure VM (excluding frontend)
165+
run: |
166+
rsync -av --exclude=frontend -e "ssh -i ~/.ssh/myDockerVM_key.pem -o StrictHostKeyChecking=no" week7/ ${{ secrets.AZURE_VM_USER }}@${{ secrets.AZURE_VM_HOST }}:~/week7/
167+
168+
- name: Deploy with Docker Compose on Azure VM
169+
run: |
170+
ssh -i ~/.ssh/myDockerVM_key.pem -o StrictHostKeyChecking=no ${{ secrets.AZURE_VM_USER }}@${{ secrets.AZURE_VM_HOST }} '
171+
cd ~/week7 && docker-compose up --build -d
172+
'
173+
174+
- name: Check service health on Azure VM
175+
run: |
176+
ssh -i ~/.ssh/myDockerVM_key.pem -o StrictHostKeyChecking=no ${{ secrets.AZURE_VM_USER }}@${{ secrets.AZURE_VM_HOST }} '
177+
curl -f http://localhost:3000/health
178+
'
179+
180+
- name: Shut down containers on Azure VM
181+
if: always()
182+
run: |
183+
ssh -i ~/.ssh/myDockerVM_key.pem -o StrictHostKeyChecking=no ${{ secrets.AZURE_VM_USER }}@${{ secrets.AZURE_VM_HOST }} '
184+
cd ~/week7 && docker-compose down --volumes
185+
'
186+
```

0 commit comments

Comments
 (0)