Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
cfe5c92
Replicating repo file structure according to the presentation diagram
FannyMalinova Nov 18, 2024
c07edba
Adding the Dockerfile from the previous excercise - docker-first-test
FannyMalinova Nov 18, 2024
6e0ba15
Updating the playbook.yaml file as per the ansible-docker-homework
FannyMalinova Nov 18, 2024
6b1a2c9
Populating the .editorconfig file.
FannyMalinova Nov 18, 2024
60b467b
Adding GitLeaks scan
FannyMalinova Nov 18, 2024
18a2acc
Removing .env from the GitLeaks config
FannyMalinova Nov 18, 2024
5815615
Adding EditorChecker
FannyMalinova Nov 18, 2024
4708310
Changing .editorconfig to use spaces for indentation.
FannyMalinova Nov 18, 2024
445ec99
Removing trailing whitespace and final newline conditions.
FannyMalinova Nov 18, 2024
63af1c0
Adding Python Black scanning.
FannyMalinova Nov 18, 2024
7fdf3b7
Joining Pylint to Black Check.
FannyMalinova Nov 18, 2024
7603560
Adding exceptions to Pylint.
FannyMalinova Nov 18, 2024
ff98ceb
Fixing a typo.
FannyMalinova Nov 18, 2024
09eb566
Specifying .py files
FannyMalinova Nov 18, 2024
e3c02f2
Adding Markdownlint.
FannyMalinova Nov 18, 2024
28417f6
Adding exceptions to Markdownlint.
FannyMalinova Nov 18, 2024
5c2dce9
Fixing a typo on L12.
FannyMalinova Nov 18, 2024
b7ad5ce
Fixing an indentation issue.
FannyMalinova Nov 18, 2024
8fd6c21
Fixing a typo.
FannyMalinova Nov 18, 2024
4b69891
Fixing a typo.
FannyMalinova Nov 18, 2024
4b5327b
Adding unit testing.
FannyMalinova Nov 18, 2024
bb07f41
Specifying test file.
FannyMalinova Nov 18, 2024
d83de77
Adding Snyk.
FannyMalinova Nov 18, 2024
718bab4
Adding Sonar Cloud.
FannyMalinova Nov 18, 2024
e172307
Adding ProjectKey and Organization to the Sonar setup.
FannyMalinova Nov 18, 2024
f59bed4
Building a Docker image.
FannyMalinova Nov 18, 2024
2534533
Fixing indentation.
FannyMalinova Nov 18, 2024
7c66b67
Changing build-push-action version.
FannyMalinova Nov 18, 2024
85e2a4c
Adding the right variable for the Docker tag.
FannyMalinova Nov 18, 2024
5038d80
Adding Trivy.
FannyMalinova Nov 18, 2024
c423253
Increasing timeout for Trivy.
FannyMalinova Nov 18, 2024
ed9206b
Adding a condition to run Trivy.
FannyMalinova Nov 18, 2024
d1f3152
Trying to fix issue with pulling Trivy DB.
FannyMalinova Nov 18, 2024
89855ea
Splitting jobs and unifying Docker build and scan with Trivy.
FannyMalinova Nov 18, 2024
cec4d4f
Adding a missing step for Pylint.
FannyMalinova Nov 18, 2024
fa55caf
Trying with skip-update with Trivy.
FannyMalinova Nov 18, 2024
96808d2
Fixing Trivy.
FannyMalinova Nov 18, 2024
853fb29
Adding Docker push.
FannyMalinova Nov 18, 2024
429cb9e
Unifying steps.
FannyMalinova Nov 18, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# top-most EditorConfig file
root = true

# Set default parameters
[*]
charset = utf-8
indent_style = space

170 changes: 170 additions & 0 deletions .github/workflows/ci-pipeline.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,170 @@
---
name: GitHub Actions Pipeline for a Flask App

on:
push:
branches:
- monday-practice
pull_request:
branches:
- main

jobs:
scan:
name: GitLeaks scan for secrets
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: gitleaks/gitleaks-action@v2.3.7

editorconfig:
name: EditorConfig checker
runs-on: ubuntu-latest
needs: scan
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Use EditorConfig Checker
uses: editorconfig-checker/action-editorconfig-checker@main

- name: Run EditorConfig Checker
run: editorconfig-checker

markdownlintcli:
name: Markdownlint CLI
runs-on: ubuntu-latest
needs: scan
steps:
- name: Install Markdownlint CLI
run: npm install -g markdownlint-cli

- name: Run Markdownlint
run: markdownlint **/*.md

python-black:
name: Run Python Black
runs-on: ubuntu-latest
needs: scan
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Python Black Check
uses: rodrigogiraoserrao/python-black-check@v3.0
with:
line-length: '81'

python-pylint:
name: Run Pylint Github Action
runs-on: ubuntu-latest
needs: scan
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Run Pylint GitHub Action
uses: ReasonSoftware/action-pylint@v2.0.3
with:
requirements_file: requirements.txt
filepaths: "app/*.py"
options: "-d C0114,C0115,C0116"

unittest:
name: Run Python unit tests
runs-on: ubuntu-latest
needs: [scan, editorconfig,markdownlintcli, python-black, python-pylint]
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.13"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Run unit tests
run: python -m unittest discover -s app -p "*.py"

snyk:
name: Run Snyk
runs-on: ubuntu-latest
needs: [scan, editorconfig,markdownlintcli, python-black, python-pylint]
steps:
- name: Run Snyk
uses: snyk/actions/python@master
continue-on-error: true
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}

sonar:
name: Run SonarCloud
runs-on: ubuntu-latest
needs: [scan, editorconfig,markdownlintcli, python-black, python-pylint]
steps:
- name: SonarCloud Scan
uses: SonarSource/sonarcloud-github-action@v3.1.0
with:
args:
-Dsonar.organization=fannymalinova
-Dsonar.projectKey=FannyMalinova_devops-programme
env:
SONAR_TOKEN: ${{ secrets.SONAR_SECRET }}

docker-build-trivy-push:
name: Docker build, scan with Trivy, push
runs-on: ubuntu-latest
needs: [unittest, snyk, sonar]
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Log in to Docker Hub
uses: docker/login-action@v3.3.0
with:
username: ${{ vars.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build image
uses: docker/build-push-action@v6
with:
context: .
push: false
tags: ${{ vars.DOCKERHUB_USERNAME }}/flask-app:${{ github.sha }}

- name: Scan with Trivy
uses: aquasecurity/trivy-action@0.28.0
with:
image-ref: ${{ vars.DOCKERHUB_USERNAME }}/flask-app:${{ github.sha }}
format: "table"
ignore-unfixed: true
vuln-type: "os,library"

- name: Push container to Docker Hub
if: ${{ success() }}
run: docker push ${{ vars.DOCKERHUB_USERNAME }}/flask-app:${{ github.sha }}




















3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,6 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

#Credentials
vars/credentials.yaml
11 changes: 11 additions & 0 deletions .markdownlint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"default": false,
"overrides": [
{
"files": ["**/*.md"],
"default": true,
"MD012": false,
"MD013": false
}
]
}
29 changes: 29 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#Ubuntu 22.04 base image
FROM ubuntu:22.04

#Copy the requirements file
COPY requirements.txt .

#Install python3
RUN apt-get update && apt-get install -y python3 python3-pip \
&& useradd -m -s /bin/bash nruser \
&& pip install -r requirements.txt \
&& mkdir /app

#Copy app
COPY --chown=nruser app /app

#Switch to the non-root user
USER nruser

#Add work dir
WORKDIR /app

#Expose the port
EXPOSE 5000

#Add entrypoint
ENTRYPOINT [ "python3"]

#Run the app
CMD ["app.py"]
Empty file added ansible/README.md
Empty file.
33 changes: 33 additions & 0 deletions ansible/playbook.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
- hosts: localhost
gather_facts: no
vars:
image_name: fannymalinova/python_app_from_ansible
image_tag: v1.0.1
listen_port: 5000
vars_files:
- vars/credentials.yaml
tasks:
- name: Docker login
docker_login:
username: "{{ dockerhub_credentials['username'] }}"
password: "{{ dockerhub_credentials['password'] }}"
- name: Build an image from Dockerfile
docker_image:
build:
path: ./
name: "{{ image_name }}"
tag: "{{ image_tag }}"
push: yes
source: build
- name: Logout from Docker Hub
docker_login:
username: "{{ dockerhub_credentials['username'] }}"
state: absent
- name: Run a container from this image
docker_container:
name: python_app_from_ansible_container
image: "{{ image_name }}:{{ image_tag }}"
ports:
- "8080:{{ listen_port }}"
env:
PORT: "{{ listen_port | string }}"
12 changes: 12 additions & 0 deletions app/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
ansible==10.3.0
ansible-compat==24.9.1
ansible-core==2.17.5
ansible-lint==24.9.2
blinker==1.6.3 ; python_version >= "3.10" and python_version < "4.0"
click==8.1.7 ; python_version >= "3.10" and python_version < "4.0"
colorama==0.4.6 ; python_version >= "3.10" and python_version < "4.0" and platform_system == "Windows"
flask==3.0.0 ; python_version >= "3.10" and python_version < "4.0"
itsdangerous==2.1.2 ; python_version >= "3.10" and python_version < "4.0"
jinja2==3.1.2 ; python_version >= "3.10" and python_version < "4.0"
markupsafe==2.1.3 ; python_version >= "3.10" and python_version < "4.0"
werkzeug==3.0.0 ; python_version >= "3.10" and python_version < "4.0"
10 changes: 10 additions & 0 deletions vars/credentials.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
$ANSIBLE_VAULT;1.1;AES256
63666461366532393264616561363736626230313666623763336563636665623464326661363764
3065376230393033313664376336383732643138343235390a343936663933613832303963383935
35313137373262383962373938643564316464356565656466303733393466623733376638316234
3330333635613638380a613130643932333635616461633761643130653634613365656262313261
66386464373933616262323835393936633162333538346236306633323736656661326264663237
37366465343862616532386338383634663833303833333466653535333363316239323266666333
38646563643937373937313336366339656164326563353831653961393732643261383234373737
64663863343630366161613635373461306438363136343635356262306332656365643830363436
6464