updated docker config; corrected env variable workflow
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -7,6 +7,10 @@
|
|||||||
__notes__
|
__notes__
|
||||||
*.env
|
*.env
|
||||||
|
|
||||||
|
# Files for/generated by Docker Compose
|
||||||
|
secrets
|
||||||
|
db_data
|
||||||
|
|
||||||
# User-specific files
|
# User-specific files
|
||||||
*.rsuser
|
*.rsuser
|
||||||
*.suo
|
*.suo
|
||||||
|
|||||||
@@ -1,18 +1,18 @@
|
|||||||
# get .net 8
|
# get .net 8
|
||||||
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||||
|
WORKDIR /app
|
||||||
COPY . ./src
|
|
||||||
WORKDIR /src
|
|
||||||
|
|
||||||
RUN dotnet build -o /app
|
|
||||||
RUN dotnet publish -o /publish
|
|
||||||
|
|
||||||
ENV AWS_S3_URL=$AWS_S3_URL
|
ENV AWS_S3_URL=$AWS_S3_URL
|
||||||
ENV AWS_ACCESS_KEY=$AWS_ACCESS_KEY
|
ENV AWS_ACCESS_KEY=$AWS_ACCESS_KEY
|
||||||
ENV AWS_SECRET_KEY=$AWS_SECRET_KEY
|
ENV AWS_SECRET_KEY=$AWS_SECRET_KEY
|
||||||
ENV AWS_BUCKET_NAME=$AWS_BUCKET_NAME
|
ENV AWS_BUCKET_NAME=$AWS_BUCKET_NAME
|
||||||
|
|
||||||
WORKDIR /publish
|
COPY . .
|
||||||
|
RUN dotnet restore
|
||||||
|
RUN dotnet publish -o out
|
||||||
|
|
||||||
EXPOSE 80
|
# build runtime image
|
||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:8.0
|
||||||
|
WORKDIR /app
|
||||||
|
COPY --from=build /app/out .
|
||||||
ENTRYPOINT ["./Unbinder"]
|
ENTRYPOINT ["./Unbinder"]
|
||||||
79
Unbinder/Migrations/20231201185549_update-table-names.Designer.cs
generated
Normal file
79
Unbinder/Migrations/20231201185549_update-table-names.Designer.cs
generated
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Unbinder.DB;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Unbinder.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(UnbinderDbContext))]
|
||||||
|
[Migration("20231201185549_update-table-names")]
|
||||||
|
partial class updatetablenames
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "8.0.0")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 128);
|
||||||
|
|
||||||
|
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("Unbinder.Models.Ingredient", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("IngredientId")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("IngredientId"));
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("IngredientId");
|
||||||
|
|
||||||
|
b.ToTable("Ingredients");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Unbinder.Models.Recipe", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("RecipeId")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("int");
|
||||||
|
|
||||||
|
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("RecipeId"));
|
||||||
|
|
||||||
|
b.Property<string>("Author")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("ImageUrl")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("RecipeText")
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.Property<string>("ShortDescription")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("nvarchar(max)");
|
||||||
|
|
||||||
|
b.HasKey("RecipeId");
|
||||||
|
|
||||||
|
b.ToTable("Recipes");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
22
Unbinder/Migrations/20231201185549_update-table-names.cs
Normal file
22
Unbinder/Migrations/20231201185549_update-table-names.cs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace Unbinder.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class updatetablenames : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
namespace Unbinder.Models
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace Unbinder.Models
|
||||||
{
|
{
|
||||||
|
[Table("Ingredients")]
|
||||||
public record Ingredient
|
public record Ingredient
|
||||||
{
|
{
|
||||||
public int IngredientId { get; init; }
|
public int IngredientId { get; init; }
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
namespace Unbinder.Models
|
using System.ComponentModel.DataAnnotations.Schema;
|
||||||
|
|
||||||
|
namespace Unbinder.Models
|
||||||
{
|
{
|
||||||
|
[Table("Recipes")]
|
||||||
public record Recipe
|
public record Recipe
|
||||||
{
|
{
|
||||||
public int RecipeId { get; init; }
|
public int RecipeId { get; init; }
|
||||||
|
|||||||
@@ -1,19 +1,13 @@
|
|||||||
using Microsoft.AspNetCore.Authentication;
|
using Microsoft.Data.SqlClient;
|
||||||
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
|
|
||||||
using Microsoft.AspNetCore.Authorization;
|
|
||||||
using Microsoft.AspNetCore.Mvc.Authorization;
|
|
||||||
using Microsoft.Identity.Web;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.Identity.Web.UI;
|
|
||||||
using Unbinder.DB;
|
using Unbinder.DB;
|
||||||
using Unbinder.Models;
|
|
||||||
using Unbinder.Repositories;
|
using Unbinder.Repositories;
|
||||||
using Unbinder.Services;
|
using Unbinder.Services;
|
||||||
using Amazon.S3;
|
|
||||||
using Microsoft.Extensions.Azure;
|
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
|
|
||||||
|
// pull in environment variables from secrets
|
||||||
|
EnvironmentLoader.Load(builder);
|
||||||
|
|
||||||
// Add services to the container.
|
// Add services to the container.
|
||||||
//builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
|
//builder.Services.AddAuthentication(OpenIdConnectDefaults.AuthenticationScheme)
|
||||||
@@ -23,8 +17,16 @@ var connectionString = builder.Configuration.GetConnectionString("DefaultConnect
|
|||||||
// // By default, all incoming requests will be authorized according to the default policy.
|
// // By default, all incoming requests will be authorized according to the default policy.
|
||||||
// options.FallbackPolicy = options.DefaultPolicy);
|
// options.FallbackPolicy = options.DefaultPolicy);
|
||||||
|
|
||||||
|
SqlConnectionStringBuilder connBuilder = new()
|
||||||
|
{
|
||||||
|
ConnectionString = builder.Configuration.GetConnectionString("DefaultConnection"),
|
||||||
|
Password = builder.Configuration["SA_PASSWORD"],
|
||||||
|
};
|
||||||
|
|
||||||
builder.Services.AddDbContext<UnbinderDbContext>(options =>
|
builder.Services.AddDbContext<UnbinderDbContext>(options =>
|
||||||
options.UseSqlServer(connectionString));
|
{
|
||||||
|
options.UseSqlServer(connBuilder.ConnectionString);
|
||||||
|
});
|
||||||
|
|
||||||
// configure MVC
|
// configure MVC
|
||||||
builder.Services.AddControllersWithViews();
|
builder.Services.AddControllersWithViews();
|
||||||
|
|||||||
13
Unbinder/Services/EnvironmentLoader.cs
Normal file
13
Unbinder/Services/EnvironmentLoader.cs
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
namespace Unbinder.Services
|
||||||
|
{
|
||||||
|
public static class EnvironmentLoader
|
||||||
|
{
|
||||||
|
public static void Load(WebApplicationBuilder builder)
|
||||||
|
{
|
||||||
|
Environment.SetEnvironmentVariable("AWS_S3_URL", builder.Configuration["AWS_S3_URL"]);
|
||||||
|
Environment.SetEnvironmentVariable("AWS_ACCESS_KEY", builder.Configuration["AWS_ACCESS_KEY"]);
|
||||||
|
Environment.SetEnvironmentVariable("AWS_SECRET_KEY", builder.Configuration["AWS_SECRET_KEY"]);
|
||||||
|
Environment.SetEnvironmentVariable("AWS_BUCKET_NAME", builder.Configuration["AWS_BUCKET_NAME"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,8 +16,6 @@ namespace Unbinder.Services
|
|||||||
string? accessKey = Environment.GetEnvironmentVariable("AWS_ACCESS_KEY");
|
string? accessKey = Environment.GetEnvironmentVariable("AWS_ACCESS_KEY");
|
||||||
string? secret = Environment.GetEnvironmentVariable("AWS_SECRET_KEY");
|
string? secret = Environment.GetEnvironmentVariable("AWS_SECRET_KEY");
|
||||||
|
|
||||||
Console.WriteLine(accessKey ?? "(none)", secret ?? "(none)");
|
|
||||||
|
|
||||||
if (accessKey == null || secret == null)
|
if (accessKey == null || secret == null)
|
||||||
{
|
{
|
||||||
throw new Exception("AWS credentials not found");
|
throw new Exception("AWS credentials not found");
|
||||||
@@ -32,7 +30,7 @@ namespace Unbinder.Services
|
|||||||
RegionEndpoint = RegionEndpoint.USEast2
|
RegionEndpoint = RegionEndpoint.USEast2
|
||||||
};
|
};
|
||||||
|
|
||||||
private static AmazonS3Client Client => new(Credentials);
|
private static AmazonS3Client Client => new(Credentials, Config);
|
||||||
private static readonly AmazonS3Client client = Client;
|
private static readonly AmazonS3Client client = Client;
|
||||||
private static readonly string? BucketName = Environment.GetEnvironmentVariable("AWS_BUCKET_NAME");
|
private static readonly string? BucketName = Environment.GetEnvironmentVariable("AWS_BUCKET_NAME");
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="DB\SQL\" />
|
<Folder Include="DB\SQL\" />
|
||||||
|
<Folder Include="secrets\" />
|
||||||
<Folder Include="__notes__\" />
|
<Folder Include="__notes__\" />
|
||||||
<Folder Include="ViewModels\" />
|
<Folder Include="ViewModels\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@@ -5,5 +5,8 @@
|
|||||||
"Default": "Information",
|
"Default": "Information",
|
||||||
"Microsoft.AspNetCore": "Warning"
|
"Microsoft.AspNetCore": "Warning"
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"ConnectionStrings": {
|
||||||
|
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=Unbinder111623"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@
|
|||||||
"CallbackPath": "/signin-oidc"
|
"CallbackPath": "/signin-oidc"
|
||||||
},
|
},
|
||||||
"ConnectionStrings": {
|
"ConnectionStrings": {
|
||||||
"DefaultConnection": "Server=(localdb)\\mssqllocaldb;Database=Unbinder11623"
|
"DefaultConnection": "Server=db;Database=master;User=sa;Encrypt=False;TrustServerCertificate=true"
|
||||||
},
|
},
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
|
|||||||
@@ -2,23 +2,40 @@ version: '3.8'
|
|||||||
|
|
||||||
services:
|
services:
|
||||||
client:
|
client:
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
build:
|
build:
|
||||||
context: .
|
context: .
|
||||||
dockerfile: ./Docker/DOTNET.Dockerfile
|
dockerfile: ./Docker/DOTNET.Dockerfile
|
||||||
args:
|
|
||||||
AWS_S3_URL: ${AWS_S3_URL}
|
|
||||||
AWS_ACCESS_KEY: ${AWS_ACCESS_KEY}
|
|
||||||
AWS_SECRET_KEY: ${AWS_SECRET_KEY}
|
|
||||||
AWS_BUCKET_NAME: ${AWS_BUCKET_NAME}
|
|
||||||
ports:
|
ports:
|
||||||
- 80:80
|
- 80:80
|
||||||
depends_on:
|
environment:
|
||||||
- db
|
SA_PASSWORD: /run/secrets/SA_PASSWORD
|
||||||
|
AWS_S3_URL: /run/secrets/AWS_S3_URL
|
||||||
|
AWS_ACCESS_KEY: /run/secrets/AWS_ACCESS_KEY
|
||||||
|
AWS_SECRET_KEY: /run/secrets/AWS_SECRET_KEY
|
||||||
|
AWS_BUCKET_NAME: /run/secrets/AWS_BUCKET_NAME
|
||||||
db:
|
db:
|
||||||
build:
|
image: mcr.microsoft.com/mssql/server:2022-latest
|
||||||
context: .
|
volumes:
|
||||||
dockerfile: ./Docker/MSSQL.Dockerfile
|
- ./db_data:/var/opt/mssql/data
|
||||||
args:
|
|
||||||
DB_PASSWORD: ${DB_PASSWORD}
|
|
||||||
ports:
|
ports:
|
||||||
- 1433:1433
|
- 1433:1433
|
||||||
|
environment:
|
||||||
|
SA_PASSWORD: /run/secrets/SA_PASSWORD
|
||||||
|
ACCEPT_EULA: "Y"
|
||||||
|
|
||||||
|
secrets:
|
||||||
|
AWS_S3_URL:
|
||||||
|
file: ./secrets/AWS_S3_URL.txt
|
||||||
|
AWS_ACCESS_KEY:
|
||||||
|
file: ./secrets/AWS_ACCESS_KEY.txt
|
||||||
|
AWS_SECRET_KEY:
|
||||||
|
file: ./secrets/AWS_SECRET_KEY.txt
|
||||||
|
AWS_BUCKET_NAME:
|
||||||
|
file: ./secrets/AWS_BUCKET_NAME.txt
|
||||||
|
SA_PASSWORD:
|
||||||
|
file: ./secrets/SA_PASSWORD.txt
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
db_data:
|
||||||
Reference in New Issue
Block a user