-
Notifications
You must be signed in to change notification settings - Fork 6
105 lines (86 loc) · 2.81 KB
/
ci-pipeline.yaml
File metadata and controls
105 lines (86 loc) · 2.81 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
name: REST-API-CI-Pipeline
on:
push:
branches:
- dev
- main
paths:
- 'app/**'
pull_request:
branches:
- dev
- main
paths:
- 'app/**'
workflow_dispatch:
jobs:
build:
runs-on: self-hosted
outputs:
image_tag: ${{ steps.build-image.outputs.image_tag }}
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.12'
- name: Install Dependencies
run: |
cd app
python3 -m pip install --upgrade pip
pip install -r requirements.txt
- name: Run Tests with SQLite
run: |
pytest -v
- name: Build Docker Image
id: build-image
run: |
cd app
IMAGE_TAG=${GITHUB_SHA::7}
echo "IMAGE_TAG=$IMAGE_TAG" >> $GITHUB_ENV
echo "image_tag=$IMAGE_TAG" >> $GITHUB_OUTPUT
docker build -t flask-app:$IMAGE_TAG .
- name: Login to Docker Hub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
- name: Push Docker Image to Docker Hub
run: |
docker tag flask-app:$IMAGE_TAG ${{ secrets.DOCKER_HUB_USERNAME }}/flask-app:$IMAGE_TAG
docker push ${{ secrets.DOCKER_HUB_USERNAME }}/flask-app:$IMAGE_TAG
- name: Cleanup Local Docker Images
run: |
docker rmi flask-app:$IMAGE_TAG || true
docker rmi ${{ secrets.DOCKER_HUB_USERNAME }}/flask-app:$IMAGE_TAG || true
docker system prune -f || true
update-helm:
needs: build
runs-on: self-hosted
env:
IMAGE_TAG: ${{ needs.build.outputs.image_tag }}
steps:
- name: Checkout Helm Charts
uses: actions/checkout@v3
- name: Configure Git
run: |
git config --global user.name "akhil27051999"
git config --global user.email "thyadiakhil@gmail.com"
- name: Ensure main branch is up to date
run: git pull origin main
- name: Install yq
run: |
sudo apt-get update -y
sudo apt-get install -y yq
- name: Update Helm Chart with New Image Tag
run: |
echo "Updating image tag to $IMAGE_TAG..."
yq e -i '.app.image.tag = strenv(IMAGE_TAG)' ./helm/application/values.yaml
echo "Updated Helm values.yaml:"
cat ./helm/application/values.yaml
- name: Commit and Push Changes
run: |
git add ./helm/application/values.yaml
git commit -m "Update Flask App image tag to $IMAGE_TAG" || echo "No changes to commit"
git push https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}.git main