I am trying to deploy my docker images from Docker Hub to Rancher. When I do that, I am getting only updating status and then after some time, I am getting deployment timeout. I am new to Rancher and trying to go through documents but not able to understand it properly. Can anyone assist me to do this?
I already tried to pull the image and after some time it shows "deployment does not have minimum availability".
Below is my .gitlab-ci.yml file configuration:
stages:
- build
- publish
.build: &build_template
stage: build
image: microsoft/dotnet:2.2-sdk-alpine
cache:
key: "$CI_PROJECT_NAMESPACE-$CI_PROJECT_NAME"
paths:
- .nuget/
script:
- dotnet restore -s https://api.nuget.org/v3/index.json --packages ./.nuget/
- dotnet publish --no-restore -c Release -o ./docker/publish/
develop_build:
<<: *build_template
only:
- develop
artifacts:
expire_in: 1 day
paths:
- docker/
.docker: &docker_template
stage: publish
image: docker:stable-dind
script:
- mkdir docker/app/
- mv docker/publish/$ASSEMBLY_NAME.* docker/app/
- mv docker/publish/*.config docker/app/
- mv docker/publish/*.json docker/app/
- cp Dockerfile docker/
- docker build -t $TAG ./docker/
- docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
- docker push $TAG
develop_docker:
<<: *docker_template
only:
- develop
dependencies:
- develop_build
variables:
ASSEMBLY_NAME: app
TAG: $CI_REGISTRY_IMAGE/$CI_COMMIT_REF_NAME:$CI_PIPELINE_ID
Below is my DockerFile:
# Dockerfile
FROM microsoft/dotnet:sdk AS build-env
WORKDIR /app
# Copy csproj and restore as distinct layers set
COPY ./DataStore/DataStore/*.csproj ./
RUN dotnet restore
# Copy everything else and build
COPY *[^.csproj] ./
RUN dotnet publish -c Release -o out
# Build runtime images
FROM microsoft/dotnet:aspnetcore-runtime
ENTRYPOINT ["dotnet", "DataStore.dll"]
I want to run my C# web APIs after deploying it to Rancher.
Related
I'm running a CI pipeline in gitlab-runner which is running on a linux machine.
In the pipeline I'm trying to build an image.
The Error I'm getting is,
ci runtime error: rootfs_linux.go:53: mounting "/sys/fs/cgroup" to rootfs "/var/lib/docker/overlay/d6b9ba61e6eed4bcd9c23722ad6f6a9fb05b6c536dbab31f47b835c25c0a343b/merged" caused "no subsystem for mount"
The Dockerfile contains :
# Set the base image to node:12-alpine
FROM node:16.7.0-buster
# Specify where our app will live in the container
WORKDIR /app
# Copy the React App to the container
COPY . /app/
# Prepare the container for building React
RUN npm install
RUN npm install react-scripts#4.0.3 -g
# We want the production version
RUN npm run build
# Prepare nginx
FROM nginx:stable
COPY --from=0 /app/build /usr/share/nginx/html
RUN rm /etc/nginx/conf.d/default.conf
COPY nginx/nginx.conf /etc/nginx/conf.d
# Fire up nginx
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
The gitlab-ci.yml contains :
image: gitlab/dind
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay
stages:
- build
- docker-build
cache:
paths:
- node_modules
yarn-build:
stage: build
image: node:latest
script:
- unset CI
- yarn install
- yarn build
artifacts:
expire_in: 1 hour # the artifacts expire from the artifacts folder after 1 hour
paths:
- build
docker-build:
stage: docker-build
script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD
- docker build -t $CI_REGISTRY_USER/$app_name .
- docker push $CI_REGISTRY_USER/$app_name
I'm not getting how to resolve this, I tried upgrading docker in my linux machine.
I have Installed Gitlab in one of the Ubuntu machine. And I have dotnetcore project in the name of ABC in the Gitlab.
But, In that ABC repo have multiple small doetnetcore application with different different directory like abc1 abc2 abc3 abc4.
I want to write a single pipeline under ABC to create the docker Image whenever developer push the code in the respective directory. but that need to be create docker Image for that only directory.
eg: Developer push the code under abc3 directory, that time pipeline run and create the docker Image for only abc3 directory.
Please help me out with it.
Thanks in Advance...!!!
Below is my pipeline what I have written also Docker file:
stages:
- docker
- build
services:
- docker:dind
before_script:
- "echo $gitlab"
docker-job:
stage: docker
image: docker:dind
script:
- docker login -u username -p password $CI_REGISTRY
- docker build -t dotnetcore .
#- docker push $IMAGE_PUSH:latest
build:
stage: build
tags:
- shell
image: mcr.microsoft.com/dotnet/sdk
script:
- dotnet restore
- dotnet build
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
WORKDIR /app
EXPOSE 80
ENV ASPNETCORE_URLS=http://+:80
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
WORKDIR /src
COPY ["dotnetcore.csproj","./"]
RUN dotnet restore "dotnetcore.csproj"
COPY . .
WORKDIR "/src/"
RUN dotnet build "dotnetcore.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "dotnetcore.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "dotnetcore.dll"]
In this pipeline and dockerfile I am only able to build "dotnetcore" project. But I have dotnetcore1 doctnetcore2 dotnetcore3 projects under the same Repo.
gitlab ci has a only:changes feature. You can define multiple jobs, each for one docker.
job-a:
script: docker build a
only:
changes:
- a/**/*
job-b:
script: docker build b
only:
changes:
- b/**/*
Assuming you have a small number of directories. You can create a job for each directory. Use rules with changes to check if changes were made in the particular directory.
I am working on a gitlab CI/CD project to build an asp.net core application into a docker.
Currently I have 2 possible implementations in mind. The first one have the full logic in the Dockerfile, but I can't visualize the stages in Gitlab this way (build, test, publish). So I thought about moving the main logic to the gitlab-ci.yml file. But what bothers me now is that I have to manage the image docker dotnet versions on 2 places (sdk:3.1, aspnet:3.1.1-alpine3.10). Is it a good idea to deliver the version via build-arg or is there a more elegant solution?
.gitlab-ci.yml
stages:
- build
- test
- docker
build:
stage: build
image: mcr.microsoft.com/dotnet/core/sdk:3.1
only:
- master
script:
- cd src
- dotnet restore --interactive
- dotnet build --configuration Release
- dotnet publish --configuration Release --output ../publish/
artifacts:
paths:
- ./publish/*.*
expire_in: 1 week
tags:
- docker
test:
stage: test
image: mcr.microsoft.com/dotnet/core/sdk:3.1
only:
- master
script:
- cd src
- dotnet test --test-adapter-path:. --logger:"junit;LogFilePath=../../MyProject.xml"
artifacts:
paths:
- ./MyProject.xml
reports:
junit: ./MyProject.xml
tags:
- docker
docker:
stage: docker
image: docker:stable
services:
- docker:dind
variables:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
only:
- master
script:
- docker login -u "gitlab-ci-token" -p "$CI_JOB_TOKEN" $CI_REGISTRY
- docker build --tag "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA" --tag "$CI_REGISTRY_IMAGE:latest" --build-arg EXECUTABLE=Test.WebApi.dll .
- docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA"
- docker push "$CI_REGISTRY_IMAGE:latest"
tags:
- docker
Dockerfile
FROM mcr.microsoft.com/dotnet/core/aspnet:3.1.1-alpine3.10
ARG EXECUTABLE
WORKDIR /app
COPY /publish .
ENV ASPNETCORE_URLS "http://*:5000"
ENV ASPNETCORE_ENVIRONMENT "Staging"
CMD ["dotnet", "$EXECUTABLE"]
Here is my solution, I have defined the variables above and replace them in the docker file with sed
My Solution have this two Projects
Test.WebApi (WebApi Project)
Test.WebApi.UnitTest (Unit Test Project)
#ThomasBrüggemann thanks for the Inspiration.
.gitlab-ci.yml
variables:
PROJECT_NAME: "Test.WebApi"
BUILD_IMAGE: "mcr.microsoft.com/dotnet/core/sdk:3.1"
RUNTIME_IMAGE: "mcr.microsoft.com/dotnet/core/aspnet:3.1.1-alpine3.10"
stages:
- build
- test
- docker
build:
stage: build
image: $BUILD_IMAGE
only:
- master
script:
- cd src/$PROJECT_NAME
- dotnet restore --interactive
- dotnet build --configuration Release
- dotnet publish --configuration Release --output ../../publish/
artifacts:
paths:
- ./publish/*
expire_in: 1 week
tags:
- docker
test:
stage: test
image: $BUILD_IMAGE
only:
- master
script:
- cd src/$PROJECT_NAME.UnitTest
- dotnet test --test-adapter-path:. --logger:"junit;LogFilePath=../../UnitTestResult.xml"
artifacts:
paths:
- ./UnitTestResult.xml
reports:
junit: ./UnitTestResult.xml
tags:
- docker
docker:
stage: docker
image: docker:stable
services:
- docker:18.09.7-dind
variables:
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
only:
- master
script:
# Prepare Dockerfile
- sed -i "s~\$DOCKERIMAGE~$RUNTIME_IMAGE~g" Dockerfile
- sed -i 's/$ENVIRONMENT/Staging/g' Dockerfile
- sed -i "s/\$ENTRYPOINT/$PROJECT_NAME.dll/g" Dockerfile
# Process Dockerfile
- docker login -u "gitlab-ci-token" -p "$CI_JOB_TOKEN" $CI_REGISTRY
- docker build --tag "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA" --tag "$CI_REGISTRY_IMAGE:latest" .
- docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA"
- docker push "$CI_REGISTRY_IMAGE:latest"
tags:
- docker
Dockerfile
FROM $DOCKERIMAGE
WORKDIR /app
COPY /publish .
EXPOSE 5000/tcp
ENV ASPNETCORE_URLS "http://*:5000"
ENV ASPNETCORE_ENVIRONMENT "$ENVIRONMENT"
CMD ["dotnet", "$ENTRYPOINT"]
Here some Version handling when tagging in GitLab-Pipeline:
script:
- COMMIT_DATE=$(git log -1 --format=%cd --date=iso-strict | grep -o '\([0-9]*\)' | tr -d '\n')
- VERSION_PREFIX=$CI_COMMIT_TAG
- VERSION_SUFFIX="${COMMIT_DATE::-6}"
- echo $VERSION_PREFIX-$VERSION_SUFFIX
- sed -i "s:<VersionPrefix>.*</VersionPrefix>:<VersionPrefix>$VERSION_PREFIX</VersionPrefix>:g" [PROJECT].csproj
- dotnet publish --version-suffix $VERSION_SUFFIX -c Release -o ./out
- docker build --tag "$CI_REGISTRY_IMAGE:$VERSION_PREFIX"
only:
- tags
In Project file must
<!-- Version is set by CI-Script do not modify manually -->
<VersionPrefix>0.0.0</VersionPrefix>
<Deterministic>False</Deterministic>
be set
Maybe this is helpful.
Something similar can be done when build without tagging.
I am trying to push my images from Travis CI to docker hub.
Here is my Dockerfile
FROM node:alpine as builder
WORKDIR /app
COPY ./package.json ./
RUN npm install
COPY . .
CMD npm run build
FROM nginx
EXPOSE 3000
COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf
COPY --from=builder /app/build /usr/share/nginx/html
My .travis.yml
sudo: required
services:
- docker
before_install:
- docker build -t aseel/react-test -f ./client/Dockerfile.dev ./client
script:
- docker run -e CI=true aseel/react-test npm run test
after_success:
- docker build -t aseel/multi-client ./client
- docker build -t aseel/multi-nginx ./nginx
- docker build -t aseel/multi-server ./server
- docker build -t aseel/multi-worker ./worker
- echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_ID" --password-stdin
- docker push aseel/multi-server
- docker push aseel/multi-nginx
- docker push aseel/multi-worker
- docker push aseel/multi-client
The reason the push is failing is because this command
docker build -t aseel/multi-client ./client
is failing on travis (but not locally).
More specifically, I'm getting this error on travis
COPY failed: stat
/var/lib/docker/overlay2/135282513e177be132b6978986f878ba61f3b89914b6b2f7030cbafa0d33f629/merged/app/build:
no such file or directory
Any idea why this is happening?
I needed to switch CMD to RUN -- It was a pretty silly mistake
I am trying to use gitlab CI for docker in docker builds and i have it up and running.
My issue is that the nice pipeline functionality of gitlab is somewhat lost since the whole build,test,etc... stages are defined in the DockerFile and not yaml.
I only have a single stage in the yaml right now.
Is there a way to use docker in docker and still leverage gitlab pipelines?
Relevant files.
Dockerfile
# Stage 1 - require and update image
FROM microsoft/aspnetcore-build:2.0.0 AS build
# Update the imgage OS
RUN apt-get update \
&& apt-get install -y
# set the container working directory
WORKDIR /code
# Stage 2 - copy data
# caches restore result by copying csproj file separately
COPY src/Nuget.Config ./src/
COPY src/Inflow.NewsMl.FileLoader/Inflow.NewsMl.FileLoader.csproj ./src/Inflow.NewsMl.FileLoader/
RUN dotnet restore src/Inflow.NewsMl.FileLoader/Inflow.NewsMl.FileLoader.csproj --configfile /code/src/Nuget.Config
COPY src/Inflow.NewsMl.FileLoader.Test/Inflow.NewsMl.FileLoader.Test.csproj ./src/Inflow.NewsMl.FileLoader.Test/
RUN dotnet restore src/Inflow.NewsMl.FileLoader.Test/Inflow.NewsMl.FileLoader.Test.csproj --configfile /code/src/Nuget.Config
# Copy the rest
COPY . .
# Stage 3 - Build and test
RUN dotnet test src/Inflow.NewsMl.FileLoader.Test/Inflow.NewsMl.FileLoader.Test.csproj
# Stage 4 - Deploym to image
RUN dotnet publish src/Inflow.NewsMl.FileLoader --output /code/output --configuration Release
FROM microsoft/aspnetcore:2.0.0
COPY --from=build /code/output /app
WORKDIR /app
ENTRYPOINT [ "dotnet", "Inflow.NewsMl.FileLoader.dll" ]
and the ci runner yaml
image: docker:latest
.before_script:
- docker info
variables:
DOCKER_DRIVER: overlay
CONTAINER_TEST_IMAGE: infomedia/newsml.fileloader:CI_COMMIT_SHA
#$CI_COMMIT_TAG
services:
- docker:dind
stages:
- build
build:
stage: build
#only:
# - tags
#except:
# - master
script:
- docker build -t $CONTAINER_TEST_IMAGE .