Skip to content
Open

Lab06 #2843

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c73c4ba
lab01: implemented main task prerequirements
Feb 11, 2026
e4d0823
lab01: added bonus task - the implementation of go app
Feb 11, 2026
f5ec5dd
lab02: create a docker image of my apps and pushed to docker hub
Feb 12, 2026
01ad188
lab03: added unit tests
Feb 12, 2026
b316ae8
lab03:added CI workflow
Feb 12, 2026
8f094f2
lab03: implemented all tasks exept bonus
Feb 12, 2026
35ed67a
ci: trigger workflow
Feb 12, 2026
45b8db8
lab03: added github ci/cd link
Feb 12, 2026
cc3df52
lab03: implemented bonus task
Feb 12, 2026
cf52a47
lab03: fix- handle json encode errors in go app
Feb 12, 2026
674e084
lab04: done main taks and bonus
Feb 25, 2026
66a40cb
Complete Lab 05: Ansible Configuration Management with bonus task
Feb 26, 2026
2121283
Complete Lab 06: Advanced Ansible & CI/CD
Mar 5, 2026
93c49a6
Fix ansible-lint errors: add role prefix to variables and use FQCN
Mar 5, 2026
da036bb
Fix remaining ansible-lint errors: yaml truthy, key-order, line-length
Mar 5, 2026
77961a2
Fix all ansible-lint errors: yaml formatting and vault_example exclusion
Mar 5, 2026
514811b
Skip internal-error in ansible-lint for vault_example.yml
Mar 5, 2026
b1ad633
Fix SSH key setup in workflow using heredoc
Mar 5, 2026
f1911db
Add SSH debug output in workflow
Mar 5, 2026
56579a2
Re-enable deploy job and add port 8000 to security group
Mar 5, 2026
3029f97
Remove hardcoded private_key_file from ansible.cfg for CI/CD compatib…
Mar 5, 2026
1d86801
Remove SSH key path from inventory for CI/CD compatibility
Mar 5, 2026
184ac2f
Remove obsolete version from docker-compose template
Mar 5, 2026
858837a
Complete Lab 06
Mar 5, 2026
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
83 changes: 83 additions & 0 deletions .github/workflows/ansible-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
name: Ansible Deployment

on:
push:
branches: [main, master, lab06]
paths:
- 'ansible/**'
- '!ansible/docs/**'
- '.github/workflows/ansible-deploy.yml'
pull_request:
branches: [main, master]
paths:
- 'ansible/**'

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

jobs:
lint:
name: Ansible 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: '3.12'

- name: Install dependencies
run: |
pip install ansible ansible-lint

- name: Run ansible-lint
run: |
cd ansible
ansible-lint playbooks/*.yml

deploy:
name: Deploy Application
needs: lint
runs-on: ubuntu-latest
if: github.event_name == 'push'
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install Ansible
run: pip install ansible

- name: Install Ansible collections
run: ansible-galaxy collection install community.docker community.general

- name: Setup SSH
run: |
mkdir -p ~/.ssh
cat > ~/.ssh/id_rsa << 'EOF'
${{ secrets.SSH_PRIVATE_KEY }}
EOF
chmod 600 ~/.ssh/id_rsa
ssh-keyscan -H ${{ secrets.VM_HOST }} >> ~/.ssh/known_hosts

- name: Deploy with Ansible
run: |
cd ansible
echo "${{ secrets.ANSIBLE_VAULT_PASSWORD }}" > /tmp/vault_pass
ansible-playbook playbooks/deploy.yml \
-i inventory/hosts.yml \
--vault-password-file /tmp/vault_pass
rm /tmp/vault_pass

- name: Verify Deployment
run: |
sleep 10
curl -f http://${{ secrets.VM_HOST }}:8000 || exit 1
curl -f http://${{ secrets.VM_HOST }}:8000/health || exit 1
69 changes: 69 additions & 0 deletions .github/workflows/go-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Go CI

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

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

jobs:
test:
name: Lint & Test
runs-on: ubuntu-latest
defaults:
run:
working-directory: app_go

steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: '1.21'
cache-dependency-path: app_go/go.mod

- name: Lint with golangci-lint
uses: golangci/golangci-lint-action@v6
with:
working-directory: app_go

- name: Run tests
run: go test -v ./...

docker:
name: Build & Push Docker
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push'

steps:
- uses: actions/checkout@v4

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

- name: Generate CalVer tag
id: version
run: echo "TAG=$(date +%Y.%m).${{ github.run_number }}" >> "$GITHUB_OUTPUT"

- name: Build and push
uses: docker/build-push-action@v6
with:
context: app_go
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/devops-info-service-go:${{ steps.version.outputs.TAG }}
${{ secrets.DOCKERHUB_USERNAME }}/devops-info-service-go:latest
85 changes: 85 additions & 0 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
name: Python CI

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

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

jobs:
test:
name: Lint & Test
runs-on: ubuntu-latest
defaults:
run:
working-directory: app_python

steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: '3.13'
cache: 'pip'
cache-dependency-path: app_python/requirements-dev.txt

- name: Install dependencies
run: pip install -r requirements-dev.txt

- name: Lint with ruff
run: ruff check .

- name: Run tests with coverage
run: pytest -v --cov=. --cov-report=xml --cov-report=term

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
file: app_python/coverage.xml
token: ${{ secrets.CODECOV_TOKEN }}

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

docker:
name: Build & Push Docker
needs: test
runs-on: ubuntu-latest
if: github.event_name == 'push'

steps:
- uses: actions/checkout@v4

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

- name: Generate CalVer tag
id: version
run: echo "TAG=$(date +%Y.%m).${{ github.run_number }}" >> "$GITHUB_OUTPUT"

- name: Build and push
uses: docker/build-push-action@v6
with:
context: app_python
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/devops-info-service:${{ steps.version.outputs.TAG }}
${{ secrets.DOCKERHUB_USERNAME }}/devops-info-service:latest
94 changes: 94 additions & 0 deletions .github/workflows/terraform-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
name: Terraform CI

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

jobs:
terraform-validate:
name: Terraform Validation
runs-on: ubuntu-latest
defaults:
run:
working-directory: terraform

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

- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: 1.9.0

- name: Terraform Format Check
id: fmt
run: terraform fmt -check -recursive
continue-on-error: true

- name: Terraform Init
id: init
run: terraform init -backend=false

- name: Terraform Validate
id: validate
run: terraform validate -no-color

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

- name: Initialize TFLint
run: tflint --init

- name: Run TFLint
id: tflint
run: tflint --format compact
continue-on-error: true

- name: Comment PR
uses: actions/github-script@v7
if: github.event_name == 'pull_request'
with:
script: |
const output = `#### Terraform Format and Style 🖌\`${{ steps.fmt.outcome }}\`
#### Terraform Initialization ⚙️\`${{ steps.init.outcome }}\`
#### Terraform Validation 🤖\`${{ steps.validate.outcome }}\`
#### TFLint 🔍\`${{ steps.tflint.outcome }}\`

<details><summary>Validation Output</summary>

\`\`\`
${{ steps.validate.outputs.stdout }}
\`\`\`

</details>

*Pusher: @${{ github.actor }}, Action: \`${{ github.event_name }}\`, Workflow: \`${{ github.workflow }}\`*`;

github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: output
})

- name: Terraform Format Status
if: steps.fmt.outcome == 'failure'
run: |
echo "::error::Terraform format check failed. Run 'terraform fmt -recursive' to fix."
exit 1

- name: TFLint Status
if: steps.tflint.outcome == 'failure'
run: |
echo "::warning::TFLint found issues. Please review and fix if necessary."
34 changes: 33 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,33 @@
test
test
pyrightconfig.json

# Terraform
*.tfstate
*.tfstate.*
.terraform/
terraform.tfvars
*.tfvars
.terraform.lock.hcl

# Pulumi
pulumi/venv/
Pulumi.*.yaml
__pycache__/
*.pyc

# Cloud credentials
*.pem
*.key
credentials

# Yandex Cloud key files
key.json

# Allow package.json and other project files
!package.json
!package-lock.json
!tsconfig.json

# IDE
.vscode/
.idea/
6 changes: 6 additions & 0 deletions ansible/.ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
skip_list:
- internal-error

exclude_paths:
- playbooks/vault_example.yml
Loading