Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions Homeworks/05 Упаковка в docker/src/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Общие системные файлы
.gitignore
.idea
.vscode
.vs
bin
obj
*.sqlite

# Docker и окружение
docker/volumes/
docker/.env*
docker-compose*.yml

# Не тянем тесты в образ
PromoCodeFactory.UnitTests/

# Исключаем локальные publish-артефакты (если есть)
publish/
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public static void AddEfDataAccess(this IServiceCollection services)
{
services.AddDbContext<PromoCodeFactoryDbContext>((sp, builder) =>
{
var conncetionString = sp.GetRequiredService<IConfiguration>().GetConnectionString("PromocodeFactoryDb")
?? "Filename=PromoCodeFactory.sqlite";
builder.UseSqlite(conncetionString);
var connectionString = sp.GetRequiredService<IConfiguration>().GetConnectionString("Default")
?? throw new NotSupportedException("ConnectionStrings:Default not set");
builder.UseSqlite(connectionString);
});

services.AddScoped<IRepository<Employee>, EmployeeEfRepository>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
}
},
"ConnectionStrings": {
"PromocodeFactoryDb": "Filename=PromoCodeFactory.sqlite"
"Default": "Filename=PromoCodeFactory.sqlite"
},
"AllowedHosts": "*"
}
10 changes: 10 additions & 0 deletions Homeworks/05 Упаковка в docker/src/docker/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
ASPNETCORE_ENVIRONMENT=Development
HTTP_PORT_EXT=8091
HTTP_PORT_INT=8080

SQL_LITE_PATH=/webhost/db
SQL_LITE_NAME=PromoCodeFactory.sqlite

# Внутри контейнера используется своя собственная сеть
# в контейнере свой <ConnectionStrings__Default> (перекрывает appsettings.Development.json)
# см. docker-compose.yml
25 changes: 25 additions & 0 deletions Homeworks/05 Упаковка в docker/src/docker/HW05.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# build
FROM mcr.microsoft.com/dotnet/sdk:10.0 AS build

WORKDIR /src
# сначала только csproj — лучше кэшируется (все зависимые проекты тоже)
COPY ./PromoCodeFactory.Core/PromoCodeFactory.Core.csproj ./PromoCodeFactory.Core/
COPY ./PromoCodeFactory.DataAccess/PromoCodeFactory.DataAccess.csproj ./PromoCodeFactory.DataAccess/
COPY ./PromoCodeFactory.WebHost/PromoCodeFactory.WebHost.csproj ./PromoCodeFactory.WebHost/

RUN dotnet restore ./PromoCodeFactory.WebHost/PromoCodeFactory.WebHost.csproj

# теперь весь код
COPY ./PromoCodeFactory.Core/ ./PromoCodeFactory.Core/
COPY ./PromoCodeFactory.DataAccess/ ./PromoCodeFactory.DataAccess/
COPY ./PromoCodeFactory.WebHost/ ./PromoCodeFactory.WebHost/

RUN dotnet publish ./PromoCodeFactory.WebHost -c Release -o /app/publish

# run
FROM mcr.microsoft.com/dotnet/aspnet:10.0 AS final
WORKDIR /app
COPY --from=build /app/publish ./
ARG API_PORT_INT
EXPOSE ${API_PORT_INT}
ENTRYPOINT ["dotnet","PromoCodeFactory.WebHost.dll"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: promocode-factory

services:
promocode-factory-api:
build:
context: ..
dockerfile: docker/HW05.Dockerfile
args:
API_PORT_INT: ${HTTP_PORT_INT}
env_file:
- .env
volumes:
- sqlite-data:${SQL_LITE_PATH}
environment:
# перекрывает appsettings.Development.json:
ConnectionStrings__Default: "Filename=${SQL_LITE_PATH}/${SQL_LITE_NAME}"
ASPNETCORE_ENVIRONMENT: ${ASPNETCORE_ENVIRONMENT}
ASPNETCORE_HTTP_PORTS: "${HTTP_PORT_INT}"
ports:
- "${HTTP_PORT_EXT}:${HTTP_PORT_INT}"

volumes:
sqlite-data:
name: db