CSCI-GA-2820-FA23-003 / promotions

NYU DevOps Promotions Service Fall 2023-003
Apache License 2.0
1 stars 0 forks source link

NYU DevOps Project - Promotions

License Python CI Build codecov

Contents

The project contains the following:

.gitignore          - this will ignore vagrant and other metadata files
.flaskenv           - Environment variables to configure Flask
.gitattributes      - File to gix Windows CRLF issues
.devcontainers/     - Folder with support for VSCode Remote Containers
dot-env-example     - copy to .env to use environment variables
requirements.txt    - list if Python libraries required by your code
Dockerfile          - instructions for building a Docker image for the application
setup.cfg           - configuration file for automated tasks like linting, testing, etc.
.coverage           - Coverage report file

service/                   - service python package
├── __init__.py            - package initializer
├── models.py              - module with business models
├── routes.py              - module with service routes
└── common                 - common code package
    ├── __init__.py        - package initializer
    ├── cli_commands.py    - Flask CLI extension for database management commands
    ├── error_handlers.py  - HTTP error handling code
    ├── log_handlers.py    - logging setup code
    └── status.py          - HTTP status constants

tests/              - test cases package
├── __init__.py     - package initializer
├── factories.py     - factories for creating mock objects in tests
├── test_cli_commands.py     - test suite for CLI command extensions
├── test_models.py  - test suite for business models
└── test_routes.py  - test suite for service routes

features/                     - BDD feature files and accompanying test steps
├── steps/                    - Step definition modules for feature tests
│   ├── promotions_steps.py   - Step definitions for promotions feature tests
│   ├── web_detail_steps.py   - Step definitions for web detail feature tests
│   ├── web_steps.py          - Step definitions for web feature tests
│   └── environment.py        - Setup and teardown hooks for BDD tests
└── promotions.feature        - Feature file describing promotion scenarios

k8s/                         - Kubernetes deployment configurations
├── deployment.yaml          - Defines the deployment to manage application pods
├── ingress.yaml             - Configuration for ingress resource to manage external access to the services
├── postgresql.yaml          - Deployment and service configuration for the PostgreSQL database
├── pv.yaml                  - Defines persistent volumes for durable storage
└── service.yaml             - Service configuration to expose the application pods

Description

This service is designed to manage promotions. It offers endpoints to create, retrieve, update, and delete promotions.

Running the tests

Run the tests using green. The goal is to have 95% coverage with 100% passing tests.

$ green

Running the service

The project uses honcho which gets it's commands from the Procfile. To start the service simply use:

$ honcho start

Service available at: http://localhost:8000. The port that is used is controlled by an environment variable defined in the .flaskenv file which Flask uses to load it's configuration from the environment by default.

Deploying to Local K8 Cluster

Step 1: Create a kubernetes cluster

This assumes the Makefile has the below command:

make cluster

Step 2: Build image and push to local registry & Deploy the K8 cluster

make deploy

Step 3: Show the services

make show

Optional: Cleanup

make delete
make cluster-rm 

Data Model / DB Schema

Promotion Schema

Field Type Description
id int The promotion id
code str The Promotion code
name str The Promotion label (description)
start date Active date
expired date Expired date
available int Code available to use
whole_store bool Whether is whole store promotion
promo_type int The Promotion type
value double Promotion value according to the type
created_at Date Date the Promotion was created
updated_at Date Model lasted updated timestamp

Note: promotion_type is an integer value that represents the type of promotion. The value can be one of the following:

  • 1: Percentage
  • 2: Fixed Amount
  • 3: Buy X Get Y Free
  • 4: Buy X Get Y at Z% Off
  • 5: Buy X Get Y at Z% Off (same product)

Product Schema

Field Type Description
id int The Promotion Id
created_at str Date the Promotion applies to the product
updated_at Date Model lasted updated timestamp

Promotion - Product Schema

Field Type Description
promotion_id int The Promotion id
product_id int The Product Id
created_at str Date the Promotion applies to the product
updated_at Date Model lasted updated timestamp

API Endpoints

1. Root URL

Example Response:

{
    "name": "Promotion Demo REST API Service",
    "version": "1.0",
    "paths": "<URL for listing promotions>"
}

2. Create Promotion


3. Delete Promotion


4. Update Promotion


5. List All Promotions


6. Retrieve a Specific Promotion


Action Routes

7. Apply Promotion

8. Cancel Promotion


License

Copyright (c) John Rofrano. All rights reserved.

Licensed under the Apache License. See LICENSE

This repository is part of the NYU masters class: CSCI-GA.2820-001 DevOps and Agile Methodologies created and taught by John Rofrano, Adjunct Instructor, NYU Courant Institute, Graduate Division, Computer Science, and NYU Stern School of Business.