-
Notifications
You must be signed in to change notification settings - Fork 0
152 lines (119 loc) · 3.92 KB
/
master-deploy.yaml
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
name: Production-Pipeline-Dockerhub
on:
push:
branches:
- master
pull_request:
branches:
- master
env:
IMAGE_NAME: auth_converter
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
DOCKER_HUB_TOKEN: ${{ secrets.DOCKER_HUB_TOKEN }}
DATABASE_URL: ${{vars.TEST_DATABASE_URL}}
TEST_DATABASE_URL: ${{vars.TEST_DATABASE_URL}}
SECRET_KEY: ""
ALGORITHM: ${{ secrets.ALGORITHM }}
ACCESS_TOKEN_EXPIRE_MINUTES: 30
POSTGRES_USER: ""
POSTGRES_PASSWORD: ""
POSTGRES_DB: ""
PAGE: "1"
PAGE_SIZE: "10"
ORDERING: "-created_at"
jobs:
build-and-test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres
env:
POSTGRES_DB: ${{vars.TEST_POSTGRES_DB}}
POSTGRES_PASSWORD: ${{vars.TEST_POSTGRES_PASSWORD}}
POSTGRES_USER: ${{vars.TEST_POSTGRES_USER}}
ports:
- 5433:5432
steps:
- name: Cloning the Repository
uses: actions/checkout@v3
- name: Set up Python 3.11
uses: actions/setup-python@v3
with:
python-version: "3.11.1"
- name: Install Poetry
run: pipx install poetry
- name: Install Dependencies
run: poetry install
- name: Run tests
run: poetry run task test
- name: Checkout code
uses: actions/checkout@v2
push-to-dockerhub:
runs-on: ubuntu-latest
needs: build-and-test
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v3
with:
python-version: "3.11.1"
- name: Install Poetry
run: pipx install poetry
- name: Get Version from pyproject.toml
id: get-version
run: |
VERSION=$(poetry version --short)
echo "VERSION=${VERSION}" >> $GITHUB_ENV
echo "::set-output name=version::${VERSION}"
- name: Build Docker Image
id: build-image
env:
IMAGE_NAME: ${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }}
VERSION: ${{ steps.get-version.outputs.version }}
run: |
docker build -t $IMAGE_NAME:latest -t $IMAGE_NAME:$VERSION .
- name: Docker Hub Login
run: echo "${{ secrets.DOCKER_HUB_TOKEN }}" | docker login -u "${{ secrets.DOCKER_HUB_USERNAME }}" --password-stdin
- name: docker images
run: docker images
- name: Tag and Push Docker Image to Docker Hub
run: |
docker push ${{ secrets.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }} --all-tags
Update-Image-Tag-in-Deployment:
runs-on: ubuntu-latest
needs: [build-and-test, push-to-dockerhub]
steps:
- name: Checkout Repository
uses: actions/checkout@v3
with:
token: ${{ secrets.ACCOUNT_MODIFY_TOKEN }}
fetch-depth: 0
- name: Install Poetry
run: pipx install poetry
- name: Get Version from pyproject.toml
id: get-version
run: |
VERSION=$(poetry version --short)
echo "NEW_IMAGE_TAG=${VERSION}" >> $GITHUB_ENV
echo "::set-output name=new_version::${VERSION}"
- name: Checkout GitOps Branch
run: |
git fetch origin
git checkout gitops
- name: Update Image Tag in Deployment
run: |
sed -i "s|image: ${{ env.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }}:.*|image: ${{ env.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ env.NEW_IMAGE_TAG }}|" k8s/deployment.yaml
- name: Check deployment.yaml after sed
run: cat k8s/deployment.yaml
- name: Git Status
run: git status
- name: Git Config
run: |
git config --global user.email "[email protected]"
git config --global user.name "CI Bot"
- name: Commit and Push Changes
run: |
git add k8s/deployment.yaml
git commit -m "Updating the image tag: ${{ env.NEW_IMAGE_TAG }}"
git push origin gitops