Skip to content

Commit 9a208c6

Browse files
committed
feat: add docker support and change database to sqlite
1 parent 27f681c commit 9a208c6

File tree

6 files changed

+57
-2
lines changed

6 files changed

+57
-2
lines changed

.dockerignore

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
**/.classpath
2+
**/.dockerignore
3+
**/.env
4+
**/.git
5+
**/.gitignore
6+
**/.project
7+
**/.settings
8+
**/.toolstarget
9+
**/.vs
10+
**/.vscode
11+
**/*.*proj.user
12+
**/*.dbmdl
13+
**/*.jfm
14+
**/azds.yaml
15+
**/bin
16+
**/charts
17+
**/docker-compose*
18+
**/Dockerfile*
19+
**/node_modules
20+
**/npm-debug.log
21+
**/obj
22+
**/secrets.dev.yaml
23+
**/values.dev.yaml
24+
LICENSE
25+
README.md

Dockerfile

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1-buster-slim AS base
2+
WORKDIR /app
3+
4+
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
5+
WORKDIR /src
6+
COPY ["src/SocialMediaDashboard.WebAPI/SocialMediaDashboard.WebAPI.csproj", "src/SocialMediaDashboard.WebAPI/"]
7+
COPY ["src/SocialMediaDashboard.Logic/SocialMediaDashboard.Logic.csproj", "src/SocialMediaDashboard.Logic/"]
8+
COPY ["src/SocialMediaDashboard.Data/SocialMediaDashboard.Data.csproj", "src/SocialMediaDashboard.Data/"]
9+
COPY ["src/SocialMediaDashboard.Domain/SocialMediaDashboard.Domain.csproj", "src/SocialMediaDashboard.Domain/"]
10+
COPY ["src/SocialMediaDashboard.Common/SocialMediaDashboard.Common.csproj", "src/SocialMediaDashboard.Common/"]
11+
RUN dotnet restore "src/SocialMediaDashboard.WebAPI/SocialMediaDashboard.WebAPI.csproj"
12+
COPY . .
13+
WORKDIR "/src/src/SocialMediaDashboard.WebAPI"
14+
RUN dotnet build "SocialMediaDashboard.WebAPI.csproj" -c Release -o /app/build
15+
16+
FROM build AS publish
17+
RUN dotnet publish "SocialMediaDashboard.WebAPI.csproj" -c Release -o /app/publish
18+
19+
FROM base AS final
20+
WORKDIR /app
21+
COPY --from=publish /app/publish .
22+
CMD ASPNETCORE_URLS=http://*:$PORT dotnet SocialMediaDashboard.WebAPI.dll

SocialMediaDashboard.sln

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SocialMediaDashboard.Integr
2323
EndProject
2424
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SocialMediaDashboard.Common", "src\SocialMediaDashboard.Common\SocialMediaDashboard.Common.csproj", "{E4EB9A44-A437-4302-AE49-F64EB809D111}"
2525
EndProject
26+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{67A61AB0-CC13-4459-A953-D86E134DBD3B}"
27+
ProjectSection(SolutionItems) = preProject
28+
Dockerfile = Dockerfile
29+
README.md = README.md
30+
EndProjectSection
31+
EndProject
2632
Global
2733
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2834
Debug|Any CPU = Debug|Any CPU

src/SocialMediaDashboard.Data/Extensions/DataServiceCollectionExtension.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public static class DataServiceCollectionExtension
2020
/// <returns>Service collection.</returns>
2121
public static IServiceCollection AddData(this IServiceCollection services, IConfiguration configuration)
2222
{
23-
services.AddDbContext<ApplicationContext>(options => options.UseSqlServer(configuration.GetConnectionString("DefaultConnection")));
23+
services.AddDbContext<ApplicationContext>(options => options.UseSqlite(configuration.GetConnectionString("SQLiteConnection")));
2424
services.AddScoped(typeof(IRepository<>), typeof(Repository<>));
2525

2626
return services;

src/SocialMediaDashboard.Data/SocialMediaDashboard.Data.csproj

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<ItemGroup>
88
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="3.1.3" />
9+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.3" />
910
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.3" />
1011
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.1.3">
1112
<PrivateAssets>all</PrivateAssets>

src/SocialMediaDashboard.WebAPI/appsettings.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"ConnectionStrings": {
3-
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=SocialMediaDashboardApp;Trusted_Connection=True;MultipleActiveResultSets=true"
3+
"DefaultConnection": "Server=db;Database=SocialMediaDashboardApp;User=sa;Password=Your_password123;Trusted_Connection=False;MultipleActiveResultSets=true",
4+
"SQLiteConnection": "Filename=SocialMediaDashboardApp.db"
45
},
56
"AppSettings": {
67
"Secret": "3ce1637ed40041cd94d4853d3e766c4d"

0 commit comments

Comments
 (0)