diff --git a/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/.env b/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/.env new file mode 100755 index 0000000..bc83e83 --- /dev/null +++ b/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/.env @@ -0,0 +1,6 @@ +MSSQL_HOST=mssql_server_local # must be mssql_server_local service defined in mssql/docker-compose.yml +MSSQL_PORT=1433 +MSSQL_DB=app_pizza +MSSQL_SA_PASSWORD=example_123 +MSSQL_SA_USER=sa +ACCEPT_EULA=Y \ No newline at end of file diff --git a/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/.gitignore b/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/.gitignore new file mode 100644 index 0000000..9710047 --- /dev/null +++ b/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/.gitignore @@ -0,0 +1 @@ +mssql_server_local \ No newline at end of file diff --git a/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/docker-compose.yml b/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/docker-compose.yml new file mode 100644 index 0000000..7d55647 --- /dev/null +++ b/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/docker-compose.yml @@ -0,0 +1,52 @@ +volumes: + # the name of a volume to be used to store the database folder + # the same is used at "- ./app_x_mssql_data:/var/lib/mssql" + app_pizza_mssql_data: + driver: local +services: + initialize-database: + image: mcr.microsoft.com/mssql-tools:latest + container_name: initialize-database + restart: no + command: "/opt/mssql-tools/bin/sqlcmd -C -S ${MSSQL_HOST} -U ${MSSQL_SA_USER} -P ${MSSQL_SA_PASSWORD} -i /tmp/mssql-init.sql" + depends_on: + mssql_server_local: + condition: service_healthy + volumes: + - ./mssql/mssql-init.sql:/tmp/mssql-init.sql + env_file: + - .env + + mssql_server_local: + image: mcr.microsoft.com/mssql/server + container_name: mssql_server_local + restart: always + ports: + - ${MSSQL_PORT}:1433 + expose: + # Opens port 3306 on the container + - ${MSSQL_PORT} + env_file: + - .env + volumes: + # the location of the database folder + - ./mssql_server_local:/var/opt/mssql + healthcheck: + test: + [ + "CMD-SHELL", + "/opt/mssql-tools18/bin/sqlcmd -C -S localhost -U ${MSSQL_SA_USER} -P ${MSSQL_SA_PASSWORD} -Q 'SELECT 1' || exit 1", + ] + interval: 10s + retries: 10 + start_period: 10s + timeout: 3s + + app_pizza: + container_name: app_pizza + build: + context: ./pizza_shop/ + dockerfile: ./Dockerfile.dev + depends_on: + mssql_server_local: + condition: service_healthy diff --git a/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/mssql/mssql-init.sql b/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/mssql/mssql-init.sql new file mode 100644 index 0000000..81bcb68 --- /dev/null +++ b/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/mssql/mssql-init.sql @@ -0,0 +1,3 @@ +DROP DATABASE IF EXISTS app_pizza_shop + +CREATE DATABASE app_pizza_shop \ No newline at end of file diff --git a/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/mssql/start_system.sh b/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/mssql/start_system.sh new file mode 100755 index 0000000..c0bf239 --- /dev/null +++ b/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/mssql/start_system.sh @@ -0,0 +1,3 @@ +echo "Starting up the sytem. Please wait until the script confirms the system is running." +docker compose up -d +echo "The System is now ready." \ No newline at end of file diff --git a/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/mssql/stop_system.sh b/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/mssql/stop_system.sh new file mode 100755 index 0000000..2927f26 --- /dev/null +++ b/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/mssql/stop_system.sh @@ -0,0 +1,3 @@ +echo "Stopping the sytem. Please wait until the script confirms the system is switch off." +docker compose down +echo "The System has shutdown. Come again soon! :)" \ No newline at end of file diff --git a/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/Dockerfile.dev b/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/pizza_shop/Dockerfile.dev similarity index 50% rename from ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/Dockerfile.dev rename to ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/pizza_shop/Dockerfile.dev index dbf2d47..8f9047b 100644 --- a/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/Dockerfile.dev +++ b/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/pizza_shop/Dockerfile.dev @@ -1,5 +1,11 @@ FROM mcr.microsoft.com/devcontainers/dotnet:8.0 +WORKDIR /pizza_shop + +COPY . . + RUN dotnet tool install --global dotnet-ef --version 8.0.0 -ENV PATH="$PATH:/root/.dotnet/tools" \ No newline at end of file +ENV PATH="$PATH:/root/.dotnet/tools" + +ENTRYPOINT [ "./entry_point.dev.sh" ] \ No newline at end of file diff --git a/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/pizza_shop/entry_point.dev.sh b/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/pizza_shop/entry_point.dev.sh new file mode 100755 index 0000000..a3509d5 --- /dev/null +++ b/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/pizza_shop/entry_point.dev.sh @@ -0,0 +1,4 @@ +#!/bin/sh +dotnet ef database update + +dotnet run \ No newline at end of file diff --git a/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/pizza_shop/src/Data/PizzaShopContext.cs b/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/pizza_shop/src/Data/PizzaShopContext.cs index e92ef2e..88e86ae 100644 --- a/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/pizza_shop/src/Data/PizzaShopContext.cs +++ b/ecosystem/database/4_experiments/4_applications/entity_framework_core/pizza_shop/pizza_shop/src/Data/PizzaShopContext.cs @@ -20,6 +20,6 @@ public class PizzaShopContext : DbContext protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { // Never hard code in PROD of-course - optionsBuilder.UseSqlServer("Server=localhost,1433; Database=PizzaShop; User Id=sa; Password=example_123; Encrypt=false; TrustServerCertificate=true; MultipleActiveResultSets=true;"); + optionsBuilder.UseSqlServer("Server=mssql_server_local,1433; Database=app_pizza_shop; User Id=sa; Password=example_123; Encrypt=false; TrustServerCertificate=true; MultipleActiveResultSets=true;"); } } \ No newline at end of file diff --git a/todo.txt b/todo.txt index 75b25b0..b026480 100644 --- a/todo.txt +++ b/todo.txt @@ -82,6 +82,7 @@ - .NET: - readings: + - https://learn.microsoft.com/en-us/dotnet/fundamentals/ - ecosystem/0_dotnet.txt - course schedule: -