Skip to content

Commit

Permalink
initial commit for adding docker to lg
Browse files Browse the repository at this point in the history
  • Loading branch information
montymi committed Dec 3, 2024
1 parent a7d1cdc commit d5c9625
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 7 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=user
MYSQL_PASSWORD=password
MYSQL_DATABASE=lazygrocer_db
MYSQL_ROOT_PASSWORD=rootpassword
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
38 changes: 38 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
version: '3.8'

services:
app:
build: .
container_name: lazygrocer_app
ports:
- "8000:8000"
env_file:
- .env
environment:
MYSQL_HOST: ${MYSQL_HOST}
MYSQL_PORT: ${MYSQL_PORT}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
depends_on:
- db
volumes:
- .:/src

db:
image: mysql:8.0
container_name: lazygrocer_db
env_file:
- .env
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
ports:
- "3306:3306"
volumes:
- db_data:/var/lib/mysql

volumes:
db_data:
27 changes: 27 additions & 0 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use an official Python runtime as a parent image
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
RUN apt-get update && apt-get install -y --no-install-recommends \
default-libmysqlclient-dev build-essential && \
rm -rf /var/lib/apt/lists/*

# Copy the application code to the container
COPY . /src/

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

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

# Command to run the application
CMD ["python", "src/main.py"]
Empty file added src/artifacts/recipe.db
Empty file.
5 changes: 1 addition & 4 deletions src/main.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
import logging
import argparse

from controller.dataControllerv2 import DataController2 as DataController
from controller.dataController import DataController as DataController

def main(db):
db.connect()
print("HI")
db.disconnect()
print(type(db))

if __name__ == '__main__':
Expand Down
3 changes: 1 addition & 2 deletions src/scripts/init.sql
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
DROP DATABASE lazygrocer;
CREATE DATABASE IF NOT EXISTS lazygrocer;
CREATE DATABASE lazygrocer;
use lazygrocer;

-- tables
Expand Down

0 comments on commit d5c9625

Please sign in to comment.