Skip to content
Open

Lab03 #2446

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

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

permissions:
contents: read

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

env:
JAVA_VERSION: "21"
DOCKER_IMAGE: "112005/devops-lab3-java"

jobs:
test:
runs-on: ubuntu-latest
defaults:
run:
working-directory: app_java
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Java
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: ${{ env.JAVA_VERSION }}
cache: "maven"

- name: Lint (Checkstyle)
run: mvn -q -DskipTests=true checkstyle:check

- name: Test
run: mvn -q test

docker:
runs-on: ubuntu-latest
needs: test
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
steps:
- name: Checkout
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: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_IMAGE }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest

- name: Build and push
uses: docker/build-push-action@v6
with:
context: app_java
file: app_java/Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
111 changes: 111 additions & 0 deletions .github/workflows/python-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
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"
workflow_dispatch:

permissions:
contents: read

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

env:
PYTHON_VERSION: "3.11"
DOCKER_IMAGE: "112005/devops-lab3-python"

jobs:
test:
runs-on: ubuntu-latest
env:
SNYK_TOKEN: ${{ secrets.SNYK_TOKEN }}
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
defaults:
run:
working-directory: app_python
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: ${{ env.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 requirements.txt -r requirements-dev.txt

- name: Lint
run: ruff check .

- name: Test with coverage
run: pytest --cov=. --cov-report=term --cov-report=xml --cov-fail-under=70

- name: Set up Snyk CLI
if: github.event_name != 'pull_request' && env.SNYK_TOKEN
uses: snyk/actions/setup@v1

- name: Snyk scan
if: github.event_name != 'pull_request' && env.SNYK_TOKEN
timeout-minutes: 5
env:
SNYK_TOKEN: ${{ env.SNYK_TOKEN }}
run: snyk test --severity-threshold=high --file=requirements.txt --package-manager=pip --skip-unresolved

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

docker:
runs-on: ubuntu-latest
needs: test
if: ${{ github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') }}
steps:
- name: Checkout
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: Extract Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKER_IMAGE }}
tags: |
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest

- 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 }}
21 changes: 21 additions & 0 deletions app_java/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Git
.git
.gitignore

# Maven
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties

# IDE
.idea/
.vscode/
*.iml
*.ipr
*.iws

# Logs
*.log
24 changes: 24 additions & 0 deletions app_java/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Maven
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties

# Java
*.class
*.jar
*.war
*.ear
*.log

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

# OS
.DS_Store
Thumbs.db
35 changes: 35 additions & 0 deletions app_java/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Stage 1: Build
FROM maven:3.9.6-eclipse-temurin-21 AS builder

WORKDIR /app

# Copy the Maven project file
COPY pom.xml .

# Download dependencies
RUN mvn dependency:go-offline

# Copy the rest of the source code
COPY src ./src

# Build the application
RUN mvn package -DskipTests

# Stage 2: Runtime
FROM eclipse-temurin:21-jre-jammy

# Create a non-root user
RUN useradd --create-home appuser

# Copy the JAR file from the builder stage
COPY --from=builder /app/target/*.jar /app/app.jar

# Set ownership and switch to the non-root user
RUN chown appuser:appuser /app/app.jar
USER appuser

# Expose the port the app runs on
EXPOSE 8080

# Command to run the application
CMD ["java", "-jar", "/app/app.jar"]
Loading