Skip to content

Commit

Permalink
Merge pull request #11 from montymi/f/docker
Browse files Browse the repository at this point in the history
Containerizing LazyGrocer for better MySQL support
  • Loading branch information
montymi authored Dec 23, 2024
2 parents a7d1cdc + 4bf9af9 commit bcda49f
Show file tree
Hide file tree
Showing 60 changed files with 1,405 additions and 140 deletions.
7 changes: 7 additions & 0 deletions .env.copy
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Database Configuration
MYSQL_HOST=db
MYSQL_PORT=3306
MYSQL_USER=root
MYSQL_PASSWORD=
MYSQL_DATABASE=lazygrocer
MYSQL_ROOT_PASSWORD=
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: ${{ secrets.MYSQL_PASSWORD }}
MYSQL_DATABASE: testgrocer
MYSQL_DATABASE: lazygrocer
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
Expand Down
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
__pycache__

# virtual environment
env/
.lg-venv-win
.lg-venv

# environment variables
.env
56 changes: 56 additions & 0 deletions .test/gui.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import curses

# Sample data - list of recipes and ingredients
recipes = [
{"name": "Spaghetti Carbonara", "ingredients": ["spaghetti", "eggs", "bacon", "parmesan cheese"]},
{"name": "Chicken Curry", "ingredients": ["chicken", "curry sauce", "rice", "onion", "garlic"]},
{"name": "Caesar Salad", "ingredients": ["romaine lettuce", "croutons", "parmesan cheese", "caesar dressing"]}
]

# Function to draw the header
def draw_header(stdscr):
stdscr.addstr(0, 0, "Recipe List - Commands: [A]dd [E]dit [D]elete [Q]uit")
stdscr.refresh()

# Function to draw the list of recipes
def draw_recipes(stdscr, selected_row):
stdscr.clear()
draw_header(stdscr)
for i, recipe in enumerate(recipes):
x = 2
y = i + 2
if i == selected_row:
stdscr.attron(curses.color_pair(1))
stdscr.addstr(y, x, f"{recipe['name']}")
stdscr.attroff(curses.color_pair(1))
else:
stdscr.addstr(y, x, f"{recipe['name']}")
stdscr.refresh()

# Function to handle user input
def main(stdscr):
# Initialize color pair for selected row
curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_WHITE)
# Turn off cursor display
curses.curs_set(0)
# Set up keyboard input
stdscr.keypad(True)

current_row = 0
draw_recipes(stdscr, current_row)

while True:
key = stdscr.getch()
stdscr.clear()

if key == curses.KEY_UP and current_row > 0:
current_row -= 1
elif key == curses.KEY_DOWN and current_row < len(recipes) - 1:
current_row += 1
elif key == ord('q'):
break

draw_recipes(stdscr, current_row)

curses.wrapper(main)

43 changes: 43 additions & 0 deletions build.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#0 building with "desktop-linux" instance using docker driver

#1 [app internal] load build definition from dockerfile
#1 transferring dockerfile: 920B done
#1 DONE 0.0s

#2 [app internal] load metadata for docker.io/library/python:3.10-slim
#2 DONE 0.2s

#3 [app internal] load .dockerignore
#3 transferring context: 2B done
#3 DONE 0.0s

#4 [app 1/6] FROM docker.io/library/python:3.10-slim@sha256:61912260e578182d00b5e163eb4cfb13b35fb8782c98d1df9ed584cec8939097
#4 DONE 0.0s

#5 [app internal] load build context
#5 transferring context: 7.65kB done
#5 DONE 0.0s

#6 [app 5/6] RUN pip install --no-cache-dir --upgrade pip && pip install --no-cache-dir -r requirements.txt
#6 CACHED

#7 [app 4/6] COPY requirements.txt /src/
#7 CACHED

#8 [app 3/6] RUN apt-get update && apt-get install -y --no-install-recommends default-libmysqlclient-dev build-essential && rm -rf /var/lib/apt/lists/*
#8 CACHED

#9 [app 2/6] WORKDIR /src
#9 CACHED

#10 [app 6/6] COPY src/ /src/
#10 CACHED

#11 [app] exporting to image
#11 exporting layers done
#11 writing image sha256:64875579faab298182143c44f6219647aba0fbab3f2c814260866b1cee3443c3 done
#11 naming to docker.io/library/lazygrocer-app done
#11 DONE 0.0s

#12 [app] resolving provenance for metadata file
#12 DONE 0.0s
34 changes: 34 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
services:
app:
build:
context: .
ports:
- "8000:8000"
environment:
MYSQL_HOST: db
MYSQL_USER: root
MYSQL_PASSWORD: lg-db-pd
MYSQL_DATABASE: lazygrocer
depends_on:
db:
condition: service_healthy

db:
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: lg-db-pd
MYSQL_DATABASE: lazygrocer
ports:
- "3306:3306"
volumes:
- lg-db-volume:/var/lib/mysql
- ./scripts:/docker-entrypoint-initdb.d
healthcheck:
test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
interval: 10s
timeout: 5s
retries: 3

volumes:
lg-db-volume:
driver: local
Binary file added demo.mov
Binary file not shown.
32 changes: 32 additions & 0 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM python:3.10-slim

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

# Set working directory in the container
WORKDIR /src

# Install system dependencies for MySQL client and MySQL server
RUN apt-get update && apt-get install -y --no-install-recommends \
default-libmysqlclient-dev build-essential && \
rm -rf /var/lib/apt/lists/*

# Copy only requirements to leverage Docker cache
COPY requirements.txt /src/

# Install Python dependencies
RUN pip install --no-cache-dir --upgrade pip && \
pip install --no-cache-dir -r requirements.txt

# Copy the application code to the container (only the src folder)
COPY src/ /src/

# Expose the port the app runs on (optional)
EXPOSE 8000

# Define a volume for persistent data
VOLUME /src/data

# Start MySQL service and run the application
CMD ["python", "./main.py"]
Binary file modified docs/diagrams/LazyGrozerERDdiagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 25 additions & 16 deletions docs/plantuml/erd.wsd
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,35 @@ footer CS3200 Final Project: Michael Montanaro 2024
object Recipe {
title <<PK>>
description
rating
meal_timing
favorite?
date_published
}

object Rating {
score
description
date_added
}

object Favorite {
date_added
description
}

object RecipeList {
name <<PK>>
description
}

object Instruction {
cook_time
prep_time
servings
calories
steps
url
}

object Step {
id <<PK>>
description
}

object Ingredient {
Expand All @@ -32,29 +44,26 @@ object Ingredient {
last_added
}

object IngredientList {
object GroceryList {
name <<PK>>
description
}

object Chef {
username <<pk>>
first_name
last_name
email
}

object includes {
quantity
}
diamond DIncludes
diamond stepdiamond

Rating }o--o| Recipe
Favorite }o--|| Recipe
Recipe }|-- DIncludes
DIncludes --|{ Ingredient: >
DIncludes . includes
Recipe }|-o{ RecipeList: contains <
Ingredient }|-o{ IngredientList: for <
Chef ||--o{ Recipe: publishes >
Instruction ||-|| Recipe: explains >
Ingredient }|-o{ GroceryList: for <
Instruction ||- stepdiamond
stepdiamond -|| Recipe: explains >
stepdiamond --|{ Step: describes <

@enduml
Loading

0 comments on commit bcda49f

Please sign in to comment.