We have a basic Docker file which need to build our ASP.NET Core application. Our frontend is an Angular2 one.
In our current process we do:
npm run build: build the angular2 frontend part, which write output JS files in/wwwroot. These files will be included by ASP.NET Core views and controllers.- Then we
docker buildwhich build and encapsulate our ASP.NET Core project. We then intend to deploy it anywhere.
Our DockerFile:
FROM microsoft/dotnet:latest
COPY . /app
WORKDIR /app
RUN ["dotnet", "restore"]
RUN ["dotnet", "build"]
EXPOSE 5000/tcp
ENV ASPNETCORE_URLS http://*:5000
ENTRYPOINT ["dotnet", "run"]
Our question
How to add in our dockerfiles steps to:
- Run
npm installrequired files for our Angular2 frontend. Ourpackage.jsonfile is at ASP.NET project root. - Run
npm run build:prod: which build Angular2 project and generated files in wwwroot.
Before running dotnet build. We tried to simply try to indicate these commands before RUN ["dotnet", "build"] :
RUN npm install
RUN npm install -g angular-cli
RUN npm run build:prod
but Azure returns an "unexpected Error" without more details.
scriptsection in project.json (learn.microsoft.com/en-us/dotnet/articles/core/tools/…)? There are pre and post compile/processing triggers for itdotnet publishinstead, this will generate binaries file and put these binaries into your docker container similar to Scott's blog hanselman.com/blog/…. Your current approach also seems to include the source code into the docker container, which I'd personally consider a bad idea to deploy your source code on the servers (in case your server gets compromised).npm installandnpm run build:prodcommands?"prepublish": [ "npm install","npm run build:prod" ],etc. The default project.json already hasnpm installas prepublish step. Not sure how it changes with csproj yet