Skip to content
Open

Lab9 #3286

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.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
name: Ansible Deployment (Lab06)

on:
push:
branches: [main, master, lab6]
paths:
- "lab6c/ansible/**"
- "!.github/workflows/ansible-deploy.yml"
pull_request:
branches: [main, master, lab6]
paths:
- "lab6c/ansible/**"

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

jobs:
lint:
name: Ansible Lint
runs-on: ubuntu-latest
defaults:
run:
working-directory: lab6c/ansible
steps:
- uses: actions/checkout@v4

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

- name: Install Ansible and ansible-lint
run: |
pip install ansible ansible-lint
ansible-galaxy collection install -r requirements.yml

- name: Run ansible-lint
run: ansible-lint playbooks/*.yml 2>/dev/null || echo "Lint finished (warnings may appear)"

deploy:
name: Deploy Application
needs: lint
runs-on: ubuntu-latest
if: github.event_name == 'push'
defaults:
run:
working-directory: lab6c/ansible
steps:
- uses: actions/checkout@v4

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

- name: Install Ansible and collections
run: |
pip install ansible
ansible-galaxy collection install -r requirements.yml

- 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 || true

- name: Deploy with Ansible
env:
ANSIBLE_VAULT_PASSWORD: ${{ secrets.ANSIBLE_VAULT_PASSWORD }}
run: |
echo "$ANSIBLE_VAULT_PASSWORD" > /tmp/vault_pass
chmod 600 /tmp/vault_pass
ansible-playbook playbooks/deploy.yml \
--vault-password-file /tmp/vault_pass \
-e ansible_ssh_private_key_file=~/.ssh/id_ed25519 \
-e ansible_host=${{ secrets.VM_HOST }} \
-e ansible_user=${{ secrets.VM_USER }}
rm -f /tmp/vault_pass

- name: Verify deployment
run: |
sleep 15
curl -sf "http://${{ secrets.VM_HOST }}:5000/health" || echo "Health check failed"
curl -sf "http://${{ secrets.VM_HOST }}:5000/" || echo "Root check failed"
76 changes: 76 additions & 0 deletions .github/workflows/go-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: Go CI (Lab03 Bonus)

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

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

permissions:
contents: read

jobs:
test:
name: Lint and Test
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.22"

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
working-directory: lab3c/app_go
args: --timeout=5m

- name: Run tests
working-directory: lab3c/app_go
run: go test ./...

docker:
name: Build and Push Docker Image
runs-on: ubuntu-latest
needs: test
if: ${{ github.event_name == 'push' }}
steps:
- name: Checkout
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.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set version (CalVer)
run: echo "VERSION=$(date +%Y.%m.%d)" >> $GITHUB_ENV

- name: Build and push
uses: docker/build-push-action@v6
with:
context: ./lab3c/app_go
file: ./lab3c/app_go/Dockerfile
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/devops-info-go:${{ env.VERSION }}
${{ secrets.DOCKERHUB_USERNAME }}/devops-info-go:latest
cache-from: type=gha
cache-to: type=gha,mode=max
109 changes: 109 additions & 0 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
name: Python CI (Lab03)

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

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

permissions:
contents: read

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

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

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

- name: Lint (ruff)
working-directory: lab3c/app_python
run: ruff check .

- name: Run tests with coverage
working-directory: lab3c/app_python
run: pytest --cov=app --cov-report=xml --cov-report=term

- name: Upload coverage to Codecov
if: ${{ env.CODECOV_TOKEN != '' }}
uses: codecov/codecov-action@v4
with:
files: lab3c/app_python/coverage.xml
token: ${{ env.CODECOV_TOKEN }}

- name: Install Snyk CLI
if: ${{ env.SNYK_TOKEN != '' }}
run: npm install -g snyk

- name: Snyk scan
if: ${{ env.SNYK_TOKEN != '' }}
working-directory: lab3c/app_python
run: snyk test --file=requirements.txt --package-manager=pip
env:
SNYK_TOKEN: ${{ env.SNYK_TOKEN }}

docker:
name: Build and Push Docker Image
runs-on: ubuntu-latest
needs: test
if: ${{ github.event_name == 'push' }}
steps:
- name: Checkout
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.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Set version (CalVer)
run: echo "VERSION=$(date +%Y.%m.%d)" >> $GITHUB_ENV

- name: Build and push
uses: docker/build-push-action@v6
with:
context: ./lab3c/app_python
file: ./lab3c/app_python/Dockerfile
push: true
tags: |
${{ secrets.DOCKERHUB_USERNAME }}/devops-info-python:${{ env.VERSION }}
${{ secrets.DOCKERHUB_USERNAME }}/devops-info-python:latest
cache-from: type=gha
cache-to: type=gha,mode=max
51 changes: 51 additions & 0 deletions .github/workflows/terraform-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Terraform Validate (Lab04)

on:
push:
branches: [lab04, main, master]
paths:
- "lab4c/terraform/**"
- ".github/workflows/terraform-ci.yml"
pull_request:
branches: [lab04, main, master]
paths:
- "lab4c/terraform/**"
- ".github/workflows/terraform-ci.yml"

jobs:
validate:
name: Format, Validate, Lint
runs-on: ubuntu-latest
defaults:
run:
working-directory: lab4c/terraform
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: "1.9"
terraform_wrapper: false

- name: Terraform Format Check
run: terraform fmt -check -recursive

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

- name: Terraform Validate
run: terraform validate

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

- name: TFLint Init
run: tflint --init

- name: TFLint
run: tflint --format compact
continue-on-error: true
12 changes: 11 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,11 @@
test
test

# Ansible
*.retry
.vault_pass
ansible/inventory/*.pyc
__pycache__/

# Local lab 5 runtime artifacts
lab5c/ansible/.vault_pass
lab5c/ansible/*.retry
7 changes: 7 additions & 0 deletions lab2c/app_go/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
*.exe
*.log
.git/
.gitignore
.idea/
.vscode/
docs/
21 changes: 21 additions & 0 deletions lab2c/app_go/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM golang:1.22 AS builder

WORKDIR /src

COPY go.mod ./
RUN go mod download

COPY main.go ./
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o devops-info

FROM gcr.io/distroless/static-debian12:nonroot

WORKDIR /app
COPY --from=builder /src/devops-info /app/devops-info

ENV HOST=0.0.0.0 \
PORT=5000

EXPOSE 5000

ENTRYPOINT ["/app/devops-info"]
Loading