Skip to content
Snippets Groups Projects
Commit 66c3a9e2 authored by wep23441's avatar wep23441
Browse files

breaking case 3

parent 603009ac
Branches
No related tags found
No related merge requests found
*txt
\ No newline at end of file
......@@ -22,17 +22,20 @@ include:
# stages: code_quality, test, build, build_image
# - local: ci-configs/case-3-build/lint.yml
# - local: ci-configs/case-3-build/coverage.yml
- local: ci-configs/case-3-build/unit_test.yml
- local: ci-configs/case-3-build/build.yml
- local: ci-configs/case-3-build/build_image.yml
# - local: ci-configs/case-3-build/unit_test.yml
# - local: ci-configs/case-3-build/build.yml
# - local: ci-configs/case-3-build/build_image.yml
# Case 4 Security
# stages: code_quality, security_checks, test, build, build_image, test_image
# - local: ci-configs/case-4-security/container_scan.yml
# - local: ci-configs/case-4-security/sast.yml
# - local: ci-configs/case-4-security/secret_detection.yml
# - local: ci-configs/case-3-build/lint.yml
# - local: ci-configs/case-3-build/coverage.yml
# - local: ci-configs/case-3-build/unit_test.yml
# - local: ci-configs/case-3-build/build.yml
# - local: ci-configs/case-3-build/build_image.yml
- local: ci-configs/case-4-security/container_scan.yml
- local: ci-configs/case-4-security/sast.yml
- local: ci-configs/case-4-security/secret_detection.yml
......
### Task Case 3 Build:
Fix the issues in the CI/CD pipeline and Python script by editing the files
within the `case-3-build/` and the corresponding CI jobs in `ci-configs/case-3-build/` folders, as well as the `Dockerfile` in the root of the repo. Ensure the pipeline
runs successfully and the Python code adheres to linting and formatting standards.
## Dont forget to uncomment the corresponding case section in the `.gitlab-ci.yml`, as well as correct stages specified!
\ No newline at end of file
pytest==8.3.5
pytest-cov==6.0.0
coverage==7.7.0
from setuptools import setup, find_packages
setup(
name="my_smart_package",
version="0.1.0",
packages=find_packages(),
install_requires=[
"pytest>=8.3.5",
"pytest-cov>=6.0.0",
"coverage>=7.7.0",
],
tests_require=["pytest"],
python_requires=">=3.9",
)
import pytest
from wizard_calculator import (
summon_dragons,
vanish_trolls,
brew_potions,
cast_division_spell,
conjure_magic_circle_area,
)
def test_summon_dragons():
assert summon_dragons(1, 2) == 3
assert summon_dragons(-1, 1) == 0
assert summon_dragons(0, 0) == 0
def test_vanish_trolls():
assert vanish_trolls(5, 3) == 2
assert vanish_trolls(0, 5) == -5
assert vanish_trolls(10, 0) == 10
def test_brew_potions():
assert brew_potions(2, 3) == 6
assert brew_potions(-1, 3) == -3
assert brew_potions(0, 100) == 0
def test_cast_division_spell():
assert cast_division_spell(6, 3) == 2
assert cast_division_spell(10, 2) == 5
assert cast_division_spell(7, 7) == 1
with pytest.raises(ValueError):
cast_division_spell(1, 0)
def test_conjure_magic_circle_area():
assert conjure_magic_circle_area(3) == pytest.approx(28.274, 0.001)
assert conjure_magic_circle_area(0) == 0
assert conjure_magic_circle_area(1) == pytest.approx(3.14159, 0.001)
import math
def summon_dragons(a, b):
return a + b
def vanish_trolls(a, b):
return a - b
def brew_potions(a, b):
return a * b
def cast_division_spell(a, b):
if b == 0:
raise ValueError("Attempted to split by zero — the magic council forbids it!")
return a / b
def conjure_magic_circle_area(radius):
return math.pi * radius * radius
if __name__ == "__main__": # pragma: no cover
print("Welcome to the Wizard's Magic Calculator! 🧙‍♂️✨")
print("Choose your spell:")
print("1. Summon dragons 🐉")
print("2. Vanish trolls 👹")
print("3. Brew potions 🧪")
print("4. Cast division spell ✨")
print("5. Conjure magic circle area 🔮")
choice = input("Enter your choice (1/2/3/4/5): ")
if choice == "5":
radius = float(input("Enter the radius of your magic circle: "))
result = conjure_magic_circle_area(radius)
print("\n✨ Magic complete! ✨")
print(f"Circle area: {result:.2f} spells.")
else:
a = float(input("Enter the first magical number: "))
b = float(input("Enter the second magical number: "))
if choice == "1":
result = summon_dragons(a, b)
elif choice == "2":
result = vanish_trolls(a, b)
elif choice == "3":
result = brew_potions(a, b)
elif choice == "4":
result = cast_division_spell(a, b)
else:
result = "The spell fizzled! Invalid choice. 🫧"
print(f"The magic result is: {result}")
......@@ -8,10 +8,10 @@ WORKDIR /app
# Copy dependencies
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt
# Maybe smth is missing hea..
# Copy the rest of the application
COPY . .
# Set the default command
CMD ["python", "wizard_calculator.py"]
\ No newline at end of file
CMD ["python", "file_I_want_to_run_with_docker.py"]
\ No newline at end of file
......@@ -5,3 +5,5 @@ build:
- pip install --upgrade pip
- pip install -r ./case-3-build/requirements.txt
- python ./case-3-build/setup.py install
dependencies:
- some_other_job_that_is_not_required
......@@ -6,9 +6,10 @@ build_image:
stage: build_image
image:
name: gcr.io/kaniko-project/executor:v1.23.2-debug
entrypoint: [""]
# entrypoint: [""]
script:
- /kaniko/executor
--context "${CI_PROJECT_DIR}/case-3-build/"
--dockerfile "${CI_PROJECT_DIR}/Dockerfile"
- echo "Pushing image with tag ${CI_COMMIT_TAG}"
--destination "${CI_REGISTRY_IMAGE}/${IMAGE_NAME}:${IMAGE_TAG}"
### Solution Case 3 Build:
1.
\ No newline at end of file
1. `Dockerfile` path in the `build_image.yml` job needs to be corrected and uncomment `entrypoint: [""]` and figure out what it does
2. in `Dockerfile` the insytallation of dependencies is missing `RUN pip install --no-cache-dir -r requirements.txt`
3. `.dockerignore` file ignores `requirements.txt` at the moment, needs to be corrected
4. remove unnecessary dependency from `build.yml`
\ No newline at end of file
### Solution Case 4 Security:
1. inside container_scan.yml the path should be CS_IMAGE: "${CI_REGISTRY_IMAGE}/${IMAGE_NAME}:${IMAGE_TAG}"
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment