From e5b871c275ba33fb3af2e22086b2dab3a7f8c3c8 Mon Sep 17 00:00:00 2001 From: surtur Date: Sun, 6 Dec 2020 04:46:36 +0100 Subject: [PATCH 01/11] chore: adding postgre support [wip - batch 1] --- Models/Carousel.cs | 12 +++++++++++ Models/Database/CarouselHelper.cs | 20 +++++++++++++++++ Models/Database/DBContext.cs | 17 +++++++++++++++ Models/Database/DBInit.cs | 24 +++++++++++++++++++++ Program.cs | 13 ++++++++++- Startup.cs | 10 +++++++++ appsettings.Development.json | 4 ++++ appsettings.json | 4 ++++ docker-compose.yml | 36 +++++++++++++++++++++++++++++++ pwt-0x01-ng.csproj | 3 +++ 10 files changed, 142 insertions(+), 1 deletion(-) create mode 100644 Models/Database/CarouselHelper.cs create mode 100644 Models/Database/DBContext.cs create mode 100644 Models/Database/DBInit.cs create mode 100644 docker-compose.yml diff --git a/Models/Carousel.cs b/Models/Carousel.cs index 8ab87f3..f61d0b7 100644 --- a/Models/Carousel.cs +++ b/Models/Carousel.cs @@ -1,14 +1,26 @@ using Microsoft.AspNetCore.Http; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; namespace pwt_0x01_ng.Models { + [Table("Carousel")] public class Carousel { + [Key] + [Required] public int id { get; set; } + [Required] public string DataTarget { get; set; } + [NotMapped] public IFormFile Image { get; set; } + [Required] + [StringLength(255)] public string ImageSrc { get; set; } + [Required] + [StringLength(50)] public string ImageAlt { get; set; } + [Required] public string CarouselContent { get; set; } } } diff --git a/Models/Database/CarouselHelper.cs b/Models/Database/CarouselHelper.cs new file mode 100644 index 0000000..29f11e9 --- /dev/null +++ b/Models/Database/CarouselHelper.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; +using Microsoft.IdentityModel.Tokens; + +namespace pwt_0x01_ng.Models.Database +{ + public static class CarouselHelper + { + public static IList GenerateCarousel() + { + IList carousels = new List() + { + new Carousel() { DataTarget = "#myCarousel", ImageSrc = "/images/banner1.svg", ImageAlt = "ASP.NET", CarouselContent = "Learn how to build ASP.NET apps that can run anywhere.Learn More"}, + new Carousel() { DataTarget = "#myCarousel", ImageSrc = "/images/banner2.svg", ImageAlt = "ASP.NET", CarouselContent = "There are powerful new features in Visual Studio for building modern web apps.Learn More"}, + new Carousel() { DataTarget = "#myCarousel", ImageSrc = "/images/banner3.svg", ImageAlt = "ASP.NET", CarouselContent = "Learn how Microsoft's Azure cloud platform allows you to build, deploy, and scale web apps.Learn More"}, + new Carousel() { DataTarget = "#myCarousel", ImageSrc = "/images/ms_loves_linux.jpeg", ImageAlt = "msloveslinux", CarouselContent = "ms loves linux"} + }; + return carousels; + } + } +} diff --git a/Models/Database/DBContext.cs b/Models/Database/DBContext.cs new file mode 100644 index 0000000..59bd568 --- /dev/null +++ b/Models/Database/DBContext.cs @@ -0,0 +1,17 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Npgsql.EntityFrameworkCore; +using pwt_0x01_ng.Models; + +namespace pwt0x01ng.Models.Database +{ + public class DBContext : DbContext + { + public DBContext(DbContextOptions options) : base(options) + { + + } + + public DbSet Carousel { get; set; } + } +} diff --git a/Models/Database/DBInit.cs b/Models/Database/DBInit.cs new file mode 100644 index 0000000..29babac --- /dev/null +++ b/Models/Database/DBInit.cs @@ -0,0 +1,24 @@ +using System; +using pwt_0x01_ng.Models.Database; +using System.Collections.Generic; +using pwt_0x01_ng.Models; + +namespace pwt0x01ng.Models.Database +{ + public static class DBInit + { + + public static void Init(DBContext dbContext) + { + if (dbContext.Database.EnsureCreated()) + { + IList carousels = CarouselHelper.GenerateCarousel(); + foreach (var c in carousels) + { + dbContext.Carousel.Add(c); + } + dbContext.SaveChanges(); + } + } + } +} diff --git a/Program.cs b/Program.cs index 511bd07..58c7700 100644 --- a/Program.cs +++ b/Program.cs @@ -6,7 +6,9 @@ using System.Threading.Tasks; using Microsoft.AspNetCore; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using pwt0x01ng.Models.Database; namespace pwt_0x01_ng { @@ -14,7 +16,16 @@ namespace pwt_0x01_ng { public static void Main(string[] args) { - CreateWebHostBuilder(args).Build().Run(); + IWebHost webHost = CreateWebHostBuilder(args).Build(); + + using (var scope = webHost.Services.CreateScope()) + { + var serviceProvider = scope.ServiceProvider; + var dbctx = serviceProvider.GetRequiredService(); + DBInit.Init(dbctx); + } + + webHost.Run(); } public static IWebHostBuilder CreateWebHostBuilder(string[] args) => diff --git a/Startup.cs b/Startup.cs index 02bc2c9..b1a655d 100644 --- a/Startup.cs +++ b/Startup.cs @@ -10,6 +10,8 @@ using Microsoft.AspNetCore.HttpsPolicy; using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using pwt0x01ng.Models.Database; +using Microsoft.EntityFrameworkCore; namespace pwt_0x01_ng { @@ -35,6 +37,14 @@ namespace pwt_0x01_ng }); + var connectionString = Environment.GetEnvironmentVariable("DB_CONNECTION_STRING"); + services.AddDbContext(options => + options.UseNpgsql( + connectionString + ) + ); + + services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); } diff --git a/appsettings.Development.json b/appsettings.Development.json index e203e94..5bded5d 100644 --- a/appsettings.Development.json +++ b/appsettings.Development.json @@ -1,4 +1,8 @@ { + "db": { + "Postgre": "host=db,port=5432,database=pwt;username=postgres;password=679968312e029a806c1905c40ec331aa199a1eb86bd0b9eb04057933e449bdc9ef8ef292a39b68cafa5689c901a17266", + "MySQL": "server=db,Database=pwt-0x01-ng;Port=3306;user=root;password=679968312e029a806c1905c40ec331aa199a1eb86bd0b9eb04057933e449bdc9ef8ef292a39b68cafa5689c901a17266;" + }, "Logging": { "LogLevel": { "Default": "Debug", diff --git a/appsettings.json b/appsettings.json index def9159..fa752eb 100644 --- a/appsettings.json +++ b/appsettings.json @@ -1,4 +1,8 @@ { + "db": { + "Postgre": "host=db,port=5432;database=pwt;username=postgres;password=679968312e029a806c1905c40ec331aa199a1eb86bd0b9eb04057933e449bdc9ef8ef292a39b68cafa5689c901a17266", + "MySQL": "server=db,Database=pwt-0x01-ng;Port=3306;user=root;password=679968312e029a806c1905c40ec331aa199a1eb86bd0b9eb04057933e449bdc9ef8ef292a39b68cafa5689c901a17266;" + }, "Logging": { "LogLevel": { "Default": "Warning" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..fd07a3f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,36 @@ +version: '3.8' + +services: + netcoreultimateapp-dev: + build: + context: . + dockerfile: Dockerfile.dev + ports: + - 127.0.0.1:8001:5000 + environment: + ASPNETCORE_ENVIRONMENT: Development + DB_CONNECTION_STRING: "host=db,port=5432;database=pwt;username=postgres;password=679968312e029a806c1905c40ec331aa199a1eb86bd0b9eb04057933e449bdc9ef8ef292a39b68cafa5689c901a17266" + restart: always + cap_drop: + - NET_ADMIN + - SYS_ADMIN + depends_on: + - db + + db: + image: postgres:13.1-alpine + ports: + - 5432:5432 + volumes: + - dbdata:/var/lib/postgresql/data + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: 679968312e029a806c1905c40ec331aa199a1eb86bd0b9eb04057933e449bdc9ef8ef292a39b68cafa5689c901a17266 + POSTGRES_INITDB_ARGS: "--data-checksums" + restart: always + cap_drop: + - NET_ADMIN + - SYS_ADMIN + +volumes: + dbdata: diff --git a/pwt-0x01-ng.csproj b/pwt-0x01-ng.csproj index 1909d43..0868ab9 100644 --- a/pwt-0x01-ng.csproj +++ b/pwt-0x01-ng.csproj @@ -15,11 +15,14 @@ + + + -- 2.48.1 From 67561303a46836c83dd2d86cc45a0326135938c3 Mon Sep 17 00:00:00 2001 From: surtur Date: Tue, 15 Dec 2020 15:04:28 +0100 Subject: [PATCH 02/11] feat: move to framework version 3.1 * lots of pertaining changes * again solving global.json version mismatch with sed * correctly specify db creds via dc env --- .drone.yml | 15 +++++++++++++-- Areas/Admin/Controllers/CarouselController.cs | 4 ++-- Dockerfile | 8 ++++++-- Dockerfile.dev | 6 +++++- Models/Database/CarouselHelper.cs | 1 - Models/Dbfake/CarouselHelper.cs | 1 - Models/MegaUpload.cs | 4 ++-- README.md | 2 ++ Startup.cs | 10 +++++++--- docker-compose.yml | 3 ++- global.json | 2 +- pwt-0x01-ng.csproj | 8 +++----- 12 files changed, 43 insertions(+), 21 deletions(-) diff --git a/.drone.yml b/.drone.yml index 80461f8..b85f58e 100644 --- a/.drone.yml +++ b/.drone.yml @@ -8,16 +8,27 @@ platform: arch: amd64 steps: +- name: sed-tgt-version + pull: always + image: bash + commands: + - sed -i 's/3.1.110/3.1.404/' global.json + # since we're running 3.1.404 here in the CI, this is necessary + - name: debug pull: always - image: mcr.microsoft.com/dotnet/core/sdk:2.1-alpine + image: mcr.microsoft.com/dotnet/core/sdk:3.1-alpine + depends_on: + - sed-tgt-version commands: - dotnet restore - dotnet build . - name: release pull: always - image: mcr.microsoft.com/dotnet/core/sdk:2.1-alpine + image: mcr.microsoft.com/dotnet/core/sdk:3.1-alpine + depends_on: + - sed-tgt-version commands: - dotnet restore - dotnet publish -c Release -o out diff --git a/Areas/Admin/Controllers/CarouselController.cs b/Areas/Admin/Controllers/CarouselController.cs index e39ee15..261552e 100644 --- a/Areas/Admin/Controllers/CarouselController.cs +++ b/Areas/Admin/Controllers/CarouselController.cs @@ -13,10 +13,10 @@ namespace pwt_0x01_ng.Areas.Admin.Controllers [Area("Admin")] public class CarouselController : Controller { - IHostingEnvironment hosting_env; + IWebHostEnvironment hosting_env; private IList Carousels = Dbfake.Carousels; - public CarouselController(IHostingEnvironment hosting_env){ + public CarouselController(IWebHostEnvironment hosting_env){ this.hosting_env = hosting_env; } diff --git a/Dockerfile b/Dockerfile index 28de731..de287eb 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,17 @@ -FROM mcr.microsoft.com/dotnet/core/sdk:2.1-alpine +FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine WORKDIR /src +COPY global.json ./ +RUN sed -i 's/3.1.110/3.1.404/' global.json + COPY *.csproj ./ RUN dotnet restore COPY . ./ +RUN sed -i 's/3.1.110/3.1.404/' global.json RUN dotnet publish -c Release -o bin/out -FROM mcr.microsoft.com/dotnet/aspnet:2.1 +FROM mcr.microsoft.com/dotnet/aspnet:3.1 WORKDIR /App COPY --from=0 /src/bin/out/ . ENV ASPNETCORE_ENVIRONMENT=Release diff --git a/Dockerfile.dev b/Dockerfile.dev index 67fa996..f4bf0ac 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,10 +1,14 @@ -FROM mcr.microsoft.com/dotnet/core/sdk:2.1-alpine +FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine WORKDIR /src +COPY global.json ./ +RUN sed -i 's/3.1.110/3.1.404/' global.json + COPY *.csproj ./ RUN dotnet restore COPY . ./ +RUN sed -i 's/3.1.110/3.1.404/' global.json RUN dotnet build -c Debug -o bin/out ENV ASPNETCORE_ENVIRONMENT=Development diff --git a/Models/Database/CarouselHelper.cs b/Models/Database/CarouselHelper.cs index 29f11e9..39f6e43 100644 --- a/Models/Database/CarouselHelper.cs +++ b/Models/Database/CarouselHelper.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Microsoft.IdentityModel.Tokens; namespace pwt_0x01_ng.Models.Database { diff --git a/Models/Dbfake/CarouselHelper.cs b/Models/Dbfake/CarouselHelper.cs index 622d8ca..096d61a 100644 --- a/Models/Dbfake/CarouselHelper.cs +++ b/Models/Dbfake/CarouselHelper.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Microsoft.IdentityModel.Tokens; namespace pwt_0x01_ng.Models.Dbfake { diff --git a/Models/MegaUpload.cs b/Models/MegaUpload.cs index a690568..d3178b3 100644 --- a/Models/MegaUpload.cs +++ b/Models/MegaUpload.cs @@ -9,9 +9,9 @@ namespace pwt_0x01_ng.Models { public class MegaUpload { - IHostingEnvironment hosting_env; + IWebHostEnvironment hosting_env; - public MegaUpload(IHostingEnvironment hosting_env){ + public MegaUpload(IWebHostEnvironment hosting_env){ this.hosting_env = hosting_env; } public async Task DoMegaUpload(Carousel carousel) diff --git a/README.md b/README.md index 748c183..9519231 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,8 @@ this repo holds *sawce* for PWT .netcore mvc project 0x01-ng +> Note: app-3.1-migration branch + ### how to run this > run the following commands from the solution folder diff --git a/Startup.cs b/Startup.cs index b1a655d..1e4b47b 100644 --- a/Startup.cs +++ b/Startup.cs @@ -35,6 +35,10 @@ namespace pwt_0x01_ng options.HttpOnly = HttpOnlyPolicy.Always; options.Secure = CookieSecurePolicy.Always; }); + services.Configure(options => { + /* necessary due to a switch to 3.1 */ + options.EnableEndpointRouting = false; + }); var connectionString = Environment.GetEnvironmentVariable("DB_CONNECTION_STRING"); @@ -45,13 +49,13 @@ namespace pwt_0x01_ng ); - services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); + services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. - public void Configure(IApplicationBuilder app, IHostingEnvironment env) + public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { - if (env.IsDevelopment()) + if (env.EnvironmentName.Equals("Development")) { app.UseDeveloperExceptionPage(); } diff --git a/docker-compose.yml b/docker-compose.yml index fd07a3f..95b598d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,7 +9,7 @@ services: - 127.0.0.1:8001:5000 environment: ASPNETCORE_ENVIRONMENT: Development - DB_CONNECTION_STRING: "host=db,port=5432;database=pwt;username=postgres;password=679968312e029a806c1905c40ec331aa199a1eb86bd0b9eb04057933e449bdc9ef8ef292a39b68cafa5689c901a17266" + DB_CONNECTION_STRING: "User ID=postgres;Password=679968312e029a806c1905c40ec331aa199a1eb86bd0b9eb04057933e449bdc9ef8ef292a39b68cafa5689c901a17266;Server=db;Port=5432;Database=pwt;Integrated Security=true;Pooling=true;" restart: always cap_drop: - NET_ADMIN @@ -18,6 +18,7 @@ services: - db db: + container_name: 'db' image: postgres:13.1-alpine ports: - 5432:5432 diff --git a/global.json b/global.json index 0bd29c4..8afc0f0 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ { "sdk": { - "version": "2.1.811" + "version": "3.1.404" } } diff --git a/pwt-0x01-ng.csproj b/pwt-0x01-ng.csproj index 0868ab9..d47aecd 100644 --- a/pwt-0x01-ng.csproj +++ b/pwt-0x01-ng.csproj @@ -1,7 +1,7 @@ - netcoreapp2.1 + netcoreapp3.1 @@ -13,10 +13,8 @@ false - - - - + + -- 2.48.1 From 1489069c5c10ebf4bed9d528153ee7e5b4056a19 Mon Sep 17 00:00:00 2001 From: surtur Date: Tue, 15 Dec 2020 15:22:07 +0100 Subject: [PATCH 03/11] chore: update Makefile - add dcdevrun target * [skip ci] --- Makefile | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Makefile b/Makefile index fd88945..540f9e6 100644 --- a/Makefile +++ b/Makefile @@ -55,6 +55,12 @@ dockerdevrun: @echo ====================== $(dcmdrun) -p $(lportdev):5000 $(dtagdev) +dcdevrun: + @echo ====================== + @echo local dev port: $(lportdev) + @echo ====================== + docker-compose up --build --remove-orphans + kaniko: $(krelease) $(kdebug) -- 2.48.1 From 82d075dd01aa51110be186368f59c1b857f80147 Mon Sep 17 00:00:00 2001 From: surtur Date: Tue, 15 Dec 2020 22:47:08 +0100 Subject: [PATCH 04/11] feat: switch to rootless runs + refactor * build as root but run the container as UID/GID 1000 * db expose only on localhost * docker-compose mount $PWD for easy local debugging --- Dockerfile | 6 ++++++ Dockerfile.dev | 6 ++++++ docker-compose.yml | 4 +++- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index de287eb..51f7da3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,8 @@ FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine +ENV UID 1000 +ENV GID 1000 +ENV UNAME unpriv +RUN adduser -D -u ${UID} -g ${GID} -H ${UNAME} -h /src WORKDIR /src COPY global.json ./ @@ -14,5 +18,7 @@ RUN dotnet publish -c Release -o bin/out FROM mcr.microsoft.com/dotnet/aspnet:3.1 WORKDIR /App COPY --from=0 /src/bin/out/ . +RUN chown -R ${UID}:${GID} ./ +USER ${UNAME} ENV ASPNETCORE_ENVIRONMENT=Release ENTRYPOINT ["dotnet", "pwt-0x01-ng.dll"] diff --git a/Dockerfile.dev b/Dockerfile.dev index f4bf0ac..777491b 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -1,4 +1,8 @@ FROM mcr.microsoft.com/dotnet/core/sdk:3.1-alpine +ENV UID 1000 +ENV GID 1000 +ENV UNAME unpriv +RUN adduser -D -u ${UID} -g ${GID} -H ${UNAME} -h /src WORKDIR /src COPY global.json ./ @@ -10,6 +14,8 @@ RUN dotnet restore COPY . ./ RUN sed -i 's/3.1.110/3.1.404/' global.json RUN dotnet build -c Debug -o bin/out +RUN chown -R ${UID}:${GID} ./ /root/ +USER ${UNAME} ENV ASPNETCORE_ENVIRONMENT=Development diff --git a/docker-compose.yml b/docker-compose.yml index 95b598d..abdd17a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,6 +7,8 @@ services: dockerfile: Dockerfile.dev ports: - 127.0.0.1:8001:5000 + volumes: + - $PWD:/src environment: ASPNETCORE_ENVIRONMENT: Development DB_CONNECTION_STRING: "User ID=postgres;Password=679968312e029a806c1905c40ec331aa199a1eb86bd0b9eb04057933e449bdc9ef8ef292a39b68cafa5689c901a17266;Server=db;Port=5432;Database=pwt;Integrated Security=true;Pooling=true;" @@ -21,7 +23,7 @@ services: container_name: 'db' image: postgres:13.1-alpine ports: - - 5432:5432 + - 127.0.0.1:5432:5432 volumes: - dbdata:/var/lib/postgresql/data environment: -- 2.48.1 From 779c349ff61bf5b5070328096a132a71660eda8e Mon Sep 17 00:00:00 2001 From: surtur Date: Sat, 26 Dec 2020 17:02:24 +0100 Subject: [PATCH 05/11] chore: correct db creds format + mount local dir * ./ instead of $PWD means that the mounted folder is not where the command is run from but rather the folder local to the compose file * use proper db creds format --- appsettings.Development.json | 2 +- docker-compose.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/appsettings.Development.json b/appsettings.Development.json index 5bded5d..74513e4 100644 --- a/appsettings.Development.json +++ b/appsettings.Development.json @@ -1,6 +1,6 @@ { "db": { - "Postgre": "host=db,port=5432,database=pwt;username=postgres;password=679968312e029a806c1905c40ec331aa199a1eb86bd0b9eb04057933e449bdc9ef8ef292a39b68cafa5689c901a17266", + "Postgre": "User ID=postgres;Password=679968312e029a806c1905c40ec331aa199a1eb86bd0b9eb04057933e449bdc9ef8ef292a39b68cafa5689c901a17266;Server=db;Port=5432;Database=pwt;Integrated Security=true;Pooling=true;", "MySQL": "server=db,Database=pwt-0x01-ng;Port=3306;user=root;password=679968312e029a806c1905c40ec331aa199a1eb86bd0b9eb04057933e449bdc9ef8ef292a39b68cafa5689c901a17266;" }, "Logging": { diff --git a/docker-compose.yml b/docker-compose.yml index abdd17a..cccb07d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -8,7 +8,7 @@ services: ports: - 127.0.0.1:8001:5000 volumes: - - $PWD:/src + - ./:/src environment: ASPNETCORE_ENVIRONMENT: Development DB_CONNECTION_STRING: "User ID=postgres;Password=679968312e029a806c1905c40ec331aa199a1eb86bd0b9eb04057933e449bdc9ef8ef292a39b68cafa5689c901a17266;Server=db;Port=5432;Database=pwt;Integrated Security=true;Pooling=true;" -- 2.48.1 From 4fd5b9f4dedad5ec0d06174add07a6a1bac92388 Mon Sep 17 00:00:00 2001 From: surtur Date: Sat, 26 Dec 2020 17:05:31 +0100 Subject: [PATCH 06/11] chore: turn off the stupid banner for now --- Startup.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Startup.cs b/Startup.cs index 1e4b47b..9cea2fc 100644 --- a/Startup.cs +++ b/Startup.cs @@ -30,7 +30,7 @@ namespace pwt_0x01_ng services.Configure(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. - options.CheckConsentNeeded = context => true; + options.CheckConsentNeeded = context => false; options.MinimumSameSitePolicy = SameSiteMode.Lax; options.HttpOnly = HttpOnlyPolicy.Always; options.Secure = CookieSecurePolicy.Always; -- 2.48.1 From b0669f65c0486f247decd6f40d4e7b95e1f7fedf Mon Sep 17 00:00:00 2001 From: surtur Date: Sat, 26 Dec 2020 17:06:03 +0100 Subject: [PATCH 07/11] chore: target 3.1.* + connected simplification * global.json sdk value will now match 3.1.whatever * rm the now-redundant sed both from the ci pipeline and Dockerfile* * limit ci pipeline runs to single build for an event. e.g. on a pr, run a single build instead of both a pr build and a push build * edit Makefile to force --no-cache builds --- .drone.yml | 18 +++++++----------- Dockerfile | 4 ---- Dockerfile.dev | 4 ---- Makefile | 4 ++-- global.json | 2 +- 5 files changed, 10 insertions(+), 22 deletions(-) diff --git a/.drone.yml b/.drone.yml index b85f58e..15d6a8d 100644 --- a/.drone.yml +++ b/.drone.yml @@ -7,19 +7,17 @@ platform: os: linux arch: amd64 -steps: -- name: sed-tgt-version - pull: always - image: bash - commands: - - sed -i 's/3.1.110/3.1.404/' global.json - # since we're running 3.1.404 here in the CI, this is necessary +trigger: + ref: + - refs/heads/master + - refs/heads/feature-* + - refs/pull/*/head + - refs/tags/* +steps: - name: debug pull: always image: mcr.microsoft.com/dotnet/core/sdk:3.1-alpine - depends_on: - - sed-tgt-version commands: - dotnet restore - dotnet build . @@ -27,8 +25,6 @@ steps: - name: release pull: always image: mcr.microsoft.com/dotnet/core/sdk:3.1-alpine - depends_on: - - sed-tgt-version commands: - dotnet restore - dotnet publish -c Release -o out diff --git a/Dockerfile b/Dockerfile index 51f7da3..6e0cc77 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,14 +5,10 @@ ENV UNAME unpriv RUN adduser -D -u ${UID} -g ${GID} -H ${UNAME} -h /src WORKDIR /src -COPY global.json ./ -RUN sed -i 's/3.1.110/3.1.404/' global.json - COPY *.csproj ./ RUN dotnet restore COPY . ./ -RUN sed -i 's/3.1.110/3.1.404/' global.json RUN dotnet publish -c Release -o bin/out FROM mcr.microsoft.com/dotnet/aspnet:3.1 diff --git a/Dockerfile.dev b/Dockerfile.dev index 777491b..9aa1753 100644 --- a/Dockerfile.dev +++ b/Dockerfile.dev @@ -5,14 +5,10 @@ ENV UNAME unpriv RUN adduser -D -u ${UID} -g ${GID} -H ${UNAME} -h /src WORKDIR /src -COPY global.json ./ -RUN sed -i 's/3.1.110/3.1.404/' global.json - COPY *.csproj ./ RUN dotnet restore COPY . ./ -RUN sed -i 's/3.1.110/3.1.404/' global.json RUN dotnet build -c Debug -o bin/out RUN chown -R ${UID}:${GID} ./ /root/ USER ${UNAME} diff --git a/Makefile b/Makefile index 540f9e6..de90dd9 100644 --- a/Makefile +++ b/Makefile @@ -35,13 +35,13 @@ dockerbuild: docker build \ --build-arg VCS_REF=`git rev-parse --short HEAD` \ --build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \ - -t $(dtag) -f $(dfile) . + -t $(dtag) -f $(dfile) --no-cache . dockerdevbuild: docker build \ --build-arg VCS_REF=`git rev-parse --short HEAD` \ --build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \ - -t $(dtagdev) -f $(dfiledev) . + -t $(dtagdev) -f $(dfiledev) --no-cache . dockerrun: @echo ====================== diff --git a/global.json b/global.json index 8afc0f0..a90a85c 100644 --- a/global.json +++ b/global.json @@ -1,5 +1,5 @@ { "sdk": { - "version": "3.1.404" + "version": "3.1.*" } } -- 2.48.1 From 5a81c93395e709ad3f7bb7aa07fe112d53d575f8 Mon Sep 17 00:00:00 2001 From: surtur Date: Sat, 26 Dec 2020 17:59:32 +0100 Subject: [PATCH 08/11] chore: include carousels folder --- pwt-0x01-ng.csproj | 1 + 1 file changed, 1 insertion(+) diff --git a/pwt-0x01-ng.csproj b/pwt-0x01-ng.csproj index d47aecd..dbf4e9a 100644 --- a/pwt-0x01-ng.csproj +++ b/pwt-0x01-ng.csproj @@ -21,6 +21,7 @@ + -- 2.48.1 From 61714e3d9ead7744e2ac9571be475e3c5dd4d658 Mon Sep 17 00:00:00 2001 From: surtur Date: Sat, 26 Dec 2020 18:00:15 +0100 Subject: [PATCH 09/11] chore: use async for db ops --- Models/Database/DBInit.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Models/Database/DBInit.cs b/Models/Database/DBInit.cs index 29babac..5ab8eef 100644 --- a/Models/Database/DBInit.cs +++ b/Models/Database/DBInit.cs @@ -8,7 +8,7 @@ namespace pwt0x01ng.Models.Database public static class DBInit { - public static void Init(DBContext dbContext) + public async static void Init(DBContext dbContext) { if (dbContext.Database.EnsureCreated()) { @@ -17,7 +17,7 @@ namespace pwt0x01ng.Models.Database { dbContext.Carousel.Add(c); } - dbContext.SaveChanges(); + await dbContext.SaveChangesAsync(); } } } -- 2.48.1 From 83379ec335c3a5e5abae475eac18f2955ddf1382 Mon Sep 17 00:00:00 2001 From: surtur Date: Sat, 26 Dec 2020 18:42:34 +0100 Subject: [PATCH 10/11] chore: revert 61714e3d9e * didn't work out so well, builds fine but refuses to run, stashing the idea for another time --- Models/Database/DBInit.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Models/Database/DBInit.cs b/Models/Database/DBInit.cs index 5ab8eef..29babac 100644 --- a/Models/Database/DBInit.cs +++ b/Models/Database/DBInit.cs @@ -8,7 +8,7 @@ namespace pwt0x01ng.Models.Database public static class DBInit { - public async static void Init(DBContext dbContext) + public static void Init(DBContext dbContext) { if (dbContext.Database.EnsureCreated()) { @@ -17,7 +17,7 @@ namespace pwt0x01ng.Models.Database { dbContext.Carousel.Add(c); } - await dbContext.SaveChangesAsync(); + dbContext.SaveChanges(); } } } -- 2.48.1 From fe2e054f0b0d269f4ca4d3fd4ef9ea0123d1b3a3 Mon Sep 17 00:00:00 2001 From: surtur Date: Sat, 26 Dec 2020 19:28:41 +0100 Subject: [PATCH 11/11] chore: postgre --> postgres --- appsettings.Development.json | 2 +- appsettings.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/appsettings.Development.json b/appsettings.Development.json index 74513e4..18b9722 100644 --- a/appsettings.Development.json +++ b/appsettings.Development.json @@ -1,6 +1,6 @@ { "db": { - "Postgre": "User ID=postgres;Password=679968312e029a806c1905c40ec331aa199a1eb86bd0b9eb04057933e449bdc9ef8ef292a39b68cafa5689c901a17266;Server=db;Port=5432;Database=pwt;Integrated Security=true;Pooling=true;", + "Postgres": "User ID=postgres;Password=679968312e029a806c1905c40ec331aa199a1eb86bd0b9eb04057933e449bdc9ef8ef292a39b68cafa5689c901a17266;Server=db;Port=5432;Database=pwt;Integrated Security=true;Pooling=true;", "MySQL": "server=db,Database=pwt-0x01-ng;Port=3306;user=root;password=679968312e029a806c1905c40ec331aa199a1eb86bd0b9eb04057933e449bdc9ef8ef292a39b68cafa5689c901a17266;" }, "Logging": { diff --git a/appsettings.json b/appsettings.json index fa752eb..5cd33f1 100644 --- a/appsettings.json +++ b/appsettings.json @@ -1,6 +1,6 @@ { "db": { - "Postgre": "host=db,port=5432;database=pwt;username=postgres;password=679968312e029a806c1905c40ec331aa199a1eb86bd0b9eb04057933e449bdc9ef8ef292a39b68cafa5689c901a17266", + "Postgres": "host=db,port=5432;database=pwt;username=postgres;password=679968312e029a806c1905c40ec331aa199a1eb86bd0b9eb04057933e449bdc9ef8ef292a39b68cafa5689c901a17266", "MySQL": "server=db,Database=pwt-0x01-ng;Port=3306;user=root;password=679968312e029a806c1905c40ec331aa199a1eb86bd0b9eb04057933e449bdc9ef8ef292a39b68cafa5689c901a17266;" }, "Logging": { -- 2.48.1