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

on:
push:
branches:
- main
- master
- lab3
paths:
- 'app_go/**'
- '.github/workflows/go-ci.yml'
pull_request:
branches:
- main
- master
paths:
- 'app_go/**'
- '.github/workflows/go-ci.yml'

env:
GO_VERSION: '1.21'
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
IMAGE_NAME: devops-info-service-go

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

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

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache-dependencies: true

- name: Run go vet
run: |
cd app_go
go vet ./...

- name: Run gofmt check
run: |
cd app_go
if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then
echo "Code is not formatted. Run 'gofmt -s -w .'"
gofmt -d .
exit 1
fi

- name: Run tests
run: |
cd app_go
go test -v -coverprofile=coverage.out ./...

- name: Generate coverage report
run: |
cd app_go
go tool cover -html=coverage.out -o coverage.html

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: ./app_go/coverage.out
flags: go
name: go-coverage
fail_ci_if_error: false

build-and-push:
name: Build and Push Docker Image
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || 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_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}

- name: Generate CalVer version
id: calver
run: |
VERSION=$(date +'%Y.%m.%d')
BUILD_NUMBER=${GITHUB_RUN_NUMBER}
FULL_VERSION="${VERSION}.${BUILD_NUMBER}"
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "full_version=${FULL_VERSION}" >> $GITHUB_OUTPUT
echo "CalVer: ${VERSION}, Full: ${FULL_VERSION}"

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./app_go
push: true
tags: |
${{ env.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.calver.outputs.version }}
${{ env.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.calver.outputs.full_version }}
${{ env.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest
cache-from: type=registry,ref=${{ env.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }}:buildcache,mode=max
labels: |
org.opencontainers.image.title=DevOps Info Service (Go)
org.opencontainers.image.description=DevOps course info service - Go implementation
org.opencontainers.image.version=${{ steps.calver.outputs.version }}
org.opencontainers.image.revision=${{ github.sha }}
153 changes: 153 additions & 0 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
name: Python CI/CD Pipeline

on:
push:
branches:
- main
- master
- lab3
paths:
- 'app_python/**'
- '.github/workflows/python-ci.yml'
pull_request:
branches:
- main
- master
paths:
- 'app_python/**'
- '.github/workflows/python-ci.yml'

env:
PYTHON_VERSION: '3.13'
DOCKER_HUB_USERNAME: ${{ secrets.DOCKER_HUB_USERNAME }}
IMAGE_NAME: devops-info-service

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

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

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

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

- name: Run linter (flake8)
run: |
cd app_python
flake8 app.py tests/ --max-line-length=120 --extend-ignore=E203,W503

- name: Run formatter check (black)
run: |
cd app_python
black --check app.py tests/

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

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: ./app_python/coverage.xml
flags: python
name: python-coverage
fail_ci_if_error: false

security-scan:
name: Security Scanning
runs-on: ubuntu-latest

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

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

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

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

build-and-push:
name: Build and Push Docker Image
runs-on: ubuntu-latest
needs: [test, security-scan]
if: github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || 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_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}

- name: Extract metadata (tags, labels)
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=sha,prefix={{branch}}-
type=raw,value=latest,enable={{is_default_branch}}

- name: Generate CalVer version
id: calver
run: |
VERSION=$(date +'%Y.%m.%d')
BUILD_NUMBER=${GITHUB_RUN_NUMBER}
FULL_VERSION="${VERSION}.${BUILD_NUMBER}"
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "full_version=${FULL_VERSION}" >> $GITHUB_OUTPUT
echo "CalVer: ${VERSION}, Full: ${FULL_VERSION}"

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: ./app_python
push: true
tags: |
${{ env.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.calver.outputs.version }}
${{ env.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }}:${{ steps.calver.outputs.full_version }}
${{ env.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }}:latest
cache-from: type=registry,ref=${{ env.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }}:buildcache
cache-to: type=registry,ref=${{ env.DOCKER_HUB_USERNAME }}/${{ env.IMAGE_NAME }}:buildcache,mode=max
labels: |
org.opencontainers.image.title=DevOps Info Service
org.opencontainers.image.description=DevOps course info service
org.opencontainers.image.version=${{ steps.calver.outputs.version }}
org.opencontainers.image.revision=${{ github.sha }}
67 changes: 67 additions & 0 deletions .github/workflows/terraform-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Terraform CI

on:
pull_request:
branches:
- main
- master
- lab04
paths:
- 'terraform/**'
- '.github/workflows/terraform-ci.yml'
push:
branches:
- main
- master
- lab04
paths:
- 'terraform/**'
- '.github/workflows/terraform-ci.yml'

env:
TF_VERSION: '1.9.0'

jobs:
validate:
name: Validate Terraform
runs-on: ubuntu-latest

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

- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TF_VERSION }}

- name: Terraform Format Check
run: |
cd terraform
terraform fmt -check -recursive
continue-on-error: false

- name: Terraform Init
run: |
cd terraform
terraform init -backend=false

- name: Terraform Validate
run: |
cd terraform
terraform validate

- name: Setup TFLint
uses: terraform-linters/setup-tflint@v3
with:
tflint_version: latest

- name: TFLint Init
run: |
cd terraform
tflint --init

- name: Run TFLint
run: |
cd terraform
tflint --format compact
Loading