Setup for docker use

This commit is contained in:
Luke Else 2022-02-19 21:26:31 +00:00
parent e783f8c614
commit 3f9bf384b0
9 changed files with 150 additions and 8 deletions

24
.dockerignore Normal file
View File

@ -0,0 +1,24 @@
**/.classpath
**/.dockerignore
**/.env
**/.git
**/.gitignore
**/.project
**/.settings
**/.toolstarget
**/.vs
**/.vscode
**/*.*proj.user
**/*.dbmdl
**/*.jfm
**/bin
**/charts
**/docker-compose*
**/compose*
**/Dockerfile*
**/node_modules
**/npm-debug.log
**/obj
**/secrets.dev.yaml
**/values.dev.yaml
README.md

14
.vscode/launch.json vendored
View File

@ -2,19 +2,14 @@
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
// Use IntelliSense to find out which attributes exist for C# debugging
// Use hover for the description of the existing attributes
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
"name": ".NET Core Launch (web)", "name": ".NET Core Launch (web)",
"type": "coreclr", "type": "coreclr",
"request": "launch", "request": "launch",
"preLaunchTask": "build", "preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/net5.0/EFB.dll", "program": "${workspaceFolder}/bin/Debug/net5.0/EFB.dll",
"args": [], "args": [],
"cwd": "${workspaceFolder}", "cwd": "${workspaceFolder}",
"stopAtEntry": false, "stopAtEntry": false,
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"serverReadyAction": { "serverReadyAction": {
"action": "openExternally", "action": "openExternally",
"pattern": "\\bNow listening on:\\s+(https?://\\S+)" "pattern": "\\bNow listening on:\\s+(https?://\\S+)"
@ -30,6 +25,15 @@
"name": ".NET Core Attach", "name": ".NET Core Attach",
"type": "coreclr", "type": "coreclr",
"request": "attach" "request": "attach"
},
{
"name": "Docker .NET Core Launch",
"type": "docker",
"request": "launch",
"preLaunchTask": "docker-run: debug",
"netCore": {
"appProject": "${workspaceFolder}/EFB.csproj"
}
} }
] ]
} }

56
.vscode/tasks.json vendored
View File

@ -37,6 +37,62 @@
"/consoleloggerparameters:NoSummary" "/consoleloggerparameters:NoSummary"
], ],
"problemMatcher": "$msCompile" "problemMatcher": "$msCompile"
},
{
"type": "docker-build",
"label": "docker-build: debug",
"dependsOn": [
"build"
],
"dockerBuild": {
"tag": "efb:dev",
"target": "base",
"dockerfile": "${workspaceFolder}/Dockerfile",
"context": "${workspaceFolder}",
"pull": true
},
"netCore": {
"appProject": "${workspaceFolder}/EFB.csproj"
}
},
{
"type": "docker-build",
"label": "docker-build: release",
"dependsOn": [
"build"
],
"dockerBuild": {
"tag": "efb:latest",
"dockerfile": "${workspaceFolder}/Dockerfile",
"context": "${workspaceFolder}",
"pull": true
},
"netCore": {
"appProject": "${workspaceFolder}/EFB.csproj"
}
},
{
"type": "docker-run",
"label": "docker-run: debug",
"dependsOn": [
"docker-build: debug"
],
"dockerRun": {},
"netCore": {
"appProject": "${workspaceFolder}/EFB.csproj",
"enableDebugging": true
}
},
{
"type": "docker-run",
"label": "docker-run: release",
"dependsOn": [
"docker-build: release"
],
"dockerRun": {},
"netCore": {
"appProject": "${workspaceFolder}/EFB.csproj"
}
} }
] ]
} }

26
Dockerfile Normal file
View File

@ -0,0 +1,26 @@
FROM mcr.microsoft.com/dotnet/aspnet:5.0-focal AS base
WORKDIR /app
EXPOSE 5000
ENV ASPNETCORE_URLS=http://+:5000
# Creates a non-root user with an explicit UID and adds permission to access the /app folder
# For more info, please refer to https://aka.ms/vscode-docker-dotnet-configure-containers
RUN adduser -u 5678 --disabled-password --gecos "" appuser && chown -R appuser /app
USER appuser
FROM mcr.microsoft.com/dotnet/sdk:5.0-focal AS build
WORKDIR /src
COPY ["EFB.csproj", "./"]
RUN dotnet restore "EFB.csproj"
COPY . .
WORKDIR "/src/."
RUN dotnet build "EFB.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "EFB.csproj" -c Release -o /app/publish /p:UseAppHost=false
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "EFB.dll"]

View File

@ -63,7 +63,7 @@ namespace EFB.Models
Dictionary<string, string> formData = new Dictionary<string, string>(); Dictionary<string, string> formData = new Dictionary<string, string>();
formData.Add("token", Environment.GetEnvironmentVariable("ChartFoxAPIKey", EnvironmentVariableTarget.User)); formData.Add("token", Environment.GetEnvironmentVariable("ChartFoxAPIKey"));
FormUrlEncodedContent body = new FormUrlEncodedContent(formData); FormUrlEncodedContent body = new FormUrlEncodedContent(formData);
//make Charts request //make Charts request

View File

@ -39,7 +39,7 @@ namespace EFB.Models
} }
public static async Task<NavdataModel[]> Populate(){ public static async Task<NavdataModel[]> Populate(){
string password = Environment.GetEnvironmentVariable("MySQLPassword", EnvironmentVariableTarget.User); string password = Environment.GetEnvironmentVariable("MySQLPassword");
MySqlConnection con = new MySqlConnection($"server=server.luke-else.co.uk;userid=root;password={password};database=EFB"); MySqlConnection con = new MySqlConnection($"server=server.luke-else.co.uk;userid=root;password={password};database=EFB");
con.Open(); con.Open();

View File

@ -13,7 +13,7 @@ namespace EFB.MongoData
//function that is responsible to getting the user's latest sim position from the MongoDB //function that is responsible to getting the user's latest sim position from the MongoDB
public static async Task<SimPositionModel> GetLatestData(string email){ public static async Task<SimPositionModel> GetLatestData(string email){
MongoClient client = new MongoClient( MongoClient client = new MongoClient(
Environment.GetEnvironmentVariable("MongoDBConnectionString", EnvironmentVariableTarget.User) Environment.GetEnvironmentVariable("MongoDBConnectionString")
); );
MongoDatabaseBase database = (MongoDatabaseBase)client.GetDatabase("EFB"); MongoDatabaseBase database = (MongoDatabaseBase)client.GetDatabase("EFB");
MongoCollectionBase<SimPositionModel> collection = (MongoCollectionBase<SimPositionModel>)database.GetCollection<SimPositionModel>("Simdata"); MongoCollectionBase<SimPositionModel> collection = (MongoCollectionBase<SimPositionModel>)database.GetCollection<SimPositionModel>("Simdata");

16
docker-compose.debug.yml Normal file
View File

@ -0,0 +1,16 @@
# Please refer https://aka.ms/HTTPSinContainer on how to setup an https developer certificate for your ASP .NET Core service.
version: '3.4'
services:
efb:
image: efb
build:
context: .
dockerfile: ./Dockerfile
ports:
- 5000:5000
environment:
- ASPNETCORE_ENVIRONMENT=Development
volumes:
- ~/.vsdbg:/remote_debugger:rw

16
docker-compose.yml Normal file
View File

@ -0,0 +1,16 @@
# Please refer https://aka.ms/HTTPSinContainer on how to setup an https developer certificate for your ASP .NET Core service.
version: '3.4'
services:
efb:
image: efb
build:
context: .
dockerfile: ./Dockerfile
ports:
- 5000:5000
environment:
- MongoDBConnectionString=
- MySQLPassword=
- ChartFoxAPIKey=