-
Notifications
You must be signed in to change notification settings - Fork 26
123 lines (108 loc) · 3.59 KB
/
Copy pathPipelineRC.yml
File metadata and controls
123 lines (108 loc) · 3.59 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
name: Pipeline RC
on:
push:
branches:
- develop
tags:
- '*'
pull_request:
branches:
- develop
jobs:
# Job 1: Run Tests
run-tests:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
# Install a specific version of uv.
version: "0.6.13"
enable-cache: true
cache-dependency-glob: "uv.lock"
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version-file: "pyproject.toml"
- name: Run tests with coverage
run: |
export UV_PROJECT_ENVIRONMENT="${pythonLocation}"
uv sync --only-dev
export ROOT_DIR=${GITHUB_WORKSPACE}/
export DJANGO_SECRET_KEY="test_key"
export DEBUG_TOOLBAR="True"
uv run pytest src/core src/users/ src/blog --cov=src --cov-report=xml
- name: Upload coverage report
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage.xml
# Job 2: SonarQube Analysis
sonar-analysis:
runs-on: ubuntu-latest
needs: run-tests
if: github.event_name == 'push' # Only run on pushes
environment: develop
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
- name: Download coverage report
uses: actions/download-artifact@v4
with:
name: coverage-report
- name: Run SonarQube Scanner
uses: sonarsource/sonarqube-scan-action@v6
with:
projectBaseDir: .
args: >
-Dsonar.projectKey=${{ vars.SONAR_PROJECT_KEY }}
-Dsonar.organization=${{ vars.SONAR_ORGANIZATION }}
-Dsonar.host.url=${{ vars.SONAR_HOST_URL }}
-Dsonar.token=${{ secrets.SONAR_TOKEN }}
# Job 3: Build and Deploy
build-and-deploy:
runs-on: ubuntu-latest
needs: [run-tests, sonar-analysis]
if: github.event_name == 'push' # Only run on pushes
environment: develop
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USER }}
password: ${{ secrets.DOCKER_HUB_PASS }}
- name: Build and push for develop branch
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: jandigarte/django:dev
target: base
cache-from: type=registry,ref=jandigarte/django:dev
- name: Build and push for tags
if: startsWith(github.ref, 'refs/tags/')
uses: docker/build-push-action@v4
with:
context: .
push: true
tags: jandigarte/django:${{ github.ref_name }}
target: base
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ vars.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ vars.AWS_REGION }}
- name: Update ECS service
run: |
echo "Deploying to Development environment"
echo "ECS Cluster: ${{ env.ECS_CLUSTER }}"
echo "ECS Service: ${{ env.ECS_SERVICE }}"
aws ecs update-service --cluster ${{ vars.ECS_CLUSTER }} --service ${{ vars.ECS_SERVICE }} --force-new-deployment