wip: troubleshooting docker flow
This commit is contained in:
6
.gitignore
vendored
6
.gitignore
vendored
@@ -3,6 +3,10 @@
|
|||||||
##
|
##
|
||||||
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
|
||||||
|
|
||||||
|
# GITIGNORE FILES ADDED BY MIKAYLA
|
||||||
|
__notes__
|
||||||
|
*.env
|
||||||
|
|
||||||
# User-specific files
|
# User-specific files
|
||||||
*.rsuser
|
*.rsuser
|
||||||
*.suo
|
*.suo
|
||||||
@@ -360,4 +364,4 @@ MigrationBackup/
|
|||||||
.ionide/
|
.ionide/
|
||||||
|
|
||||||
# Fody - auto-generated XML schema
|
# Fody - auto-generated XML schema
|
||||||
FodyWeavers.xsd
|
FodyWeavers.xsd
|
||||||
|
|||||||
1
Unbinder/.dockerignore
Normal file
1
Unbinder/.dockerignore
Normal file
@@ -0,0 +1 @@
|
|||||||
|
__notes__
|
||||||
@@ -1,11 +1,26 @@
|
|||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
|
using Unbinder.Services;
|
||||||
|
|
||||||
namespace Unbinder.Controllers
|
namespace Unbinder.Controllers
|
||||||
{
|
{
|
||||||
public class HomeController : Controller
|
public class HomeController : Controller
|
||||||
{
|
{
|
||||||
public IActionResult Index()
|
public async Task<IActionResult> Index()
|
||||||
{
|
{
|
||||||
|
var objects = await S3Service.ListObjects();
|
||||||
|
|
||||||
|
if (objects != null)
|
||||||
|
{
|
||||||
|
foreach (var entry in objects.S3Objects)
|
||||||
|
{
|
||||||
|
Console.WriteLine(entry.Key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.WriteLine("Did not find results in S3");
|
||||||
|
}
|
||||||
|
|
||||||
return View();
|
return View();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,8 @@ namespace Unbinder.Controllers
|
|||||||
{
|
{
|
||||||
if (q == null && category == null) return View(_recipeRepository.GetAll);
|
if (q == null && category == null) return View(_recipeRepository.GetAll);
|
||||||
|
|
||||||
var result = _recipeRepository.GetAll?.Where(r => r.Name.Contains(q, StringComparison.OrdinalIgnoreCase));
|
var result = _recipeRepository.GetAll?.Where(r => r.Name.Contains(q!, StringComparison.OrdinalIgnoreCase));
|
||||||
|
ViewBag.Query = q;
|
||||||
|
|
||||||
return result == null
|
return result == null
|
||||||
? NotFound()
|
? NotFound()
|
||||||
|
|||||||
25
Unbinder/DB/SQL/create_database.sql
Normal file
25
Unbinder/DB/SQL/create_database.sql
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
IF NOT EXISTS(SELECT name FROM sys.databases WHERE name = 'Unbinder')
|
||||||
|
BEGIN
|
||||||
|
CREATE DATABASE Unbinder;
|
||||||
|
|
||||||
|
USE Unbinder;
|
||||||
|
|
||||||
|
CREATE TABLE [dbo].Recipes (
|
||||||
|
[Id] INT IDENTITY(1,1) NOT NULL,
|
||||||
|
[Name] NVARCHAR(50) NOT NULL,
|
||||||
|
[ShortDescription] NVARCHAR(1000) NULL,
|
||||||
|
[Author] NVARCHAR(100) NULL,
|
||||||
|
[RecipeText] NVARCHAR(8000) NULL,
|
||||||
|
[ImageUrl] NVARCHAR(1000) NULL,
|
||||||
|
[Created] DATETIME NOT NULL,
|
||||||
|
[Updated] DATETIME NOT NULL,
|
||||||
|
CONSTRAINT [PK_Recipes] PRIMARY KEY CLUSTERED ([Id] ASC)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE [dbo].Ingredients (
|
||||||
|
[Id] INT IDENTITY(1,1) NOT NULL,
|
||||||
|
[Name] NVARCHAR(50) NOT NULL,
|
||||||
|
[Description] NVARCHAR(1000) NULL,
|
||||||
|
CONSTRAINT [PK_Ingredients] PRIMARY KEY CLUSTERED ([Id] ASC)
|
||||||
|
);
|
||||||
|
END
|
||||||
18
Unbinder/Docker/DOTNET.Dockerfile
Normal file
18
Unbinder/Docker/DOTNET.Dockerfile
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
# get .net 8
|
||||||
|
FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
|
||||||
|
|
||||||
|
COPY . ./src
|
||||||
|
WORKDIR /src
|
||||||
|
|
||||||
|
RUN dotnet build -o /app
|
||||||
|
RUN dotnet publish -o /publish
|
||||||
|
|
||||||
|
ENV AWS_S3_URL=$AWS_S3_URL
|
||||||
|
ENV AWS_ACCESS_KEY=$AWS_ACCESS_KEY
|
||||||
|
ENV AWS_SECRET_KEY=$AWS_SECRET_KEY
|
||||||
|
ENV AWS_BUCKET_NAME=$AWS_BUCKET_NAME
|
||||||
|
|
||||||
|
WORKDIR /publish
|
||||||
|
|
||||||
|
EXPOSE 80
|
||||||
|
ENTRYPOINT ["./Unbinder"]
|
||||||
16
Unbinder/Docker/MSSQL.Dockerfile
Normal file
16
Unbinder/Docker/MSSQL.Dockerfile
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# build from sql server image
|
||||||
|
FROM mcr.microsoft.com/mssql/server:2022-latest
|
||||||
|
|
||||||
|
# set environment variables
|
||||||
|
ENV ACCEPT_EULA=Y
|
||||||
|
ENV MSSQL_PID Express
|
||||||
|
ENV SA_PASSWORD=$DB_PASSWORD
|
||||||
|
|
||||||
|
# WORKDIR /db
|
||||||
|
# COPY ../DB/SQL/create_database.sql .
|
||||||
|
|
||||||
|
# run the sql script
|
||||||
|
# CMD /opt/mssql-tools/bin/sqlcmd -S localhost -U sa -P fhhwergaiuh12480y53 -d master -i create_database.sql
|
||||||
|
|
||||||
|
# run the command to start sql server
|
||||||
|
CMD /opt/mssql/bin/sqlservr
|
||||||
@@ -8,6 +8,9 @@ using Microsoft.Identity.Web.UI;
|
|||||||
using Unbinder.DB;
|
using Unbinder.DB;
|
||||||
using Unbinder.Models;
|
using Unbinder.Models;
|
||||||
using Unbinder.Repositories;
|
using Unbinder.Repositories;
|
||||||
|
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");
|
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
|
||||||
@@ -43,6 +46,10 @@ builder.Services.AddScoped<IIngredientRepository, IngredientRepository>();
|
|||||||
builder.Services.AddHttpContextAccessor();
|
builder.Services.AddHttpContextAccessor();
|
||||||
builder.Services.AddServerSideBlazor();
|
builder.Services.AddServerSideBlazor();
|
||||||
|
|
||||||
|
|
||||||
|
// include extra services
|
||||||
|
//builder.Services.AddSingleton(S3Service.Client);
|
||||||
|
|
||||||
var app = builder.Build();
|
var app = builder.Build();
|
||||||
|
|
||||||
// Configure the HTTP request pipeline.
|
// Configure the HTTP request pipeline.
|
||||||
|
|||||||
@@ -2,22 +2,54 @@
|
|||||||
using Amazon.S3;
|
using Amazon.S3;
|
||||||
using Amazon.S3.Transfer;
|
using Amazon.S3.Transfer;
|
||||||
using Amazon.Runtime;
|
using Amazon.Runtime;
|
||||||
|
using System.Net;
|
||||||
|
using Amazon.S3.Model;
|
||||||
|
|
||||||
namespace Unbinder.Services
|
namespace Unbinder.Services
|
||||||
{
|
{
|
||||||
public class S3Service
|
public sealed class S3Service
|
||||||
{
|
{
|
||||||
public static AWSCredentials Credentials =>
|
private static AWSCredentials Credentials
|
||||||
new BasicAWSCredentials(
|
{
|
||||||
Environment.GetEnvironmentVariable("AWS_ACCESS_KEY"),
|
get
|
||||||
Environment.GetEnvironmentVariable("AWS_SECRET_KEY"));
|
{
|
||||||
|
string? accessKey = Environment.GetEnvironmentVariable("AWS_ACCESS_KEY");
|
||||||
|
string? secret = Environment.GetEnvironmentVariable("AWS_SECRET_KEY");
|
||||||
|
|
||||||
public static AmazonS3Client Client => new(Credentials, RegionEndpoint.USEast1);
|
Console.WriteLine(accessKey ?? "(none)", secret ?? "(none)");
|
||||||
|
|
||||||
|
if (accessKey == null || secret == null)
|
||||||
|
{
|
||||||
|
throw new Exception("AWS credentials not found");
|
||||||
|
}
|
||||||
|
|
||||||
|
return new BasicAWSCredentials(accessKey, secret);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static AmazonS3Config Config => new()
|
||||||
|
{
|
||||||
|
RegionEndpoint = RegionEndpoint.USEast2
|
||||||
|
};
|
||||||
|
|
||||||
|
private static AmazonS3Client Client => new(Credentials);
|
||||||
|
private static readonly AmazonS3Client client = Client;
|
||||||
|
private static readonly string? BucketName = Environment.GetEnvironmentVariable("AWS_BUCKET_NAME");
|
||||||
|
|
||||||
|
public static async Task<ListObjectsResponse> ListObjects(string? prefix = "")
|
||||||
|
{
|
||||||
|
var bucketName = BucketName;
|
||||||
|
var request = new ListObjectsRequest
|
||||||
|
{
|
||||||
|
BucketName = bucketName,
|
||||||
|
Prefix = prefix
|
||||||
|
};
|
||||||
|
|
||||||
|
return await client.ListObjectsAsync(request);
|
||||||
|
}
|
||||||
|
|
||||||
public async Task<string?> UploadFileAsync(IFormFile file)
|
public async Task<string?> UploadFileAsync(IFormFile file)
|
||||||
{
|
{
|
||||||
using IAmazonS3 client = Client;
|
|
||||||
|
|
||||||
if (file == null || file.Length == 0)
|
if (file == null || file.Length == 0)
|
||||||
{
|
{
|
||||||
return null;
|
return null;
|
||||||
@@ -34,8 +66,6 @@ namespace Unbinder.Services
|
|||||||
|
|
||||||
public async Task GetFile(string path, string outFile)
|
public async Task GetFile(string path, string outFile)
|
||||||
{
|
{
|
||||||
using IAmazonS3 client = Client;
|
|
||||||
|
|
||||||
var bucketName = "unbinder-recipe-images";
|
var bucketName = "unbinder-recipe-images";
|
||||||
using var fileTransferUtility = new TransferUtility(client);
|
using var fileTransferUtility = new TransferUtility(client);
|
||||||
await fileTransferUtility.DownloadAsync(outFile, bucketName, path);
|
await fileTransferUtility.DownloadAsync(outFile, bucketName, path);
|
||||||
|
|||||||
@@ -24,6 +24,8 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<Folder Include="DB\SQL\" />
|
||||||
|
<Folder Include="__notes__\" />
|
||||||
<Folder Include="ViewModels\" />
|
<Folder Include="ViewModels\" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,13 @@
|
|||||||
@model IEnumerable<Recipe>
|
@model IEnumerable<Recipe>
|
||||||
|
|
||||||
|
@{
|
||||||
|
string InputValue = ViewBag.Query ?? String.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<div id="search-page-header" class="mb-8 border-white border-b">
|
<div id="search-page-header" class="mb-8 border-white border-b">
|
||||||
<h3 id="query-message"></h3>
|
<h3 id="query-message"></h3>
|
||||||
<input class="text-black" id="new-search-query" type="text" />
|
<input value="@InputValue" class="text-black" id="new-search-query" type="text" />
|
||||||
<button id="execute-search">Search</button>
|
<button id="execute-search">Search</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="search-results">
|
<div id="search-results">
|
||||||
@@ -26,11 +30,7 @@
|
|||||||
console.log(query);
|
console.log(query);
|
||||||
|
|
||||||
// set initial message value
|
// set initial message value
|
||||||
if (query) {
|
message.innerHTML = query ? `Viewing ${@Model.ToArray().Length} results for: ${query}` : "Enter a new search term below:";
|
||||||
message.innerHTML = `Viewing ${@Model.ToArray().Length} results for: ${query}`;
|
|
||||||
} else {
|
|
||||||
message.innerHTML = "Enter a new search term below:";
|
|
||||||
}
|
|
||||||
|
|
||||||
// handle search updates on client side
|
// handle search updates on client side
|
||||||
searchButton.onclick = async () => {
|
searchButton.onclick = async () => {
|
||||||
@@ -40,13 +40,6 @@
|
|||||||
|
|
||||||
const newResultJson = await newResult.json();
|
const newResultJson = await newResult.json();
|
||||||
window.location.search = `?q=${textField.value}`;
|
window.location.search = `?q=${textField.value}`;
|
||||||
searchResultsContainer.innerHTML = `@{
|
|
||||||
foreach (var recipe in @Model)
|
|
||||||
{
|
|
||||||
<p>@recipe.Name</p>
|
|
||||||
<p>@recipe.RecipeText</p>
|
|
||||||
}
|
|
||||||
}`;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
24
Unbinder/docker-compose.yaml
Normal file
24
Unbinder/docker-compose.yaml
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
version: '3.8'
|
||||||
|
|
||||||
|
services:
|
||||||
|
client:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
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:
|
||||||
|
- 80:80
|
||||||
|
depends_on:
|
||||||
|
- db
|
||||||
|
db:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
dockerfile: ./Docker/MSSQL.Dockerfile
|
||||||
|
args:
|
||||||
|
DB_PASSWORD: ${DB_PASSWORD}
|
||||||
|
ports:
|
||||||
|
- 1433:1433
|
||||||
Reference in New Issue
Block a user