Skip to content

Commit bc25c86

Browse files
authored
Optimize CI/CD pipeline architecture (#434)
1 parent 851c4c8 commit bc25c86

File tree

12 files changed

+337
-188
lines changed

12 files changed

+337
-188
lines changed

.github/workflows/cd.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: cd
2+
3+
on:
4+
pull_request:
5+
types: [ opened, synchronize, reopened ]
6+
7+
jobs:
8+
deploy:
9+
if: github.event.pull_request.state == 'open' && github.event.pull_request.draft == false
10+
runs-on: ubuntu-latest
11+
concurrency:
12+
group: cd-preview-${{ github.event.pull_request.head.ref }}
13+
cancel-in-progress: true
14+
steps:
15+
- name: Checkout app
16+
uses: actions/checkout@v3
17+
with:
18+
path: app
19+
20+
- name: Checkout github-ci
21+
uses: actions/checkout@v3
22+
with:
23+
repository: jalantechnologies/github-ci
24+
path: platform
25+
ref: v3.2.5
26+
27+
- name: Extract branch name
28+
id: extract_branch
29+
run: |
30+
BRANCH_NAME=$(echo ${{ github.event.pull_request.head.ref }} | sed -e 's/^refs\/heads\///g')
31+
BRANCH_HASH=$(sha1sum < <(printf '%s' $BRANCH_NAME) | cut -c -15)
32+
echo "branch_hash=$(echo $BRANCH_HASH)" >> $GITHUB_OUTPUT
33+
34+
- name: Build Docker image
35+
id: build
36+
uses: ./platform/.github/actions/build
37+
with:
38+
app_name: flask-react-template
39+
tag: ${{ steps.extract_branch.outputs.branch_hash }}
40+
build_args: APP_ENV=preview
41+
context: app/.
42+
docker_registry: ${{ vars.DOCKER_REGISTRY }}
43+
docker_username: ${{ vars.DOCKER_USERNAME }}
44+
docker_password: ${{ secrets.DOCKER_PASSWORD }}
45+
46+
- name: Deploy to preview
47+
uses: ./platform/.github/actions/deploy
48+
with:
49+
app_name: flask-react-template
50+
app_env: preview
51+
app_hostname: '{1}.preview.platform.bettrhq.com'
52+
branch: ${{ github.event.pull_request.head.ref }}
53+
deploy_id: ${{ github.run_number }}
54+
deploy_root: app/lib/kube
55+
deploy_labels: gh/pr=${{ github.event.number }}
56+
deploy_image: ${{ steps.build.outputs.image_ref }}
57+
docker_registry: ${{ vars.DOCKER_REGISTRY }}
58+
docker_username: ${{ vars.DOCKER_USERNAME }}
59+
docker_password: ${{ secrets.DOCKER_PASSWORD }}
60+
do_access_token: ${{ secrets.DO_ACCESS_TOKEN }}
61+
do_cluster_id: ${{ vars.DO_CLUSTER_ID }}
62+
doppler_token: ${{ secrets.DOPPLER_PREVIEW_TOKEN }}

.github/workflows/ci.yml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: ci
2+
3+
on:
4+
pull_request:
5+
types: [ opened, synchronize, reopened ]
6+
7+
jobs:
8+
lint:
9+
if: github.event.pull_request.draft == false
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout code
13+
uses: actions/checkout@v4
14+
15+
- name: Setup Python
16+
uses: actions/setup-python@v5
17+
with:
18+
python-version: '3.11'
19+
20+
- name: Setup Node.js
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: '22.13.1'
24+
cache: 'npm'
25+
26+
- name: Install pipenv
27+
run: pip install pipenv
28+
29+
- name: Install Python dependencies
30+
run: pipenv install --dev --deploy
31+
32+
- name: Install Node dependencies
33+
run: npm ci
34+
35+
- name: Run linting
36+
run: npm run lint
37+
38+
sonarqube:
39+
if: github.event.pull_request.draft == false
40+
runs-on: ubuntu-latest
41+
steps:
42+
- name: Checkout
43+
uses: actions/checkout@v3
44+
with:
45+
fetch-depth: 0
46+
47+
- name: Get github-ci version
48+
id: ci_version
49+
run: |
50+
# Extract version from cd.yml workflow
51+
workflow_yaml=$(cat .github/workflows/cd.yml)
52+
uses_data=$(echo "$workflow_yaml" | grep 'jalantechnologies/github-ci')
53+
tag=$(echo $uses_data | sed -n 's/.*@\(.*\)/\1/p')
54+
echo "version=$(echo $tag)" >> $GITHUB_OUTPUT
55+
56+
- name: Checkout github-ci
57+
uses: actions/checkout@v3
58+
with:
59+
repository: jalantechnologies/github-ci
60+
path: platform
61+
ref: ${{ steps.ci_version.outputs.version }}
62+
63+
- name: Run SonarQube analysis
64+
uses: ./platform/.github/actions/analyze
65+
with:
66+
sonar_host_url: ${{ vars.SONAR_HOST_URL }}
67+
sonar_token: ${{ secrets.SONAR_TOKEN }}
68+
branch: ${{ github.head_ref }}
69+
branch_base: main
70+
pull_request_number: ${{ github.event.number }}
71+
72+
review:
73+
if: github.event.pull_request.draft == false
74+
runs-on: ubuntu-latest
75+
steps:
76+
- name: Placeholder for code review
77+
run: |
78+
echo "Code review placeholder"
79+
echo "Future implementation: AI-powered review for architecture, security, and best practices"
80+
81+
test:
82+
if: github.event.pull_request.draft == false
83+
runs-on: ubuntu-latest
84+
steps:
85+
- name: Checkout code
86+
uses: actions/checkout@v4
87+
88+
- name: Run integration tests
89+
run: docker compose -f docker-compose.test.yml up --exit-code-from app
90+
91+
- name: Coverage report
92+
continue-on-error: true
93+
uses: irongut/[email protected]
94+
with:
95+
filename: output/coverage.xml
96+
badge: true
97+
fail_below_min: true
98+
format: markdown
99+
hide_branch_rate: false
100+
hide_complexity: true
101+
indicators: true
102+
output: both
103+
thresholds: '60 80'
104+
105+
- name: Add coverage PR comment
106+
continue-on-error: true
107+
uses: marocchino/sticky-pull-request-comment@v2
108+
with:
109+
recreate: true
110+
path: code-coverage-results.md

.github/workflows/clean_on_pr_closed.yml renamed to .github/workflows/clean.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: clean_on_pr_closed
1+
name: clean
22

33
on:
44
pull_request_target:
@@ -11,8 +11,8 @@ jobs:
1111
group: ci-preview-${{ github.event.pull_request.head.ref }}
1212
cancel-in-progress: true
1313
with:
14-
hosting_provider: ${{ vars.HOSTING_PROVIDER }} # 'DIGITAL_OCEAN' or 'AWS'
15-
app_name: flask-react-app
14+
hosting_provider: ${{ vars.HOSTING_PROVIDER }}
15+
app_name: flask-react-template
1616
app_env: preview
1717
branch: ${{ github.event.pull_request.head.ref }}
1818
docker_registry: ${{ vars.DOCKER_REGISTRY }}

.github/workflows/clean_on_delete.yml

Lines changed: 0 additions & 27 deletions
This file was deleted.

.github/workflows/clean_on_dispatch.yml

Lines changed: 0 additions & 25 deletions
This file was deleted.
Lines changed: 45 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,54 @@
1-
name: permanent_preview
1+
name: cd_permanent_preview
22

33
on:
44
push:
55
branches:
66
- main
77

88
jobs:
9-
permanent_preview:
10-
uses: jalantechnologies/github-ci/.github/workflows/[email protected]
9+
deploy:
10+
runs-on: ubuntu-latest
1111
concurrency:
12-
group: ci-permanent-preview
12+
group: cd-permanent-preview
1313
cancel-in-progress: true
14-
with:
15-
hosting_provider: ${{ vars.HOSTING_PROVIDER }} # 'DIGITAL_OCEAN' or 'AWS'
16-
app_name: flask-react-app
17-
app_env: preview
18-
app_hostname: preview.flask-react-template.platform.bettrhq.com
19-
branch: main
20-
checks: "['npm:coverage', 'npm:lint', 'compose:test']"
21-
docker_registry: ${{ vars.DOCKER_REGISTRY }}
22-
docker_username: ${{ vars.DOCKER_USERNAME }}
23-
aws_cluster_name: ${{ vars.AWS_CLUSTER_NAME }}
24-
aws_region: ${{ vars.AWS_REGION }}
25-
sonar_host_url: ${{ vars.SONAR_HOST_URL }}
26-
do_cluster_id: ${{ vars.DO_CLUSTER_ID }}
27-
secrets:
28-
docker_password: ${{ secrets.DOCKER_PASSWORD }}
29-
doppler_token: ${{ secrets.DOPPLER_PREVIEW_TOKEN }}
30-
aws_access_key_id: ${{ secrets.AWS_ACCESS_KEY_ID }}
31-
aws_secret_access_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
32-
do_access_token: ${{ secrets.DO_ACCESS_TOKEN }}
33-
sonar_token: ${{ secrets.SONAR_TOKEN }}
14+
steps:
15+
- name: Checkout app
16+
uses: actions/checkout@v3
17+
with:
18+
path: app
19+
20+
- name: Checkout github-ci
21+
uses: actions/checkout@v3
22+
with:
23+
repository: jalantechnologies/github-ci
24+
path: platform
25+
ref: v3.2.5
26+
27+
- name: Build Docker image
28+
id: build
29+
uses: ./platform/.github/actions/build
30+
with:
31+
app_name: flask-react-template
32+
tag: preview
33+
context: app/.
34+
docker_registry: ${{ vars.DOCKER_REGISTRY }}
35+
docker_username: ${{ vars.DOCKER_USERNAME }}
36+
docker_password: ${{ secrets.DOCKER_PASSWORD }}
37+
38+
- name: Deploy to permanent preview
39+
uses: ./platform/.github/actions/deploy
40+
with:
41+
app_name: flask-react-template
42+
app_env: preview
43+
app_hostname: preview.flask-react-template.platform.bettrhq.com
44+
branch: main
45+
deploy_id: ${{ github.run_number }}
46+
deploy_root: app/lib/kube
47+
deploy_labels: gh/env=preview
48+
deploy_image: ${{ steps.build.outputs.image_ref }}
49+
docker_registry: ${{ vars.DOCKER_REGISTRY }}
50+
docker_username: ${{ vars.DOCKER_USERNAME }}
51+
docker_password: ${{ secrets.DOCKER_PASSWORD }}
52+
do_access_token: ${{ secrets.DO_ACCESS_TOKEN }}
53+
do_cluster_id: ${{ vars.DO_CLUSTER_ID }}
54+
doppler_token: ${{ secrets.DOPPLER_PREVIEW_TOKEN }}

.github/workflows/preview_on_dispatch.yml

Lines changed: 0 additions & 30 deletions
This file was deleted.

.github/workflows/preview_on_pr_update.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.

0 commit comments

Comments
 (0)