-
Notifications
You must be signed in to change notification settings - Fork 0
159 lines (138 loc) · 4.79 KB
/
ci-cd.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
153
154
155
156
157
158
159
name: "CI/CD Workflow"
on:
push:
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
django-lint:
name: Django linting
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v3.1.2
with:
python-version: 3.10.10
- name: Linting
run: bash bin/cleanup_pre_commit.sh
create-docker-test-image-and-test:
name: Create Docker test image and testing
runs-on: ubuntu-latest
needs: django-lint
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Build Docker test image
run: docker compose -f docker-compose.test.yaml build
- name: Create Docker network
run: docker network create planr_network
- name: Start Docker Containers
run: docker compose -f docker-compose.test.yaml up -d
- name: Run Tests
run: docker compose -f docker-compose.test.yaml run app python manage.py test
build-and-push-docker-image:
name: Build and push Docker image
if: github.ref == 'refs/heads/develop'
runs-on: ubuntu-latest
needs: create-docker-test-image-and-test
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v2
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Get current date
id: get_date
run: echo "::set-output name=DATE::$(date +'%d-%m-%Y-%H-%M-%S')"
- name: Log in to the Container registry
uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta_app
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-app
tags: |
type=raw,develop
type=raw,test
- name: Extract metadata (tags, labels) for Docker nginx
id: meta_nginx
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}-nginx
tags: |
type=raw,develop
type=raw,test
- name: Build and push app Docker image
uses: docker/build-push-action@v3
with:
context: "{{defaultContext}}:app"
push: true
tags: ${{ steps.meta_app.outputs.tags }}
labels: ${{ steps.meta_app.outputs.labels }}
build-args: |
GIT_SHA=${{ github.sha }}
DEPLOY_DATE=${{ steps.get_date.outputs.DATE }}
- name: Build and push nginx Docker image
uses: docker/build-push-action@v3
with:
context: "{{defaultContext}}:nginx"
push: true
tags: ${{ steps.meta_nginx.outputs.tags }}
labels: ${{ steps.meta_nginx.outputs.labels }}
deploy-acc:
name: Acceptance release
if: github.ref == 'refs/heads/develop'
needs: build-and-push-docker-image
runs-on: ubuntu-latest
environment: acc
permissions:
contents: read
packages: write
steps:
- name: Start rollout on k8s platform
uses: actions-hub/kubectl@master
env:
KUBE_HOST: ${{ vars.KUBE_HOST }}
KUBE_CERTIFICATE: ${{ vars.KUBE_CERTIFICATE }}
KUBE_TOKEN: ${{ secrets.KUBE_TOKEN }}
with:
args: rollout restart deployment/app deployment/worker --namespace=${{ vars.KUBE_NAMESPACE }}
- name: Status rollout on k8s platform
uses: actions-hub/kubectl@master
env:
KUBE_HOST: ${{ vars.KUBE_HOST }}
KUBE_CERTIFICATE: ${{ vars.KUBE_CERTIFICATE }}
KUBE_TOKEN: ${{ secrets.KUBE_TOKEN }}
with:
args: rollout status deployment/app --namespace=${{ vars.KUBE_NAMESPACE }}
deploy-test:
name: Test release
if: github.ref == 'refs/heads/develop'
needs: build-and-push-docker-image
runs-on: ubuntu-latest
environment: test
permissions:
contents: read
packages: write
steps:
- name: Start rollout on k8s platform
uses: actions-hub/kubectl@master
env:
KUBE_HOST: ${{ vars.KUBE_HOST }}
KUBE_CERTIFICATE: ${{ vars.KUBE_CERTIFICATE }}
KUBE_TOKEN: ${{ secrets.KUBE_TOKEN }}
with:
args: rollout restart deployment/app deployment/worker --namespace=${{ vars.KUBE_NAMESPACE }}
- name: Status rollout on k8s platform
uses: actions-hub/kubectl@master
env:
KUBE_HOST: ${{ vars.KUBE_HOST }}
KUBE_CERTIFICATE: ${{ vars.KUBE_CERTIFICATE }}
KUBE_TOKEN: ${{ secrets.KUBE_TOKEN }}
with:
args: rollout status deployment/app --namespace=${{ vars.KUBE_NAMESPACE }}