Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
137 changes: 137 additions & 0 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
name: Python CI/CD Pipeline

on:
push:
branches: [ main, master, lab03 ]
paths:
- 'app_python/**'
- '.github/workflows/python-ci.yml'
pull_request:
branches: [ main, master ]
paths:
- 'app_python/**'
- '.github/workflows/python-ci.yml'

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

env:
PYTHON_VERSION: '3.11'
DOCKER_IMAGE: netimaaaa/devops-info-service

jobs:
test:
name: Test & Lint
runs-on: ubuntu-latest

strategy:
matrix:
python-version: ['3.11', '3.12']
fail-fast: true

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
cache: 'pip'
cache-dependency-path: 'app_python/requirements.txt'

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

- name: Lint with pylint
run: |
cd app_python
pylint app.py --disable=C0114,C0116,R0903,W0718 || true

- name: Format check with black
run: |
cd app_python
black --check app.py tests/ || true

- name: Run tests with pytest
run: |
cd app_python
pytest tests/ -v --tb=short

- name: Run tests with coverage
run: |
cd app_python
pytest tests/ --cov=. --cov-report=xml --cov-report=term

- name: Upload coverage to Codecov
if: matrix.python-version == '3.11'
uses: codecov/codecov-action@v4
with:
file: ./app_python/coverage.xml
flags: unittests
name: codecov-umbrella
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}

docker:
name: Build & Push Docker Image
runs-on: ubuntu-latest
needs: [test, security]
if: github.event_name == 'push' && github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/lab03'

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Generate version tags
id: meta
run: |
# Calendar versioning: YYYY.MM.BUILD_NUMBER
VERSION=$(date +'%Y.%m').${{ github.run_number }}
MONTH_VERSION=$(date +'%Y.%m')

echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "month_version=${MONTH_VERSION}" >> $GITHUB_OUTPUT

# Generate tags
TAGS="${{ env.DOCKER_IMAGE }}:${VERSION}"
TAGS="${TAGS},${{ env.DOCKER_IMAGE }}:${MONTH_VERSION}"
TAGS="${TAGS},${{ env.DOCKER_IMAGE }}:latest"

echo "tags=${TAGS}" >> $GITHUB_OUTPUT

echo "Generated version: ${VERSION}"
echo "Generated tags: ${TAGS}"

- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: ./app_python
file: ./app_python/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
cache-from: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache
cache-to: type=registry,ref=${{ env.DOCKER_IMAGE }}:buildcache,mode=max
labels: |
org.opencontainers.image.title=DevOps Info Service
org.opencontainers.image.description=DevOps course info service
org.opencontainers.image.version=${{ steps.meta.outputs.version }}
org.opencontainers.image.created=${{ github.event.head_commit.timestamp }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.source=${{ github.repositoryUrl }}

- name: Image digest
run: echo "Image pushed with tags ${{ steps.meta.outputs.tags }}"
28 changes: 27 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,27 @@
test
# Python - app_python/
app_python/__pycache__/
app_python/*.py[cod]
app_python/venv/
app_python/env/
app_python/*.log

# Go - app_go/
app_go/devops-info-service
app_go/devops-info-service-*
app_go/*.exe

# IDE
.idea/
.vscode/

# OS
.DS_Store
Thumbs.db

# Env
.env

*.retry
.vault_pass
ansible/inventory/*.pyc
__pycache__/
11 changes: 11 additions & 0 deletions ansible/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[defaults]
inventory = inventory/hosts.ini
roles_path = roles
host_key_checking = False
remote_user = ubuntu
retry_files_enabled = False

[privilege_escalation]
become = True
become_method = sudo
become_user = root
Loading