Merge pull request #61 from zhangxd6/master

update workshop to dotnet 6
This commit is contained in:
Ajeet Singh Raina, Docker Captain, ARM Innovator, RedisInc 2021-11-22 13:59:32 +05:30 коммит произвёл GitHub
Родитель cb1fb1d619 a3ecee1f6e
Коммит 9ec0251c4e
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 61 добавлений и 40 удалений

Просмотреть файл

@ -98,21 +98,8 @@ namespace myWebApp.Data
}
```
4. Regsister SchoolContext to DI in Startup.cs
```
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<myWebApp.Data.SchoolContext>(options =>
options.UseNpgsql(Configuration.GetConnectionString("SchoolContext")));
services.AddRazorPages();
}
```
5. Adding database connectionstring to appsettings.json
4. Adding database connectionstring to appsettings.json
```
{
@ -129,33 +116,42 @@ namespace myWebApp.Data
}
}
```
6. Boostrap the table if it does not exist in Program.cs
5. Boostrap the table if it does not exist in Program.cs
```
public static void Main(string[] args)
{
var host= CreateHostBuilder(args).Build();
CreateDbIfNotExists(host);
host.Run();
}
private static void CreateDbIfNotExists(IHost host)
{
using (var scope = host.Services.CreateScope())
{
var services = scope.ServiceProvider;
try
{
var context = services.GetRequiredService<Data.SchoolContext>();
context.Database.EnsureCreated();
// DbInitializer.Initialize(context);
}
catch (Exception ex)
{
var logger = services.GetRequiredService<ILogger<Program>>();
logger.LogError(ex, "An error occurred creating the DB.");
}
}
}
using Microsoft.EntityFrameworkCore;
var builder = WebApplication.CreateBuilder(args);
// Add services to the container.
builder.Services.AddRazorPages();
builder.Services.AddDbContext<myWebApp.Data.SchoolContext>(options =>
options.UseNpgsql(builder.Configuration.GetConnectionString("SchoolContext")));
var app = builder.Build();
using (var scope = app.Services.CreateScope())
{
var services = scope.ServiceProvider;
var context = services.GetRequiredService<myWebApp.Data.SchoolContext>();
context.Database.EnsureCreated();
// DbInitializer.Initialize(context);
}
// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Error");
}else{
// app.UseDeveloperExceptionPage();
}
app.UseStaticFiles();
app.UseRouting();
app.UseAuthorization();
app.MapRazorPages();
app.Run();
```
let update the UI
@ -341,7 +337,7 @@ now open another tab with address http://localhost:8080 and you will be asked to
![login](adminerlogin.png)
use **postegres** and **example** as username/passowrd to login my_db.
use **postgres** and **example** as username/passowrd to login my_db.
once you are logged in, you can create a new student record

Просмотреть файл

@ -166,3 +166,28 @@ The path to an application .dll file to execute.
{{< /tabs >}}
# Using image for the workshop
You can use the workshop image based in dind (docker in docker), dotnet and openvscode to buddle docker, dotnet and vscode editor in a package.
1. pull the image
```
docker pull ghcr.io/zhangxd6/dockerfornetworkshop:main
```
2. start the workshop
```
docker run -p 3000:3000 -p 5027:5027 -p 5000:5000 -p 8080:8080 --privileged -v "$(pwd):/home/workspace:cached" ghcr.io/zhangxd6/dockerfornetworkshop:main
```
3. access the vscode server
you will have to check the container log to find the url with token like
```
Web UI available at http://localhost:3000/?tkn=ed93033e-e343-4e52-840a-8a7560de8c11
```
4. Once you open the vscode, you should be able to access the instruction.md buddled in image and intergated termial for the workshop