forked from inno-devops-labs/DevOps-Core-Course
-
Notifications
You must be signed in to change notification settings - Fork 1
127 lines (107 loc) · 3.42 KB
/
app_python.yml
File metadata and controls
127 lines (107 loc) · 3.42 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
124
125
126
127
name: CI for app_python
on:
push:
paths:
- 'app_python/**'
- '.github/workflows/app_python.yml'
pull_request:
paths:
- 'app_python/**'
- '.github/workflows/app_python.yml'
defaults:
run:
working-directory: app_python
jobs:
lint_and_format:
timeout-minutes: 2
runs-on: ubuntu-22.04
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.13'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pylint
- name: Run code formatter (black)
uses: psf/black@stable
with:
options: "--check --diff"
src: "./app_python"
- name: Run linter (pylint)
run: pylint app.py --disable=R,C
test:
timeout-minutes: 2
runs-on: ubuntu-22.04
needs: lint_and_format
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.13'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install pytest requests
- name: Run tests
run: pytest test_app.py
security_scan:
timeout-minutes: 5
runs-on: ubuntu-22.04
needs: [lint_and_format, test]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Run Snyk to check for vulnerabilities
uses: snyk/actions/python-3.10@master
with:
args: --skip-unresolved app_python/
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
docker_build_and_push:
timeout-minutes: 10
runs-on: ubuntu-22.04
needs: [lint_and_format, test, security_scan]
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get short commit hash
id: commit
run: echo "SHORT_COMMIT_HASH=$(echo ${GITHUB_SHA} | cut -c1-7)" >> $GITHUB_ENV
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
driver: docker-container
platforms: linux/amd64,linux/arm64,linux/arm/v7
- name: Log in to GitHub Container Registry
uses: docker/login-action@v3
with:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
registry: ghcr.io
- name: Log in to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
registry: docker.io
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: "{{defaultContext}}:app_python"
push: true
tags: |
ghcr.io/${{ github.repository_owner }}/moscow-time:${{ env.SHORT_COMMIT_HASH }}
${{ secrets.DOCKERHUB_USERNAME }}/moscow-time:${{ env.SHORT_COMMIT_HASH }}
platforms: linux/amd64,linux/arm64,linux/arm/v7
cache-from: type=gha,type=registry,ref=ghcr.io/${{ github.repository_owner }}/moscow-time:buildcache
cache-to: type=gha,mode=max,type=registry,ref=ghcr.io/${{ github.repository_owner }}/moscow-time:buildcache,mode=max