add docker support
This commit is contained in:
5
.dockerignore
Normal file
5
.dockerignore
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
bin/
|
||||||
|
obj/
|
||||||
|
.vs/
|
||||||
|
.git/
|
||||||
|
*.user
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk.Web">
|
<Project Sdk="Microsoft.NET.Sdk.Web">
|
||||||
|
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<TargetFramework>net10.0</TargetFramework>
|
<TargetFramework>net9.0</TargetFramework>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
@@ -11,13 +11,17 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="10.0.1" />
|
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="9.0" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="10.0.1" />
|
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0" />
|
||||||
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="10.0.1">
|
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="9.0">
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="10.0.1" />
|
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="9.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<EditorConfigFiles Remove="C:\Users\wessc\dev\Catalog\Catalog26\.editorconfig" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
|
|
||||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.14.36705.20 d17.14
|
VisualStudioVersion = 17.14.36705.20
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Catalog26", "Catalog26.csproj", "{1C563A4F-E0DC-974E-3438-0A05DCCA15DF}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Catalog26", "Catalog26.csproj", "{1C563A4F-E0DC-974E-3438-0A05DCCA15DF}"
|
||||||
EndProject
|
EndProject
|
||||||
|
|||||||
29
Dockerfile
Normal file
29
Dockerfile
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
# STAGE 1: Build
|
||||||
|
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
|
||||||
|
# Set the working directory in the container
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy the .csproj file and restore any dependencies
|
||||||
|
# Doing this separately allows Docker to cache this layer
|
||||||
|
COPY *.csproj ./
|
||||||
|
RUN dotnet restore
|
||||||
|
|
||||||
|
# Copy the rest of the application files
|
||||||
|
COPY . ./
|
||||||
|
|
||||||
|
# Build the application and publish it for production
|
||||||
|
RUN dotnet publish -c Release -o /app/publish
|
||||||
|
|
||||||
|
# STAGE 2: Runtime
|
||||||
|
# Use the ASP.NET runtime image (much smaller than the SDK)
|
||||||
|
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS runtime
|
||||||
|
WORKDIR /app
|
||||||
|
|
||||||
|
# Copy the published files from the build stage
|
||||||
|
COPY --from=build /app/publish .
|
||||||
|
|
||||||
|
# Expose the port your app runs on (usually 8080 in .NET 8+)
|
||||||
|
EXPOSE 8080
|
||||||
|
|
||||||
|
# Set the entrypoint for the application
|
||||||
|
ENTRYPOINT ["dotnet", "Catalog26.dll"]
|
||||||
103
README.md
103
README.md
@@ -1 +1,104 @@
|
|||||||
# Catalog - Pricing and Availability
|
# Catalog - Pricing and Availability
|
||||||
|
|
||||||
|
## SQL
|
||||||
|
|
||||||
|
## Docker
|
||||||
|
|
||||||
|
### Create a Local Docker Registry with TLS
|
||||||
|
|
||||||
|
On one of the VMs (e.g oahu.chopark.home), set up a local Docker registry.
|
||||||
|
Skip if a local registry already exists.
|
||||||
|
|
||||||
|
Prerequisite: Create a CA and a self-signed cert.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
docker run -d --restart=always --name registry \
|
||||||
|
-v /opt/registry/certs:/certs \
|
||||||
|
-v /opt/registry/data:/var/lib/registry \
|
||||||
|
-e REGISTRY_HTTP_ADDR=0.0.0.0:443 \
|
||||||
|
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/registry.crt \
|
||||||
|
-e REGISTRY_HTTP_TLS_KEY=/certs/registry.key \
|
||||||
|
-p 443:443 \
|
||||||
|
registry:2
|
||||||
|
```
|
||||||
|
|
||||||
|
### Build a Docker Image
|
||||||
|
|
||||||
|
1. Create a `Dockerfile`. Refer to the `Dockerfile` in the root of this project.
|
||||||
|
|
||||||
|
2. Then build the image.
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
# build an image
|
||||||
|
docker build -t catalog26 .
|
||||||
|
|
||||||
|
# verify the image
|
||||||
|
docker images | grep catalog26
|
||||||
|
|
||||||
|
# also try running it
|
||||||
|
docker run -d -p 5000:8080 -n catalog26 catalog26
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Tag for my registry.
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
docker tag catalog26 registry.chopark.home/catalog26
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Push to Registry
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
docker push registry.chopark.home/catalog26
|
||||||
|
```
|
||||||
|
|
||||||
|
Optional: If an https error is returned, make the following adjustments.
|
||||||
|
|
||||||
|
On Linux, edit `/etc/docker/daemon.json`:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"insecure-registries": ["registry.chopark.home"]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
On Windows (Docker Desktop):
|
||||||
|
- Open Docker Desktop
|
||||||
|
- Go to Settings > Docker Engine
|
||||||
|
- Add to the JSON configuration
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"insecure-registries": ["registry.chopark.home"]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Kubernetes
|
||||||
|
|
||||||
|
1. Containerd (on all K8s nodes) for https connection problem
|
||||||
|
|
||||||
|
```toml
|
||||||
|
sudo tee /etc/containerd/certs.d/registry.chopark.home/hosts.toml <<EOF
|
||||||
|
server = "https://registry.chopark.home"
|
||||||
|
|
||||||
|
[host."https://registry.choparkhome"]
|
||||||
|
ca = "/usr/local/share/ca-certificates/regisry.chopark.home-ca.crt"
|
||||||
|
skip_verify = false
|
||||||
|
EOF
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Optional Image Pull - create crictl config
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# Create crictl config
|
||||||
|
sudo tee /etc/crictl.yaml > /dev/null <<EOF
|
||||||
|
runtime-endpoint: unix:///run/containerd/containerd.sock
|
||||||
|
image-endpoint: unix:///run/containerd/containerd.sock
|
||||||
|
timeout: 10
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Test crictl
|
||||||
|
sudo crictl version
|
||||||
|
|
||||||
|
# Pull image
|
||||||
|
sudo crictl pull registry.chopark.home/catalog26
|
||||||
|
```
|
||||||
43
k8s-deployment.yaml
Normal file
43
k8s-deployment.yaml
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
apiVersion: v1
|
||||||
|
kind: Namespace
|
||||||
|
metadata:
|
||||||
|
name: catalog
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
name: catalog26-deployment
|
||||||
|
namespace: catalog
|
||||||
|
labels:
|
||||||
|
app: catalog26
|
||||||
|
spec:
|
||||||
|
replicas: 2
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: catalog26
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: catalog26
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: catalog26
|
||||||
|
image: registry.chopark.home/catalog26:latest # Or yourusername/catalog26:latest for Docker Hub
|
||||||
|
imagePullPolicy: Always
|
||||||
|
ports:
|
||||||
|
- containerPort: 8080 # This must match your Dockerfile EXPOSE port
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: catalog26-service
|
||||||
|
namespace: catalog
|
||||||
|
spec:
|
||||||
|
type: LoadBalancer # Or NodePort if you don't have a LoadBalancer
|
||||||
|
selector:
|
||||||
|
app: catalog26
|
||||||
|
ports:
|
||||||
|
- protocol: TCP
|
||||||
|
port: 80
|
||||||
|
targetPort: 8080
|
||||||
|
# nodePort: 30080 # Uncomment if using NodePort
|
||||||
Reference in New Issue
Block a user