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
123 changes: 123 additions & 0 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
name: Python CI/CD Pipeline

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

env:
REGISTRY: docker.io
IMAGE_NAME: ${{ github.repository_owner }}/devops-info-service
PYTHON_VERSION: '3.13'

jobs:
code-quality-and-testing:
name: Code Quality & Testing
runs-on: ubuntu-latest
defaults:
run:
working-directory: app_python

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

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

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

- name: Lint with flake8
run: |
echo "Running flake8 linting..."
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics

- name: Check code formatting with black
run: |
echo "Checking code formatting with black..."
black --check --diff .

- name: Run unit tests with pytest
run: |
echo "Running unit tests with pytest..."
pytest --cov=app --cov-report=term-missing -v

- name: Security scan with Snyk
uses: snyk/actions/python@master
continue-on-error: true
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
with:
args: --severity-threshold=high --file=requirements.txt

docker-build-and-push:
name: Docker Build & Push
runs-on: ubuntu-latest
needs: code-quality-and-testing
if: github.event_name == 'push' && github.ref == 'refs/heads/master'

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- 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_PASSWORD }}

- name: Generate version tags
id: vars
run: |
echo "DATE_TAG=$(date +'%Y.%m.%d')" >> $GITHUB_OUTPUT
echo "SHORT_SHA=${GITHUB_SHA:0:7}" >> $GITHUB_OUTPUT

COMMIT_COUNT=$(git rev-list --count --since="$(date +'%Y-%m-%d 00:00:00')" HEAD 2>/dev/null || echo "0")
echo "CALVER_TAG=$(date +'%Y.%m').$COMMIT_COUNT" >> $GITHUB_OUTPUT

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./app_python
push: true
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.DATE_TAG }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.CALVER_TAG }}
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.vars.outputs.DATE_TAG }}-${{ steps.vars.outputs.SHORT_SHA }}
labels: |
org.opencontainers.image.title=DevOps Info Service
org.opencontainers.image.description=DevOps course info service
org.opencontainers.image.version=${{ steps.vars.outputs.CALVER_TAG }}
org.opencontainers.image.created=${{ steps.vars.outputs.DATE_TAG }}
org.opencontainers.image.revision=${{ github.sha }}
cache-from: type=gha
cache-to: type=gha,mode=max

- name: Verify pushed images
run: |
echo "Docker images pushed with tags:"
echo "- latest"
echo "- ${{ steps.vars.outputs.DATE_TAG }}"
echo "- ${{ steps.vars.outputs.CALVER_TAG }}"
echo "- ${{ steps.vars.outputs.DATE_TAG }}-${{ steps.vars.outputs.SHORT_SHA }}"
43 changes: 43 additions & 0 deletions app_go/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Go artifacts
*.exe
*.exe~
*.dll
*.so
*.dylib
*.test
*.out
*.o
*.prof
*.trace
vendor/
__pycache__/

# Git
.git/
.gitignore

# IDE
.vscode/
.idea/
*.swp
*.swo

# OS
.DS_Store
Thumbs.db

# Documentation
*.md
docs/
README.md

# Docker
Dockerfile*
docker-compose*
.dockerignore

# Temporary files
*.tmp
*.log
tmp/
logs/
42 changes: 42 additions & 0 deletions app_go/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Stage 1: Builder - full build environment
FROM golang:1.21-alpine AS builder

# Install system dependencies for build (git for go mod download)
RUN apk add --no-cache git ca-certificates

# Set working directory
WORKDIR /app

# Copy Go module files
COPY go.mod ./

# Download Go module dependencies
RUN go mod download

# Copy application source code
COPY . .

# Build Go application with optimizations
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build \
-a \
-ldflags="-w -s -extldflags '-static'" \
-o devops-info-service .

# Stage 2: Minimal runtime
FROM scratch

# Copy CA certificates from builder for HTTPS support
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/

# Copy the compiled binary from builder
COPY --from=builder /app/devops-info-service /app/devops-info-service

# Expose port
EXPOSE 5000

# Set environment variables
ENV HOST=0.0.0.0
ENV PORT=5000

# Run the application
CMD ["/app/devops-info-service"]
97 changes: 97 additions & 0 deletions app_go/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# DevOps Info Service (Go)
## Overview
A Go-based web service designed to furnish details about itself and its operational environment. This compiled version of the service is optimized for containerization and multi-stage Docker builds, offering improved performance and smaller deployment footprints compared to interpreted languages.

## Prerequisites
- Go 1.21 or higher
- Git (for dependency management)

## Installation
1. Clone repository:

```bash
# Clone the project
git clone https://github.com/s3rap1s/DevOps-Core-Course.git
cd DevOps-Core-Course/app_go

# Download dependencies
go mod download

# Build the application
go build -o devops-info-service
```

## Running the Application
```bash
# Default configuration
./devops-info-service

# With custom port
PORT=8080 ./devops-info-service

# With custom port and host
HOST=127.0.0.1 PORT=3000 ./devops-info-service

# Run directly without building
go run main.go
Building for Different Platforms
bash
# Build for current platform
go build -o devops-info-service
```

## API Endpoints
### GET /
Return comprehensive service and system information:

```json
{
"service": {
"name": "devops-info-service",
"version": "1.0.0",
"description": "DevOps course info service",
"framework": "Go"
},
"system": {
"hostname": "my-laptop",
"platform": "linux",
"platform_version": "Linux Kernel",
"architecture": "amd64",
"cpu_count": 8,
"go_version": "go1.21.4"
},
"runtime": {
"uptime_seconds": 3600,
"uptime_human": "1 hour, 0 minutes",
"current_time": "2026-01-07T14:30:00.000Z",
"timezone": "UTC"
},
"request": {
"client_ip": "127.0.0.1:12345",
"user_agent": "curl/7.81.0",
"method": "GET",
"path": "/"
},
"endpoints": [
{"path": "/", "method": "GET", "description": "Service information"},
{"path": "/health", "method": "GET", "description": "Health check"}
]
}
```

### GET /health
Simple health endpoint for monitoring:

```json
{
"status": "healthy",
"timestamp": "2024-01-15T14:30:00.000Z",
"uptime_seconds": 3600
}
```

## Configuration
| Variable | Default | Description |
| -------- | --------- | ---------------------------- |
| `HOST` | `0.0.0.0` | Network interface to bind |
| `PORT` | `5000` | Port to listen on |
18 changes: 18 additions & 0 deletions app_go/docs/GO.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Language Justification
## My Choice: Go
I selected **Go** as the compiled language for the bonus task implementation. Here's why:

**Comparison Table:**

| Criteria | Go | Rust | Java | C# |
|----------|----|------|------|----|
|Learning Curve | Low | High | Medium | Medium |
|Development Speed | High | Low | Medium | Medium |
|Standard Library | Excellent | Good | Extensive | Extensive |
|Performance | Excellent | Outstanding | Good | Good |
|Binary Size | ~7 MB | ~3 MB | ~40 MB | ~30 MB |
|Memory Safety | GC | Compile-time | GC | GC |
| **Choice for Bonus** | **✓** | | | |

**Justification:**
Go offers the perfect balance for a DevOps service: it compiles to a single static binary with no runtime dependencies, has excellent concurrency support, and provides a rich standard library including HTTP server functionality. Its simplicity and fast compilation make it ideal for the iterative development required in this course. Go is also widely used in the DevOps ecosystem (Docker, Kubernetes, Prometheus), making it a relevant choice.
Loading