Skip to content
Open

Lab6 #2748

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
86 changes: 86 additions & 0 deletions .github/workflows/ansible-deploy-java.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Ansible Deploy Java

on:
push:
branches: [master]
paths:
- 'ansible/vars/app_java.yml'
- 'ansible/playbooks/deploy_java.yml'
- 'ansible/roles/web_app/**'
- '.github/workflows/ansible-deploy-java.yml'
pull_request:
branches: [master]
paths:
- 'ansible/**'
- '!ansible/docs/**'
- '.github/workflows/ansible-deploy-java.yml'

jobs:
lint:
name: Ansible Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: '3.12'

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

- name: Install Ansible collections
run: ansible-galaxy collection install -r requirements.yml
working-directory: ansible

- name: Create dummy vault password for lint
run: echo "dummy" > ansible/.vault_pass

- name: Run ansible-lint
run: ansible-lint playbooks/*.yml
working-directory: ansible

- name: Cleanup dummy vault pass
if: always()
run: rm -f ansible/.vault_pass

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

- uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install Ansible
run: pip install ansible

- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -H ${{ secrets.VM_HOST }} >> ~/.ssh/known_hosts 2>/dev/null

- name: Create vault password file
run: echo "${{ secrets.ANSIBLE_VAULT_PASSWORD }}" > /tmp/vault_pass

- name: Run Ansible playbook
run: |
ansible-playbook playbooks/deploy_java.yml \
-i inventory/hosts.ini \
--vault-password-file /tmp/vault_pass
working-directory: ansible

- name: Verify deployment
run: |
sleep 10
curl -f http://${{ secrets.VM_HOST }}:5001/health

- name: Cleanup
if: always()
run: rm -f /tmp/vault_pass
87 changes: 87 additions & 0 deletions .github/workflows/ansible-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
name: Ansible Deploy Python

on:
push:
branches: [master]
paths:
- 'ansible/vars/app_python.yml'
- 'ansible/playbooks/deploy_python.yml'
- 'ansible/playbooks/deploy.yml'
- 'ansible/roles/web_app/**'
- '.github/workflows/ansible-deploy.yml'
pull_request:
branches: [master]
paths:
- 'ansible/**'
- '!ansible/docs/**'
- '.github/workflows/ansible-deploy.yml'

jobs:
lint:
name: Ansible Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- uses: actions/setup-python@v5
with:
python-version: '3.12'

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

- name: Install Ansible collections
run: ansible-galaxy collection install -r requirements.yml
working-directory: ansible

- name: Create dummy vault password for lint
run: echo "dummy" > ansible/.vault_pass

- name: Run ansible-lint
run: ansible-lint playbooks/*.yml
working-directory: ansible

- name: Cleanup dummy vault pass
if: always()
run: rm -f ansible/.vault_pass

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

- uses: actions/setup-python@v5
with:
python-version: '3.12'

- name: Install Ansible
run: pip install ansible

- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SSH_PRIVATE_KEY }}" > ~/.ssh/id_ed25519
chmod 600 ~/.ssh/id_ed25519
ssh-keyscan -H ${{ secrets.VM_HOST }} >> ~/.ssh/known_hosts 2>/dev/null

- name: Create vault password file
run: echo "${{ secrets.ANSIBLE_VAULT_PASSWORD }}" > /tmp/vault_pass

- name: Run Ansible playbook
run: |
ansible-playbook playbooks/deploy_python.yml \
-i inventory/hosts.ini \
--vault-password-file /tmp/vault_pass
working-directory: ansible

- name: Verify deployment
run: |
sleep 10
curl -f http://${{ secrets.VM_HOST }}:5000/health

- name: Cleanup
if: always()
run: rm -f /tmp/vault_pass
77 changes: 77 additions & 0 deletions .github/workflows/java-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Java CI

on:
push:
branches: [master]
tags: ["v*.*.*"]
paths:
- "appJava/**"
- ".github/workflows/java-ci.yml"
pull_request:
branches: [master]
paths:
- "appJava/**"
- ".github/workflows/java-ci.yml"

permissions:
contents: read

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

jobs:
build-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: "25"
cache: gradle

- name: Build and test (Gradle)
working-directory: appJava
run: ./gradlew --no-daemon clean check bootJar

docker:
needs: build-test
runs-on: ubuntu-latest
if: ${{ github.event_name != 'pull_request' }}
steps:
- 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: luminitetime
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: luminitetime/devops-info-service-java
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest,enable={{is_default_branch}}
type=sha,format=short,prefix=sha-

- name: Build and push
uses: docker/build-push-action@v6
with:
context: ./appJava
file: ./appJava/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
107 changes: 107 additions & 0 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Python CI

on:
push:
branches: [master]
tags: ["v*.*.*"]
paths:
- "app_python/**"
- ".github/workflows/python-ci.yml"
pull_request:
branches: [master]
paths:
- "app_python/**"
- ".github/workflows/python-ci.yml"

permissions:
contents: read

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

jobs:
test:
runs-on: ubuntu-latest
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
strategy:
fail-fast: true
matrix:
python-version: ["3.12", "3.13"]
steps:
- uses: actions/checkout@v4

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

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

- name: Lint (ruff)
run: ruff check app_python

- name: Run tests (pytest + coverage)
run: pytest -q app_python/tests --cov=app_python --cov-report=term --cov-report=xml --cov-fail-under=70

- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
files: coverage.xml
fail_ci_if_error: false

- name: Set up Snyk
if: ${{ env.SNYK_TOKEN != '' }}
uses: snyk/actions/setup@master

- name: Snyk dependency scan
if: ${{ env.SNYK_TOKEN != '' }}
continue-on-error: true
run: snyk test --file=app_python/requirements.txt --severity-threshold=high

docker:
needs: test
runs-on: ubuntu-latest
if: ${{ github.event_name != 'pull_request' }}
steps:
- 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: luminitetime
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: luminitetime/devops-info-service-python
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest,enable={{is_default_branch}}
type=sha,format=short,prefix=sha-

- name: Build and push
uses: docker/build-push-action@v6
with:
context: ./app_python
file: ./app_python/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max
23 changes: 22 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,22 @@
test
.idea
.vscode

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

# Pulumi
pulumi/venv/
pulumi/.pulumi-state/
pulumi/__pycache__/
Pulumi.*.yaml

# Ansible
*.retry
.vault_pass
__pycache__/
5 changes: 5 additions & 0 deletions ansible/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
*.retry
.vault_pass
__pycache__/
*.pyc
.venv/
Loading