WebSharper ui.next site working locally but not in docker - mono

I have a site that's build using mono and WebSharper.UI.Next. It's selfhosted (Owin) and works flawlessly on my machine directly. However when I try executing it from within a docker container (FROM mono:3.10-onbuild) requesting one of the WebSHarper script files "dissappear" E.g. WebSharper.Collections.min.js returns a 404.
This behaviour can be reproduced with the project created by WebSHarpers client-server selfhosted Owin project template and the below dockerfile
FROM mono:3.10-onbuild
RUN ln -s /usr/src/app/build /usr/src/app/bin
CMD mono ./Site.exe http://*:9000
EXPOSE 9000
(Site should obviously match the name of the site being used)

It turns out that the trick is to override the default root directory when running in the docker container. changing the CMD from OP to
CMD mono ./Site.exe _PublishedWebsites/Site/ http://*:9000
Will override the default home dir then I get all the scripts alright.

Related

docker image not working or running properly

This is part of a major issue i've been fighting to get resolve in a span of 2 or even 3 weeks, first of all, i'm not a docker expert, in fact, i don't even know a thing about docker, all i know is that i need to use it in order to make a connection between an api in localhost and my app in react native, the thing is, i manage to make it work on another two projects i created to test docker, but not in the one i actually need to. This is a dockerfile for an api in .net core 2.2
my dockerfile is a combination of the code i found in stackoverflow and the example in docker documentation to create a docker in .net core, this specific file worked for me on another two api, one as a blank project, and the other one with a class library.
The code below shows the dockerfile, when i run the command line and create the image, it shows no errors, but i know there is something wrong, because when i run docker image ls, the docker image is around 200-300mb size, which seems way too small, and when i run that image with docker run... and check the list of docker containers runnning, it shows nothing
FROM mcr.microsoft.com/dotnet/core/sdk:2.2 AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers
WORKDIR /src
COPY ISARRHH.sln ./
COPY ISARRHH.BusinessGraph/*.csproj ./ISARRHH.BusinessGraph/
COPY ISARRHH.APIWeb/*.csproj ./ISARRHH.APIWeb/
RUN dotnet restore
# Copy everything else and build
COPY . ./
WORKDIR /src/ISARRHH.BusinessGraph
RUN dotnet publish -c Release -o /app
WORKDIR /src/ISARRHH.APIWeb
RUN dotnet publish -c Release -o /app
# Build runtime image
FROM mcr.microsoft.com/dotnet/core/aspnet:2.2
WORKDIR /app
COPY --from=build-env /app .
ENTRYPOINT ["dotnet", "isarrhh.dll"]
#######################################################
I want this bloody docker to work, this was the plan b on one of the modules i'm working on, and is giving me a headache, i managed to make it work on another project, i want it to work on this api which works with office 365 and sharepoint
EDIT: this is the project structure
ISARRHH (Solution)
|
|--ISARRHH.APIWeb (API)
| |_Dependencies
| |_Controllers
| |_Models
| |_Properties
| |_appsettings.json
| |_appsettings.Development.json
| |_Authentication.cs
| |_Configuration.cs
| |_Program.cs
| |_ProtectedApiCallHelper.cs
| |_PublicAppUsingUsernamePassword.cs
| |_SiteInformation.cs
| |_Startup.cs
| |_SiteInformation.cs
|
|--ISARRHH.BusinessGraph (Class Library)
| |_Dependencies
| |_UserGraph.cs
|
|--Solution Items
|_Dockerfile
|_.dockerignore
EDIT2: More information
REPOSITORY TAG IMAGE ID CREATED SIZE
isarrhh latest 67fc0628c921 13 minutes ago 268MB
according to this, the image was created succesfully apparently, but when i run it with
docker run -d -p 3001:80 ...
then i check with
docker container ls
i see no container running, also, when i check with the command you provided here
docker logs -t isachile
i get this:
MacBook: ISARRHH$ docker logs -t isachile
2019-07-31T18:49:22.553317346Z Did you mean to run dotnet SDK commands? Please install dotnet SDK from:
2019-07-31T18:49:22.553390430Z https://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
EDIT 3: SOLVED IT -- SORT OF...
i manage to run my docker by manually copy and pasting ever file on a different project, each file individually copy and paste in this second project, and each time creating the docker image, yes, a seriously horrible and tedious process, but it worked, although, we're not considering this solution anymore, since the process is too slow for our scrum project, we need to connect react native to our localhost api, i still need an answer for this
So there's two things here, and neither necessarily indicates a problem with Docker or your Dockerfile.
Size is only 200-300MB
That's about right. You haven't indicated whether you're using Windows or Linux containers, but in either case, most of the weight comes simply from the .NET Core runtime. The whole point of containers is that the host OS is shared (unlike a VM where every VM gets its own separate OS installation). The only things coming from the base OS image are user-specific files and directories. The main system components are proxied to the host operating system. Long and short, I don't know what you're expecting here in terms of size, but honestly 200-300MB is a bit on the large size for an image. It's possible in many cases to package ASP.NET Core app images down to as little as 25MB-30MB, though if you include the full runtime, it's generally going to be closer to your 200-300MB.
The container isn't running.
All the means is that it exited. When the container is run, the entrypoint line will be called, which just starts up the ASP.NET Core app running in Kestrel. That of course runs Program.Main, since it's just a console app, after all. That in turn builds the web host and calls Run, which listens for TCP socket connections, keeping the app running, which therefore keeps the container running.
If the container isn't running, then the app exited. That could happen for different reasons, but the most likely cause is that a runtime exception was thrown during the web host build phase (i.e. something in Program or Startup is throwing an exception). Try running something like:
docker logs -t {container name}
And you'll probably see a stacktrace and exception there. Fix the issue accordingly.

WCF hosted with Docker file not found if publish for "Any CPU"

I'm trying to host WCF with Docker. The problem is that the WCF is built for 32bit. First of all I tried to configure the IIS to enable 32bit app on 64 bit (there is attribute in the config) but without success. Tried with this in my Dockerfile
# install WCF basic docker image
FROM microsoft/wcf
# Next, this Dockerfile creates a directory for your application
WORKDIR BookingApi
# configure the new site in IIS.
RUN powershell -NoProfile -Command \
Import-module IISAdministration; \
New-IISSite -Name "BookingApi" -PhysicalPath C:\BookingAPI -BindingInformation "*:83:" \
Set-IISConfigAttributeValue -ConfigElement "BookingApi" -AttributeName "enable32bitAppOnWin64" -AttributeValue "True"
# This instruction tells the container to listen on port 83.
EXPOSE 83
# The final instruction copies the site you published earlier into the container.
COPY BookingApi/ .
But It fails to build it. So I decided to publish the service with Any CPU and through visual studio it works and responses, but if I use these files and host them via Docker I get 404 - File or directory not found.
What am I missing?
The 32 bit configuration option is for the app pool and can be accomplished as follows. There is undoubtedly a PowerShell equivalent.
RUN c:\windows\system32\inetsrv\appcmd.exe set config -section:system.applicationHost/applicationPools /applicationPoolDefaults.enable32BitAppOnWin64:"True" /commit:apphost

Changing permissions of added file to a Docker volume

In the Docker best practices guide it states:
You are strongly encouraged to use VOLUME for any mutable and/or user-serviceable parts of your image.
And by looking at the source code for e.g. the cpuguy83/nagios image this can clearly be seen done, as everything from nagios to apache config directories are made available as volumes.
However, looking at the same image the apache service (and cgi-scripts for nagios) are run as the nagios user by default. So now I'm in a pickle, as I can't seem to figure how to add my own config files in order to e.g. define more hosts for nagios monitoring. I've tried:
FROM cpuguy83/nagios
ADD my_custom_config.cfg /opt/nagios/etc/conf.d/
RUN chown nagios: /opt/nagios/etc/conf.d/my_custom_config.cfg
CMD ["/opt/local/bin/start_nagios"]
I build as normal, and try to run it with docker run -d -p 8000:80 <image_hash>, however I get the following error:
Error: Cannot open config file '/opt/nagios/etc/conf.d/my_custom_config.cfg' for reading: Permission denied
And sure enough, the permissions in the folder looks like (whist the apache process runs as nagios):
# ls -l /opt/nagios/etc/conf.d/
-rw-rw---- 1 root root 861 Jan 5 13:43 my_custom_config.cfg
Now, this has been answered before (why doesn't chown work in Dockerfile), but no proper solution other than "change the original Dockerfile" has been proposed.
To be honest, I think there's some core concept here I haven't grasped (as I can't see the point of declaring config directories as VOLUME nor running services as anything other than root) - so provided a Dockerfile as above (which follows Docker best practices by adding multiple volumes) is the solution/problem:
To change NAGIOS_USER/APACHE_RUN_USER to 'root' and run everything as root?
To remove the VOLUME declarations in the Dockerfile for nagios?
Other approaches?
How would you extend the nagios dockerfile above with your own config file?
Since you are adding your own my_custom_config.cfg file directly into the container at build time just change the permissions of the my_custom_config.cfg file on your host machine and then build your image using docker build. The host machine permissions are copied into the container image.

Deploying Custom Cartridges on Openshift Origin

I have created a new custom cartridge, in which I have packaged into an rpm using tito and installed using yum. This cartridge is being copied from my spec file to the /usr/libexec/openshift/cartridges directory, however, when I log into the origin home site and try to create an application my cartridge does not show up. I went digging in the ruby scripts and I found that there is a script named cartridge_cache.rb seems to be caching the cartridges it finds within the /usr/libexec/openshift/cartridges directory. I have tried to get origin to reload the cache to include my new cartridge by removing all the cache files within the /var/www/openshift/broker/cache directory then restarting the broker, but I have had no success. Is there somewhere I need to hardcode my cart name to some global variable or something ? Basically, Does anyone know how to get your custom cart to show up on the webpage for creating a new application.
UPDATE: So I ran into a slide deck that had one slide on how to install the cartridge. However, I still have had no success, but here is what I have tried since the previous post:
moved my cartridge directory from /usr/libexec/openshift/cartridges to /usr/libexec/openshift/catridges/v2
ran this command
oo-admin-cartridge -a install -s /usr/libexec/openshift/cartridges/v2/myfirstcart
which the output stated it installed the cartridge.
cleared cache with
bundle exec rake tmp:clear
restarted the openshift broker service
Also, just to make sure the cache was cleared out I went into the Rails console and ran Rails.cache.clear. And still no custom cartridge on the openshift webpage.
It works for me after cleaning cache
cd /var/www/openshift/broker
bundle exec rake tmp:clear
and restarting broker service
service openshift-broker restart
http://openshift.github.io/documentation/oo_administration_guide.html#clear-the-broker-application-cache
MCollective service on Node server (if you have separate servers for broker and node) must be restarted. e.g. with
service ruby193-mcollective restart
After that you should clear the caches on broker server e.g with
/usr/sbin/oo-admin-broker-cache --console
Then you should have new cartridges available

How do you work out the IIS Virtual Path for an application?

When I try to change the ASP.NET version to v4 on IIS 6, I receive the following warning:
Changing the Framework version requires a restart of the W3SVC service. Alternatively, you can change the Framework version without restarting the W3SVC service by running: aspnet_regiis.exe -norestart -s IIS-Viirtual-Path
Do you want to continue (this will change the Framework version and restart the W3SVC service)?
How do I work out IIS-Virtual-Path?
I have tried the obvious paths i.e.:
aspnet_regiis.exe -norestart -s "/WebSites/Extranet/AppName"
Where WebSites is the name of the folder in IIS, Extranet the name of the root app and AppName the name of the Virtual Directory application I am trying to change.
Thanks!
Edit:
How do I work out the virtual path for the Auth virtual directory in following IIS6 setup:
(source: imgbag.com)
I have tried:
aspnet_regiis.exe -norestart -s "/Web Sites/Extranet/Auth"
aspnet_regiis.exe -norestart -s "Auth"
I get:
Installation stopped because the specified path (WhateverIPutIn) is invalid.
I solved it. I had to use:
aspnet_regiis -lk to get a list of the folders in "IIS" format
Then I do something like:
aspnet_regiis.exe -norestart -s "W3SVC/1234567/root/AppName"
My problem running aspnet_regiis -lk was that I got an incomplete list of IDs and also I didn't know which ID corresponded to the Website i wanted to work on.
An easier way to find the IDs for your websites is by clicking on the "Website" node (folder) in IIS as in this picture. On the right side you should see a list of all websites with their "Identifier"s, State, IPs and ports.
Here's a good summary
W3SVC/ + [Site Identifier from IIS Console] + /root
for example W3SVC/1234567/root
To find the Identifier
Click on the Websites node (folder) in IIS.
On the right hand side is a list of all websites with their Identifiers, State, IPs and ports.
Now all together
aspnet_regiis.exe -norestart -s "W3SVC/1234567/root"
Finally
Add of the virtual directory to the end W3SVC/1234567/root/APPNAME if you need to
I think your need to use a path starting with /W3SVC. Maybe this article can help you further.
To change Framework version without restarting W3SVC:
Run aspnet_regiis.exe -norestart -s IIS-Virtual-Path
aspnet_regiis.exe should be run from %SystemRoot%\Microsoft.NET\Framework(required dotnet version)
eg C:\WindowsMicrosoft.NET\Framework\v4.0.30319
IIS-Virtual-Path is: W3SVC/(WebsiteID)/root[/AppName] Where
(WebsiteID) is the identifier as listed in IIS (see Diego C's image above) and
[/appname] is an optional virtual directory below your website. (eg W3SVC/1234567890/root/dotnetnuke)
Open a command prompt
Navigate (CD) to C:\WindowsMicrosoft.NET\Framework\v4.0.30319
Execute aspnet_regiis.exe -norestart -s “W3SVC/1234567890/root/dotnetnuke”
I was able to follow the advice according to joshcomley's post here, but had to get the name of the virtual path from the generated XML file.
You can use IIS's export site config to a file (xml file). Inside, there are a few tags that look like this:
<IIsWebVirtualDir Location ="/LM/W3SVC/2070355274/root"
Just pick the first one that ending with "root".
that worked great.
(tried, but cant post image here)