File tree 5 files changed +60
-17
lines changed 5 files changed +60
-17
lines changed Original file line number Diff line number Diff line change 1
1
PROJECT_NAME = entity-framework-example
2
2
3
+ # DotNet
4
+ DOTNET_TAG = 7.0
5
+ DOTNET_PORT = 5001
6
+
3
7
# Postgres
4
8
POSTGRES_TAG = 15.1
5
9
DB_NAME = $PROJECT_NAME
@@ -16,3 +20,6 @@ ADMINER_PORT=8080
16
20
# SQLite Browser
17
21
SQLITE_BROWSER_TAG = 3.12.2
18
22
SQLITE_BROWSER_PORT = 3000
23
+
24
+ # Database
25
+ DB = postgres
Original file line number Diff line number Diff line change
1
+ ARG DOTNET_TAG
2
+ ARG DB
3
+
4
+ FROM mcr.microsoft.com/dotnet/sdk:${DOTNET_TAG} AS build-env
5
+ WORKDIR /App
6
+
7
+ # Copy everything
8
+ COPY . ./
9
+ # Restore as distinct layers
10
+ RUN dotnet restore
11
+ # Build and publish a release
12
+ RUN dotnet publish -c Release -o out
13
+
14
+ # Build runtime image
15
+ FROM mcr.microsoft.com/dotnet/aspnet:${DOTNET_TAG}
16
+ WORKDIR /App
17
+ COPY --from=build-env /App/out .
18
+
19
+ # EXPOSE 5001
20
+ EXPOSE 80
21
+ ENTRYPOINT ["dotnet" , "EntityFrameworkExample.dll" ]
Original file line number Diff line number Diff line change 25
25
) ;
26
26
}
27
27
28
-
29
28
var app = builder . Build ( ) ;
30
29
31
- if ( app . Environment . IsDevelopment ( ) )
30
+ app . UseSwagger ( ) ;
31
+
32
+ app . UseSwaggerUI ( options =>
33
+ {
34
+ options . SwaggerEndpoint ( "/swagger/v1/swagger.json" , "v1" ) ;
35
+ options . RoutePrefix = string . Empty ;
36
+ } ) ;
37
+
38
+ using ( var scope = app . Services . CreateScope ( ) )
32
39
{
33
- app . UseSwagger ( ) ;
34
-
35
- app . UseSwaggerUI ( options =>
36
- {
37
- options . SwaggerEndpoint ( "/swagger/v1/swagger.json" , "v1" ) ;
38
- options . RoutePrefix = string . Empty ;
39
- } ) ;
40
-
41
- using ( var scope = app . Services . CreateScope ( ) )
42
- {
43
- var entityContext = scope . ServiceProvider . GetRequiredService < EntityContext > ( ) ;
44
- entityContext . Database . EnsureDeleted ( ) ;
45
- entityContext . Database . EnsureCreated ( ) ;
46
- entityContext . Seed ( ) ;
47
- }
40
+ var entityContext = scope . ServiceProvider . GetRequiredService < EntityContext > ( ) ;
41
+ entityContext . Database . EnsureDeleted ( ) ;
42
+ entityContext . Database . EnsureCreated ( ) ;
43
+ entityContext . Seed ( ) ;
48
44
}
49
45
50
46
// Configure the HTTP request pipeline.
Original file line number Diff line number Diff line change 5
5
"Microsoft.AspNetCore" : " Warning"
6
6
}
7
7
},
8
+ "ConnectionStrings" : {
9
+ "postgres" : " Server=postgres;Database=entity-framework-example;User Id=user;Password=pass" ,
10
+ "sqlite" : " Data Source=entity.db"
11
+ },
8
12
"AllowedHosts" : " *"
9
13
}
Original file line number Diff line number Diff line change @@ -2,6 +2,21 @@ version: "3.7"
2
2
3
3
services :
4
4
5
+ # app:
6
+ # image: mcr.microsoft.com/dotnet/sdk:${DOTNET_TAG}
7
+ # hostname: app
8
+ # stop_grace_period: 60s
9
+ # restart: always
10
+ # environment:
11
+ # DB: $DB
12
+ # build:
13
+ # context: ./EntityFrameworkExample
14
+ # args:
15
+ # DB: $DB
16
+ # DOTNET_TAG: $DOTNET_TAG
17
+ # ports:
18
+ # - ${DOTNET_PORT}:80
19
+
5
20
postgres :
6
21
image : " postgres:${POSTGRES_TAG}"
7
22
container_name : " ${PROJECT_NAME}-postgres"
You can’t perform that action at this time.
0 commit comments