Deploying microservices with docker executer

i’m desperate in need of help :(.

Oke, so i’m trying to deploy microservices to a local docker server. My attempt is that the ci/cd pipeline will do a docker build and then a docker push to the registery so my docker server can simply do a docker pull.

My first attempt works when using the shell executer. I have setup a vm as build server with all the tools installed that I need. → works like a charm
However i’d like to insert semantic release to my pipeline and transfer to docker executer.
Now the very very first attempt was already with the docker executer and that part failed.
Why? because my deployment part used the docker image which is necessary to use docker build Dockerfile; but in .net dockerfile includes dotnet publish command so I was continiously getting the error dotnet command not found.

Now I tought hey I can replicate my build server in my pipeline with a alpine image or in my case I used ubuntu. So In my deployment part I used ubuntu image installed docker and dotnet and the went on with my deployment script. → failed yet again :(.

my yaml: → script is what it needs to do and before script was trying to replicate build server and yes I know it’s complex.

image: Microsoft Artifact Registry

stages:

  • build
  • test
  • deploy
    before_script:
  • dotnet restore Test.sln

build:
stage: build

tags:
- dev

script:
- ‘dotnet build --no-restore Test.sln’

tests:
stage: test

tags:
- dev
script:
- ‘dotnet test --no-restore Test.sln’

deploy:
stage: deploy

tags:
- dev
image: ubuntu:20.04
before_script:
- ‘echo installing prequisites’
- ‘apt update && apt upgrade -y’
- ‘apt install wget -y’
- ‘apt install curl -y’
- ‘echo done updating - installing dotnet’
- ‘wget https://packages.microsoft.com/config/ubuntu/22.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb’
- ‘dpkg -i packages-microsoft-prod.deb’
- ‘rm packages-microsoft-prod.deb’
- ‘echo installing docker’
- ‘apt update’
- ‘apt install ca-certificates gnupg lsb-release -y’
- ‘mkdir -p /etc/apt/keyrings’
- ‘curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg’
- ‘echo “deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] Index of linux/ubuntu/ $(lsb_release -cs) stable” | tee /etc/apt/sources.list.d/docker.list > /dev/null’
- ‘apt update’
- ‘apt install docker-ce docker-ce-cli containerd.io docker-compose-plugin -y’
- ‘docker --version’
- ‘apt update’
- ‘apt install docker-compose -y’
- ‘docker-compose --version’
- ‘echo done with prequicites’
script:

  • ‘docker-compose build’
  • ‘echo $dockerHub >> pw.txt’
  • ‘cat pw.txt | docker login --username technologyresearcher --password-stdin’
  • ‘docker push technologyresearcher/test:latest’
  • ‘rm pw.txt’

The problem here is that docker-compose build gives my python errors which I don’t heck know about, but since it is throwing me filenotfound I assume it is search for something, or in this case I think it is stuck on connecting to the outside.

Oke, so What i’m looking for is A) what is the error how can I fix this?
B) if i’m doing it totally wrong, give some information, guides, any internet source cause, I don’t find any sources to deploy with gitlab and microservices at the same time.

EDIT:

so after alternating my yaml file the first attempt I had a problem on docker info.
when removing that I have got this and this is exactly what it tought it would do.
I think this is because the dockerfile contains a dotnet command which cannot be found inside the docker image

EDIt EDit:

Dockerfile:

FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY [“Test/Test.csproj”, “Test/”]
RUN dotnet restore “Test/Test.csproj”
COPY . .
WORKDIR “/src/Test”
RUN dotnet build “Test.csproj” -c Release -o /app/build

FROM build AS publish
RUN dotnet publish “Test.csproj” -c Release -o /app/publish /p:UseAppHost=false

FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT [“dotnet”, “Test.dll”]

Hi!
I think your scenario it’s a candidate to use dind (Docker in docker).
I didn’t do it myself (yet), but it seems to fit your scenario.
Use Docker to build Docker images | GitLab (GitLab doc)
How to Build a Docker Image and Push it to the GitLab Container Registry from a GitLab CI pipeline | by Valentin Despa | DevOps with Valentine | Medium (A nice example).

Hope this help!

BR.-

Gaston.

Yup thank you thats indeed exactly what I need, but there is one problem.

if I do docker build -t image or docker build Dockerfile when using the image docker:20.x.x

I get the error dotnet command not found, I assume that is because my dockerfile has the command dotnet publish.

See edit

Mmmm, can you post your Dockerfile?
Or at least the FROM, where you define which images you’re using as base for your custom image.

Thanks!

posted the dockerfile is generated trough visual studio itself, I didn’t create or modify it, it uses the standard dotnet sdk image, so yes i would guess it would use the image after the from tag in docker in docker. but it seems not.

Hi!
Try to use this image:
mcr.microsoft.com/dotnet/aspnet:6.0-alpine-amd64
I use that image for a similar scenario (less complex, but, at the end, is dotnet on linux)
Hope this helps!

well I hoped for it, but sadly not, exactly the same error-> dotnet restore test.sln dotnet command not found … :frowning: