Host Blazor Server on sub path - c#

I want to host my Blazor Server app under http://myraspberry/sample. That's why I've set the path base by calling app.UsePathBase("/sample"). Since everything is working fine on my Dev machine, I ship the app as a single executable to my Raspberry via dotnet publish -r linux-arm -c Release /p:PublishSingleFile=true. I can successfully start the app after configuring NGINX as reverse proxy and the logic is working, but it looks horrible. All the static assets (images, CSS, etc.) are not loaded - HTTP 404.
I've already tried app.UseStaticFiles("/wwwroot") and setting the base within _Host.cshtml to <base href="~/sample" /> instead of UsePathBase("/sample") - both without success. But the necessary files are there - I can see them using dir on the Raspberry.
Any ideas?

It turned out to be a trivial problem: I just SSHed into my Raspberry and this set the Content root path of the app to /home/myuser instead of the deployment directory. After cd /deploymentDirectory, everything is working.

Related

ASP .NET + Docker on linux throws system.io.filenotfoundexception: could not find file

I have an error in my .NET Web Api project when I run it with Docker on linux. This is just a very small email service that I want to host . The file that throws the error is the html email template file, so its a .html file.
My service works in debug mode on windwos and also in docker running on windows, however when I run it on my webserver and try to send an email it throws
system.io.filenotfoundexception: could not find file
the relative path should be in docker:
/app/Templates/email-template.html
I already search in the internet for a solution but did not found it for myself.
What I tried so far are:
a)
Changing the path in the EmailService.cs file
//1st try
Directory.GetCurrentDirectory() + "/Templates/email-template.html"
//2nd try
#"Templates/email-template.html"
//3rd try
#"templates/email-template.html"
//4th try
#"email-template.html"
In the docker file I tried to copy the files to the workdir file because I read that maybe they did not got copied during the docker build
I tried those copy stuffs in the docker files
#1
COPY MailService.WebApi/Templates/email-template.html /app/templates/
#2
COPY MailService.WebApi/Templates/email-template.html .
#3
COPY ["MailService.WebApi/Templates/email-template.html", "MailService.WebApi/"]
I really don't understand why its not working on linux since it is percefly running on windows (both debug mode and docker).

How to create and use docker volumes on Asp core Web app (MVC)

I have web app and I'm using docker to deploy it to Linux server. I'm using ASP .NET CORE 2.1, MVC model for my app, and I publish it through Visual studio's integrated Container Registry to docker hub. from my server i pull image, and then run it. Problem is, every time I publish update to my app it resets all files in app, as it should, that's how containers work. But I need some files to stay in server and not to reset every time i update my app, so i need to use volumes. But I can't figure out how to use ASP CORE app and docker volumes, I think i can create them, but how to access them from app ?
I'v tried some methods I found on web,
So normaly I to run docker I pull it from hub.docker with: docker pull mydockerid/appname:tag
Then, run it with command: docker run -p 3000:80 mydockerid/appname:tag
and that's it.
I'v tried : docker run -p 3000:80 -v ~mnt/files/xml:/xml mydockerid/appname:tag
As I understood it it should make docker use server folder, "mnt/files/xml" as folder in my app named "xml", but doesn't work.
I'm also Using Digital ocean and directory "mnt/files/xml" is volume connected to droplet.
Perfect solution would be so I could create docker volume inside droplets volume, but really any solution that works would be great !
Thanks, for Help !
Okay so I was close,
to create volume in docker you need to chose directory from server and folder from app.
the problem for me was, I was showing wrong directory in app. Because in docker container lets say root folder is under /app/root, so was my xml folder, all I needed to fix is to use docker run -p 3000:80 -v ~mnt/files/xml:/app/xml mydockerid/appname:tag instead of docker run -p 3000:80 -v ~mnt/files/xml:/xml mydockerid/appname:tag first directory is always from server and second is always from app.
As for volumes in digital Ocean:
Go to Volumes under manage on left.
Press Create Volume button on top right.
Choose configuration of Volume, then attach it to your droplet.
to mount it:
$ mkdir -p /mnt/files
# Mount your volume at the newly-created mount point:
$ mount -o discard,defaults,noatime /dev/disk/by-id/scsi-0DO_volume_name /mnt/files
# Change fstab so the volume will be mounted after a reboot
$ echo '/dev/disk/by-id/scsi-0DO_volume_name /mnt/files ext4 defaults,nofail,discard 0 0' | sudo tee -a /etc/fstab
Digital Ocean will actualy show all these comands with your volume names if you go into "Config instruction" under "More" on your Volume.
Then becouse my DO volume is mounted to /mnt/files I connect to server via filezila, put needed files there in folder called "xml" and run the docker container with docker run -p 3000:80 -v ~mnt/files/xml:/xml mydockerid/appname:tag, Now whatever is in folder xml in server. will be read at it is inside my app inside, folder called xml, and I can update app and the folder will never loose data. Also I can move this DO volume to another DO droplet without data loss.

No executable found matching command "dotnet-/../.dll" when running dotnet core docker image in Azure Web App on Linux

1. Background
I'm currently working on the following build/deployment pipeline:
Github (https://github.com/devedse/DeveMazeGeneratorCore)
Travis Build (https://travis-ci.org/devedse/DeveMazeGeneratorCore/jobs/196910720)
dotnet restore
dotnet build
dotnet publish
docker create image
docker publish image to hub
Docker image hub (https://hub.docker.com/r/devedse/devemazegeneratorcore/)
Use Azure Web App on Linux to execute deployment (http://devemazegeneratorcoredocker.azurewebsites.net/api/mazes/MazePath/512/512)
.
2. Problem
Whenever I push something to the Github repository, a build is kicked off and step 1-3 are being executed correctly.
However, the website on Azure is unreachable.
I used SCM to browse to the debug console (https://devemazegeneratorcoredocker.scm.azurewebsites.net/DebugConsole/Default.cshtml (for future reference)) and executed the following commands to find the log files that were generated by Docker:
and then used the following commands to read them:
cat docker_128_err.log
cat docker_128_out.log
The out log showed the following results (which seem correct):
Login Succeeded
latest: Pulling from devedse/devemazegeneratorcore
5040bd298390: Already exists
fce5728aad85: Already exists
76610ec20bf5: Already exists
51ee4768b31d: Already exists
4dc55ff439a1: Already exists
9cb727c7d7a0: Already exists
2bea08464ad0: Pulling fs layer
2bea08464ad0: Verifying Checksum
2bea08464ad0: Download complete
2bea08464ad0: Pull complete
Digest: sha256:647f3db3daa3330b7eb109a1c604e5bd403c2c7089b3c18c5e9249a9805d3a4d
Status: Downloaded newer image for devedse/devemazegeneratorcore:latest
Login Succeeded
latest: Pulling from devedse/devemazegeneratorcore
Digest: sha256:647f3db3daa3330b7eb109a1c604e5bd403c2c7089b3c18c5e9249a9805d3a4d
Status: Image is up to date for devedse/devemazegeneratorcore:latest
The error log however, shows the following errors:
2017-01-31T13:11:46.757760723Z No executable found matching command "dotnet-/home/DeveMazeGeneratorCoreWebPublish/DeveMazeGeneratorWeb.dll"
The strange thing is, is that whenever I run the image locally, it all works fine:
docker run -it --rm -p 0.0.0.0:5001:80 devedse/devemazegeneratorcore:latest
Somehow there seems to be a difference in running a Docker image on a Linux machine in Azure, compared to my local Docker installation which runs the Docker images on the default VM that's being installed when you install Docker for Windows.
3. Configuration files used:
.travis.yml: (https://github.com/devedse/DeveMazeGeneratorCore/blob/master/.travis.yml)
Dockerfile: (https://github.com/devedse/DeveMazeGeneratorCore/blob/master/Scripts/Docker/Dockerfile)
4. Summary
So summarizing, it seems that running Docker on Azure is being executed in a different manner then when doing this locally. Does anyone have an idea on what this could be/how to solve it?
Again, (just for easy reference), the error:
2017-01-31T13:11:46.757760723Z No executable found matching command "dotnet-/home/DeveMazeGeneratorCoreWebPublish/DeveMazeGeneratorWeb.dll"
Modify your image to put your application bits somewhere other than /home.
/home is where Azure App Service on Linux bind-mounts the persistent site volume, which is a disk that is shared across instances and is persisted between restarts.
You don't have to use it (you may not have any use for it when running your own image), but anything in your image's /home will disappear at runtime.

Can't find .bin file generated by app inside docker container

I have a c#/mono app running inside a docker container, using the very cool Dokku.
The app allows for token authentication and saves the keys used to validate incoming tokens inside the folder /keyChain/keyChain.bin in the root folder of the app. The app generates this folder and file by itself when it soes not exists, usually after a fresh deploy and the first auth requests comes in.
I need to mount the keyChain folder as a docker volume so the keychain gets persisted between deploys and not all users sessions are expired, forcing all users to sign in again.
However, although the app runs fine and auth works, the keyChain folder and it's contents are nowhere to be found inside the app folder, inside the Docker container, so there is nothing to mount...
Running dokku run app-name ls /app shows the contents of the app but not the keyChain folder. Running dokku run app-name find /app -type f -name "keyChain.bin" to just look for the file that way yields no results either.
I am using the NancyFx framework for the app with the Nancy.Authentication.Token package.
I am not fully sure if this is a docker/dokku related issue, a c#/mono issue or NancyFx/Nancy.Authentication.Token issue. Remember, the apps WORKS, so the keyChain.bin file must be inside the container somewhere...
Any insight is appreciated :-).

Asp.Net Core - Error cannot execute binary file on published (Ubuntu 14.04) web application with supervisor

I am not sure if this is the right place to ask, but here it is: I created an ASP.NET Core web application, and copied all the files on my Ubuntu 14.04 server. I can compile and run without a problem, but now I want this application/web site to run permanently.
I followed all the steps described here https://docs.asp.net/en/latest/publishing/linuxproduction.html, installed nginx as reverse proxy to run with apache, and all of this run perfectly well.
BUT, trying to use supervisor and start the app from it, I systematically get an error /usr/bin/dotnet cannot execute binary file. But, if I move to be in the directory where the application is published, and manually type dotnet appname.dll it does start without a glitch.
I am not sure where to look to get this to work with supervisor. Thanks for your help (and if this question should be somewhere else, let me know)
I finally solved my problem, replacing the equivalent of the line command=bash /usr/bin/dotnet /var/aspnetcore/HelloMVC/HelloMVC.dll as described in https://docs.asp.net/en/latest/publishing/linuxproduction.html under "Configuring Supervisor" by a little script, far from perfect as I get a Warning: HOME environment variable not set.
Anyway, here is the script:
#!/bin/bash
cd /var/aspnetcore/foesuivi/
dotnet FoESuivi.dll
cd $HOME
As a windows programmer, I don't know much about bash scripting, but I certainly can see that I would need to give a value to $HOME before the cd command.
Anyway, after doing a chmod +x to the sh file, and replacing the command= with the full name of the sh file, it is now working, I can reboot and my site is immediately available.

Categories

Resources