Last post Jan 19, 2018 05:53 AM by Edward Z
Jan 17, 2018 03:33 PM|NicolasREY|LINK
I can't figure out how I am supposed to handle static files in different modes (I work with VSTS Ci/Cd using Docker)
Considering the following use case (_Layout.cshtml) :
@* CSS *@
<link rel="stylesheet" href="~/css/bootstrap-flatly.css" />
<link rel="stylesheet" href="https://bootswatch.com/3/flatly/bootstrap.min.css"
asp-fallback-test-class="sr-only" asp-fallback-test-property="position" asp-fallback-test-value="absolute" />
@* JS *@
If I'am in Staging or Production Env, the CDN are called first, then a fallback allows to load lib from the published local wwwroot/lib/ folder.
Right, if CDN fails, the fallback is called, but how these libs are supposed to be published on my server ? I guess that tracking all the files within git and push them on my remotes branches and then let my Ci/Cd pipeline (VSTS ) publish them
is not the correct way.
Should we execute a bower, or npm or whatever script command after publishing the application on the remote server in order to automatically get all static files dependencies ?
Another point : as CDN url are set in the code, they may not match with my local libraries (updated with bower), so there could be version differences between my CDN and local lib, is it an acceptable point, what is the pros and the cons about that, I don't
Jan 18, 2018 09:26 AM|Edward Z|LINK
>> I guess that tracking all the files within git and push them on my remotes branches and then let my Ci/Cd pipeline (VSTS ) publish them is not the correct way.
In general, there are multiple static file types in wwwroot like js, cs and images. While using Git, we include the wwwroot folder content.
For js reference, there are two ways, including the local js files and installing the reference while building and running the project. If you check the Asp.net Core MVC project, you will find it includes the js files in project and there is no additional
task to install the packages. But, if you check Asp.net Core Angular template, you will find it add additional task to install the packages. I think it depends on whether you have many packages to install.
>> so there could be version differences between my CDN and local lib,
We should keep the version the same between CDN and local lib while developing. In my option, I would suggest you use local lib directly without using CDN.
Jan 18, 2018 09:54 AM|NicolasREY|LINK
Hi Edward Z,
Well consdering that my build steps are made by VSTS directly using the source code on the source manager (I also use VSTS for this), then if
I don't track 'wwwroot\lib' files (I do track all other wwwroot\css, wwwroot\js and so on ...), then these libs are not presents on VSTS source manager, then the publish setp can't put them into the artifact on the VSTS server.
Here is the concerned part of the .gitignore file :
# Uncomment if you have tasks that create the project's static files in wwwroot
To make it more complex, I use a Dockerfile launched by VSTS to build and publish when triggered on a PR:
FROM microsoft/aspnetcore-build:latest AS build-env
# Copy csproj and restore as distinct layers
COPY *.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY . ./
RUN dotnet publish -c Release -o out
# Build runtime image
ENV ASPNETCORE_URLS http://+:5000
COPY --from=build-env /app/out .
ENTRYPOINT ["dotnet", "WebPortal.dll"]
Then the build docker image is tagged and pushed to a private Docker Hub. The Cd pipeline finish the operation launching a script on my remote server that pull the image from the Doker hub and up the container (using docker-compose, it works like charm).
BUT in my docker container, if I look at my fodlers, in wwwroot : I have all my tracked files (normal) except the lib folder (that stores all third party librairies using bower on my dev machine) => also normal.
So it works because CDN are played before the fallback,but if any CDN url fails, I have no fallback! Is there a way to play a bower or npm or whatever command on my remote server (ideally inside my docker container) to make get locally (in my containerID/webportal/wwwroot/lib)
all my libraries that are required (listed in my bower.json)
Thanks for your help
Jan 19, 2018 05:53 AM|Edward Z|LINK
>> Is there a way to play a bower or npm or whatever command on my remote server (ideally inside my docker container) to make get locally (in my containerID/webportal/wwwroot/lib) all my libraries that are required (listed in my bower.json)
Yes, you could run npm, you could refer link below for using packages inCI/CD.
# Use Team Build to restore and publish npm packages