azuredevops docker build failing while coping the files after the build - docker

I have below task in my build pipeline:
- bash: |
echo "To test file exists and can be copied inside DOckerfile"
cat $(System.DefaultWorkingDirectory)/configCreate/properties/config.properties
ls -ltr $(System.DefaultWorkingDirectory)/configCreate/pipelines/
cd $(System.DefaultWorkingDirectory)/configCreate/
echo $(pwd)
ls -ltr $(System.DefaultWorkingDirectory)/configCreate/
echo "Started Building Docker Image"
docker build -t test -f Dockerfile .
displayName: 'Build Docker Image'
But it fails, while coping configCreate/properties/config.properties inside the dockefile.
Dockerfile
COPY properties/config.properties ${SDC_HOME}
Also I tried to pass the workingDIR as $(System.DefaultWorkingDirectory)/configCreate during the Docker build command as argument and my Docker file would be then
COPY ${workingDIR}/configCreate/properties/config.properties ${SDC_HOME}
Everytime it fails stating No such file or directory
Is there something I should do so that files can be copied ?

You have to pass workingDirctory context like below in order to files to be copied properly inside Docker.
- bash: |
cd $(System.DefaultWorkingDirectory)/configCreate/
echo "Started Building Docker Image with tag $latestECRTag"
docker build -t test:latest -f Dockerfile .
displayName: 'Build Docker Image with Tag.'
workingDirectory: $(System.DefaultWorkingDirectory)/configCreate/
now inside Dockerfile copy is working fine.
COPY properties/config.properties ${SDC_HOME}
Missing this workingDirectory will cause no files or directory error.

Related

AzureDevops Buildpipeline can not recognise docker volume mount

In my build pipeline, I'm trying to run the below task:
The main responsibility of the task is to mount the volume for Test and the Script from the AzDo to the container's working dir which is /app/ and then run the test(basically it will run npm test inside the container). But unfortunately, I don't see any outcomes. Hence I changed the command as ls -ltrR /app at the end of the docker run to check if the files are copied or not. But I see the directory is created but no files are inside.
So, to prove the files exist in $(System.DefaultWorkingDirectory) for AzDo. I tried to run all kinds of ls commands prior to docker-run which shows that the files do exist in the $(System.DefaultWorkingDirectory). But for some reason files are not mapped in docker containers. I tried to use PWD and $(Build.SourcesDirectory) but in all cases, it is not working.
I tried to replicate the same docker run command using in my local workstation, it works as expected. So, can anyone suggest how to mount the files in the docker run using AzDo build task?
- task: Bash#3
inputs:
targetType: 'inline'
script: |
echo "check in if Scripts and Tests file exists"
ls -Rtlr ./Script
cat ./Script/dev_blueprint_jest2/MyJavaScript.js
ls -ltrR $PWD/Script
ls -ltr $PWD/Test
ls -ltrR $(Build.SourcesDirectory)/Script/
docker run -v $(System.DefaultWorkingDirectory)/Script/:/app/ScriptStages/ -v $(System.DefaultWorkingDirectory)/Test/:/app/Test/ -i dockerimage ls -ltrR /app/
workingDirectory: $(System.DefaultWorkingDirectory)
displayName: 'Run the JS test pipeline.

empty allure-report. allure-results directory has all results , but data's allure-report directory (test-cases, attachment) is empty

prompt with a solution to receive an empty Allure-report on a remote machine. The results themselves are generated and added to the allure-results folder, but for some reason allure-report is displayed empty, that is, it does not add data to the allure-report / data / test-cases folder, what might be wrong?
allure-results path: /var/lib/jenkins/workspace/my-project/allure-results
[my-project] $ /var/lib/jenkins/tools/ru.yandex.qatools.allure.jenkins.tools.AllureCommandlineInstallation/Allure_Commandline/bin/allure generate /var/lib/jenkins/workspace/my-project/allure-results -c -o /var/lib/jenkins/workspace/my-project/allure-report
Report successfully generated to /var/lib/jenkins/workspace/my-project/allure-report
Allure report was successfully generated.
Creating artifact for the build.
Artifact was added to the build.
Finished: SUCCESS
and also my DockerFile
FROM python:latest as python3
FROM selenium/standalone-chrome
USER root
WORKDIR /my-projest
ADD . /my-projest
RUN pip3 install --no-cache-dir --user -r requirements.txt
RUN sudo pip3 install pytest
RUN ["pytest", "tests/GUI/test_main_page.py", "-s", "-v", "--alluredir=allure-results"]
In Jenkins I have shell command
IMAGE_NAME="myimage"
CONTAINER_NAME="mycontainer"
echo "Check current working directory"
WORKSPACE=`pwd`
pwd
echo "Build docker image and run container"
docker build -t $IMAGE_NAME .
docker run -d --name $CONTAINER_NAME $IMAGE_NAME
echo "Copy allure-results into Jenkins container"
docker cp $CONTAINER_NAME:my-project/allure-results allure-results
echo "Cleanup"
docker stop $CONTAINER_NAME
docker rm $CONTAINER_NAME
docker rmi $IMAGE_NAME
enter image description here
I fixed this problem. In Jenkins Server was set the oldest version Allure Commandline("From Maven Central")>version 2.6.0 and I set the newest version 2.13.9 and hurray! the report shows the results

Why is the docker image not building?

I was following the tutorial on the official website.
https://docs.docker.com/get-started/part2/#build-the-app
I created a directory named dir and added the Dockerfile, app.py and requirements.txt. When I try to build this, the error is-
root#ubuntu:~/dir# docker build -t hello
"docker build" requires exactly 1 argument.
See 'docker build --help'.
Usage: docker build [OPTIONS] PATH | URL | - [flags]
Build an image from a Dockerfile
You forgot to mention location of context-root
#>docker build -t hello .
Add a . at the end if Dockerfile is at the current location

Can we build a docker image using .tar or zip archive

Can we build a docker image using tarball or zip archive which includes dockerfile inside that. I need to build a image from archives by using docker api.
Is there any reference or resource , I have search for 3o minutes but couldn't find anything.
Help me, please!
Thanks in advance!
yes a dockerimage can be build from a tarball containing the Dockerfile.
Let's assume we have a dockerfile called myDockerfile which contains the following scripts
FROM ubuntu
COPY ./venv /
CMD ["/bin/bash"]
myDockerFile is present inside the folder dockerfiles
FOLDER --> dockerfiles
FILE -----------> myDockerFile
the tarball for folder dockerfiles is called dockerfiles.tar
the docker command to build the image will be:-
cat dockerfiles.tar | docker build - -f dockerfiles/myDockerFile -t mydockerimage
note:-
-f denotes the docker file in context to the tarball , if the dockerfile is called 'Dockerfile'
then there is no need to mention the name of the filename verbose
You can use docker load command to get more information visit
Do you mean, that your tar.gz is containing a Dockerfile and you would like to build the image of it? As it is if you download a archive from a github release, for example: https://github.com/nginxinc/docker-nginx/releases?
Yes you can:
#!/bin/bash
wget "https://github.com/nginxinc/docker-nginx/archive/1.13.2.tar.gz"
tar xvf 1.13.2.tar.gz --strip-components 3 docker-nginx-1.13.2/stable/alpine/Dockerfile && docker build . -t mynginx

docker build is not work

I can't seem to get docker build to run correctly:
wangyaos-MBP-3:~ wangyao$ cd /Users/wangyao/Ozintel/docker/flexcloud/
wangyaos-MBP-3:flexcloud wangyao$ ls
Dockerfile apache-tomcat-7.0.62 jdk1.8.0_45.jdk
wangyaos--3:flexcloud wangyao$ docker build -t="Users/wangyao/Ozintel/docker/flexcloud" .
Invalid namespace name (Users). Only [a-z0-9-_] are allowed.
wangyaos-MBP-3:flexcloud wangyao$ cd /Users/wangyao/
wangyaos-MBP-3:~ wangyao$ docker build -t="Users/wangyao/Ozintel/docker/flexcloud" .
Cannot locate Dockerfile: Dockerfile
wangyaos-MBP-3:~ wangyao$ docker build -t="Users/wangyao/Ozintel/docker/flexcloud"
docker: "build" requires 1 argument.
See 'docker build --help'.
Usage: docker build [OPTIONS] PATH | URL | -
Build a new image from the source code at PATH
How should I use docker build?
Slow down and take a look at the docs.
To use docker build, the easiest way is to cd into the directory with the Dockerfile then run something like:
$ docker build -t flexcloud .
The -t argument specifies the repository name and tag, not the directory with the Dockerfile. If you want to give a path to a different Dockerfile, you can use the -f argument. The . at the end specifies the "build context", in this case the current working directory.

Resources