|
1 | | -# devops-pipeline-django-demo |
2 | | -Pipeline für Python Django Applications |
| 1 | +# pipeline-django-demo |
| 2 | + |
| 3 | +Beispiel einer Pipeline, die folgendes kann: |
| 4 | +- Outdated Check |
| 5 | +- Code Format mit `black` überprüfen |
| 6 | +- Sortierung der Imports mit `isort` überprüfen |
| 7 | +- Security Check mit `bandit` |
| 8 | +- Erstellung eines Docker Images |
| 9 | + |
| 10 | +Die Dependencies werden mit Renovate aktualisiert. Mehr Infos: https://github.com/renovatebot/renovate |
| 11 | + |
| 12 | +> **Hinweis**: |
| 13 | +> - `pip list --outdated` endet unabhängig vom Ergebnis immer mit Exit Code `0`, damit die Pipeline entsprechend reagiert wurde der Befehl erweitert. |
| 14 | +
|
| 15 | +``` |
| 16 | +name: Django Pipeline |
| 17 | +
|
| 18 | +on: |
| 19 | + pull_request: |
| 20 | + branches: '**' |
| 21 | + push: |
| 22 | + branches: |
| 23 | + - develop |
| 24 | + schedule: |
| 25 | + - cron: '0 20 * * 5' |
| 26 | +
|
| 27 | +jobs: |
| 28 | + outdated: |
| 29 | + runs-on: ubuntu-latest |
| 30 | + if: startsWith(github.head_ref, 'renovate') == false |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@v2 |
| 33 | + - uses: actions/setup-python@v2 |
| 34 | + with: |
| 35 | + python-version: 3.8.2 |
| 36 | +
|
| 37 | + - name: pip install |
| 38 | + run: pip install -r requirements.txt --user |
| 39 | +
|
| 40 | + - name: outdated |
| 41 | + run: pip list --outdated --not-required --user | grep . && echo "there are outdated packages" && exit 1 || echo "all packages up to date" |
| 42 | +
|
| 43 | + black: |
| 44 | + runs-on: ubuntu-latest |
| 45 | + steps: |
| 46 | + - uses: actions/checkout@v2 |
| 47 | + - uses: actions/setup-python@v2 |
| 48 | + with: |
| 49 | + python-version: 3.8.2 |
| 50 | +
|
| 51 | + - name: pip install |
| 52 | + run: pip install -r requirements.txt |
| 53 | +
|
| 54 | + - name: black |
| 55 | + run: black --check . |
| 56 | +
|
| 57 | + isort: |
| 58 | + runs-on: ubuntu-latest |
| 59 | + steps: |
| 60 | + - uses: actions/checkout@v2 |
| 61 | + - uses: actions/setup-python@v2 |
| 62 | + with: |
| 63 | + python-version: 3.8.2 |
| 64 | +
|
| 65 | + - name: pip install |
| 66 | + run: pip install -r requirements.txt |
| 67 | +
|
| 68 | + - name: isort |
| 69 | + run: isort **/*.py -c -vb |
| 70 | +
|
| 71 | + security: |
| 72 | + runs-on: ubuntu-latest |
| 73 | + steps: |
| 74 | + - uses: actions/checkout@v2 |
| 75 | + - uses: actions/setup-python@v2 |
| 76 | + with: |
| 77 | + python-version: 3.8.2 |
| 78 | +
|
| 79 | + - name: pip install bandit |
| 80 | + run: pip install bandit==1.6.2 |
| 81 | +
|
| 82 | + - name: bandit |
| 83 | + run: bandit -r **/*.py -f json -o report.json |
| 84 | +
|
| 85 | + - name: show report |
| 86 | + if: ${{ success() || failure() }} |
| 87 | + run: cat report.json |
| 88 | +
|
| 89 | + - name: upload report |
| 90 | + if: ${{ success() || failure() }} |
| 91 | + uses: actions/upload-artifact@v2 |
| 92 | + with: |
| 93 | + name: Bandit Security Report |
| 94 | + path: report.json |
| 95 | +
|
| 96 | + django_matrix: |
| 97 | + name: Python ${{ matrix.python-version }} / Django ${{ matrix.django-version}} |
| 98 | + runs-on: ubuntu-latest |
| 99 | + strategy: |
| 100 | + max-parallel: 4 |
| 101 | + matrix: |
| 102 | + python-version: [3.7, 3.8] |
| 103 | + django-version: ["~=2.2.0", "~=3.0.0"] |
| 104 | +
|
| 105 | + steps: |
| 106 | + - uses: actions/checkout@v2 |
| 107 | + - name: Set up Python ${{ matrix.python-version }} |
| 108 | + uses: actions/setup-python@v1 |
| 109 | + with: |
| 110 | + python-version: ${{ matrix.python-version }} |
| 111 | + - name: Install Dependencies |
| 112 | + run: | |
| 113 | + python -m pip install --upgrade pip |
| 114 | + pip install -r requirements.txt |
| 115 | + pip uninstall -y Django |
| 116 | + pip install Django${{ matrix.django-version }} |
| 117 | + - name: Django test runner |
| 118 | + run: | |
| 119 | + python manage.py test |
| 120 | + - name: Django souce code check |
| 121 | + run: | |
| 122 | + python manage.py check |
| 123 | + - name: Django Template validation |
| 124 | + run: | |
| 125 | + python manage.py validate_templates |
| 126 | + docker: |
| 127 | + runs-on: ubuntu-18.04 |
| 128 | + steps: |
| 129 | + - uses: actions/checkout@v2 |
| 130 | +
|
| 131 | + - name: docker build |
| 132 | + run: docker build . --file Dockerfile -t ${{ github.repository }} -t ${{ github.repository }}:$(date +%s) |
| 133 | +``` |
| 134 | + |
| 135 | +``` |
| 136 | +name: Django Sqlite Mac, Linux, Windows |
| 137 | +
|
| 138 | +on: |
| 139 | + pull_request: |
| 140 | + branches: '**' |
| 141 | + push: |
| 142 | + branches: |
| 143 | + - develop |
| 144 | + schedule: |
| 145 | + - cron: '0 20 * * 5' |
| 146 | +
|
| 147 | +jobs: |
| 148 | + build: |
| 149 | + runs-on: ${{ matrix.os }} |
| 150 | + strategy: |
| 151 | + matrix: |
| 152 | + python_version: [3.7, 3.8] |
| 153 | + os: [macos-latest, windows-latest, ubuntu-latest] |
| 154 | + steps: |
| 155 | + - uses: actions/checkout@v1 |
| 156 | + - name: Set up Python ${{ matrix.python_version }} |
| 157 | + uses: actions/setup-python@v1 |
| 158 | + with: |
| 159 | + python-version: ${{ matrix.python_version }} |
| 160 | + - name: Install Dependencies |
| 161 | + run: | |
| 162 | + python -m pip install --upgrade pip |
| 163 | + pip install -r requirements.txt |
| 164 | + - name: Django souce code check |
| 165 | + run: | |
| 166 | + python manage.py check |
| 167 | + - name: Django test runner |
| 168 | + run: | |
| 169 | + python manage.py test |
| 170 | + - name: Django Template validation |
| 171 | + run: | |
| 172 | + python manage.py validate_templates |
| 173 | +``` |
| 174 | + |
| 175 | +## Referenzen |
| 176 | +- pip list: https://pip.pypa.io/en/stable/reference/pip_list/ |
| 177 | +- black: https://github.com/psf/black |
| 178 | +- isort: https://github.com/timothycrosley/isort |
| 179 | +- bandit: https://pypi.org/project/bandit/ |
| 180 | + |
| 181 | +- Docker Pipeline: https://partner.bdr.de/gitlab/kfe-devops/pipeline-docker-nodejs-demo |
0 commit comments