-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from montymi/f/docker
Containerizing LazyGrocer for better MySQL support
- Loading branch information
Showing
60 changed files
with
1,405 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,8 @@ | |
__pycache__ | ||
|
||
# virtual environment | ||
env/ | ||
.lg-venv-win | ||
.lg-venv | ||
|
||
# environment variables | ||
.env |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.