-
Notifications
You must be signed in to change notification settings - Fork 0
137 lines (115 loc) · 4.24 KB
/
ci-cd.yml
File metadata and controls
137 lines (115 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
name: CI/CD Pipeline
on:
push:
branches: [ main, master ]
pull_request:
branches: [ main, master ]
jobs:
test:
name: Run Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'
- name: Cache Python dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run Django migrations
run: |
python backend/manage.py migrate --noinput
- name: Run integration tests
run: |
python backend/manage.py test integration --verbosity=2
- name: Test report
if: always()
run: |
echo "✅ Integration tests completed"
build-backend:
name: Build Backend Docker Image
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build backend image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.backend
push: false
tags: spatial-explorer-backend:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
build-frontend:
name: Build Frontend Docker Image
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Build frontend image
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.frontend
push: false
tags: spatial-explorer-frontend:${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max
deploy:
name: Deploy Application
runs-on: ubuntu-latest
needs: [test, build-backend, build-frontend]
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Deploy notification
run: |
echo "🚀 Deployment triggered after successful tests"
echo "📦 Backend image: spatial-explorer-backend:${{ github.sha }}"
echo "📦 Frontend image: spatial-explorer-frontend:${{ github.sha }}"
echo ""
echo "To enable actual deployment to a cloud provider:"
echo "1. Add deployment secrets (RENDER_API_KEY, DOCKER_USERNAME, etc.)"
echo "2. Uncomment the deployment steps below"
echo "3. Configure your deployment target (Render, AWS, GCP, etc.)"
# Uncomment and configure for Render deployment:
# - name: Deploy to Render
# env:
# RENDER_API_KEY: ${{ secrets.RENDER_API_KEY }}
# run: |
# curl -X POST "https://api.render.com/v1/services/${{ secrets.RENDER_SERVICE_ID }}/deploys" \
# -H "Authorization: Bearer $RENDER_API_KEY" \
# -H "Content-Type: application/json"
# Uncomment and configure for Docker Hub push:
# - name: Login to Docker Hub
# uses: docker/login-action@v3
# with:
# username: ${{ secrets.DOCKER_USERNAME }}
# password: ${{ secrets.DOCKER_PASSWORD }}
#
# - name: Push images to Docker Hub
# run: |
# docker tag spatial-explorer-backend:${{ github.sha }} ${{ secrets.DOCKER_USERNAME }}/spatial-explorer-backend:latest
# docker tag spatial-explorer-frontend:${{ github.sha }} ${{ secrets.DOCKER_USERNAME }}/spatial-explorer-frontend:latest
# docker push ${{ secrets.DOCKER_USERNAME }}/spatial-explorer-backend:latest
# docker push ${{ secrets.DOCKER_USERNAME }}/spatial-explorer-frontend:latest