'GitLab pipeline with dotnet and node image
I'm creating a GitLab pipeline which should build
, test
and deploy
a dotnet core application with Angular application. So far so good!
This project was created using dotnet cli with dotnet new angular
.
For this pipeline I have a default image: mcr.microsoft.com/dotnet/sdk:5.0.103
The problem is that all pipeline jobs need a node installation, because by default when I execute the command dotnet build
it executes both node
and dotnet
. The same applies for dotnet publish
. This is all configured by default in the csproj
file.
To solve this issue I added to before_script
section the following command:
before_script:
- curl -sL https://deb.nodesource.com/setup_10.x | bash -
- apt-get install -y nodejs
The pipeline is working, but I wonder if this approach is ok, beucase every job will execute the apt-get
which causes some performance issues in the pipeline.
Is there a way to make this more reliable? cache for example?
This is how my pipeline looks like:
image: mcr.microsoft.com/dotnet/sdk:5.0.103
stages:
- build
- tests
- deploy
variables:
CSPROJ_PATH: 'TechDay/TechDay.csproj'
before_script:
- curl -sL https://deb.nodesource.com/setup_10.x | bash -
- apt-get install -y nodejs
build:
stage: build
script:
- 'dotnet build $CSPROJ_PATH'
tests:
stage: tests
script:
- 'dotnet test $CSPROJ_PATH'
deploy:
stage: deploy
script:
- 'dotnet publish $CSPROJ_PATH'
Solution 1:[1]
I started doing my pipelines the way you did, but have since switched to pulling in a Node image for the NPM build step, and removing that step from my .csproj
file. This allows for caching of the Node image and greatly increased my pipeline performance. You then must define the .Net SDK image in each subsequent job instead of globally. I have added in an analogous version of my setup in your pipeline file. I assumed you used the standard ClientApp
and wwwroot
structure for client source and distribution locations, respectively.
stages:
- build
- tests
- deploy
variables:
CSPROJ_PATH: 'TechDay/TechDay.csproj'
NPM_ROOT: TechDay/ClientApp
NPM_DIST: TechDay/wwwroot
build-npm:
image: node:16
stage: build
script:
- cd $NPM_ROOT
- npm install
- npm run build
artifacts:
paths:
- $NPM_DIST/
expire_in: 20 minutes
build:
image: mcr.microsoft.com/dotnet/sdk:5.0.103
stage: build
script:
- 'dotnet build $CSPROJ_PATH'
tests:
image: mcr.microsoft.com/dotnet/sdk:5.0.103
stage: tests
script:
- 'dotnet test $CSPROJ_PATH'
deploy:
image: mcr.microsoft.com/dotnet/sdk:5.0.103
stage: deploy
script:
- 'dotnet publish $CSPROJ_PATH'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 |