Building Linux C++ with VSTS - c++

I'm trying to build a C++ app for Linux using VSTS. The build is defined by the Docker container template, and the Agent queue is Hosted Linux.
When running, I get
[error]Unhandled: No Docker file matching /opt/vsts/work/1/s/**/Dockerfile was found.
How do I create the Docker file requested by the error message?

The error means that there isn’t the Dockerfile file existing in working folder, you can include the Dockerfile file in the source control and map to the agent (Get sources of build definition)
There is the Docker image that shared by others, for example: madduci/docker-ubuntu-cpp and the CMake generated files will be in build folder, if you just need to build the C++ project, you can refer to these steps (CMakeLists.txt is in the root of the repository):
Add Docker task (Action: Run a Docker command; Command: run -v $(Build.SourcesDirectory):/project madduci/docker-ubuntu-cpp)
Publish Build Artifacts (Path to publish: $(Build.SourcesDirectory)/build)
If you need to build the docker image, you need to create Dockerfile.

When the Docker task is set to Build an image you get an option to specify a Docker file:
**/Dockerfile means that the task will search your repository for a file named Dockerfile and use that to build the image.
The error you get means that this file can't be found. You can find some examples of Dockerfiles here in the Docker documentation. This blog describes how to build C++ applications that run on a Linux container

Related

AWS CodeBuild with Multi Docker Containers: unable to prepare context: unable to evaluate symlinks in Dockerfile path

so I am trying to deploy my multi-docker container(Frontend, Backend, and Nginx containers) application in AWS BeansTalk. I am using CodeBuild to build the docker images using buildspec.yml file. The build fails when trying to build the first container(containerizing frontend application). Kindly refer to the image attached for the error details.
It is basically saying could not find the Dockerfile in the client directory but the funny thing is that it exists and it works as expected locally when I build the containers with docker-compose.
Here is the project directory:
buildspec.yml file:
For the benefit of others, The reason for the error is that the Dockerfile is missing in the location. Make sure you have the DockerFile inside the directory (./client in this case). It has to be exactly spelled as Dockerfile. If it's not, check the source repo and ensure that the Dockerfile file is committed.

Sonarcloud c++ docker cmake

i was trying to integrate sonarcloud in my build.
I have created a free account in sonarcloud.io and added necessary steps in build pipeline.
When i ran the pipeline, i got the error
ERROR: Error during SonarScanner execution java.lang.IllegalStateException: java.nio.file.NoSuchFileException: /home/vsts/work/1/s/bw-outputs/build-wrapper-dump.json
The process '/home/vsts/work/_tasks/SonarCloudAnalyze_ce096e50-6155-4de8-8800-4221aaeed4a1/1.20.0/sonar-scanner/bin/sonar-scanner' failed with exit code 1
Also, i tried with a .properties file.
sonar.projectKey=jfzlma0838_dockersample
sonar.projectName=dockersample
sonar.projectVersion=1.0
sonar.sources=app
# The build-wrapper output dir
sonar.cfamily.build-wrapper-output=bw-outputs
# Encoding of the source files
sonar.sourceEncoding=UTF-8
full repo here (master)
The most likely cause of this error is that you did not run build wrapper.
Step 1. Download the Build Wrapper:
Build Wrapper for
Linux
Build Wrapper for
macOS
Build Wrapper for
Windows
Step 2. Unzip them and push them to your repository.
Step 3. Add their path to the enviornment variable PATH. You can use the following PowerShell script:
Write-Host "##vso[task.setvariable variable=PATH;]${env:PATH};$newPath";
Note that the path of repository is $(System.DefaultWorkingDirectory) in Azure DevOps.
Step 4. Execute Build Wrapper. You can click this document for detailed steps.

How to load static files with spring boot inside a docker container hosted on AWS?

I got my SpringBoot app running in a docker container built from a Dockerfile and hosted on AWS ubuntu instance.
Everything is working perfectly, except I have an image, a css file and a js file that does not load. Upon inspecting the page, these files show 404 not found error.
I have used winscp to upload my files to my aws instance. In myApp folder is where my docker file is and where I build my container.
Directory Structure is:
myApp
-Dockerfile
-target
-myApp.jar
-src
-main
-java
-[all my code in respective subdirectories]
-resources
-static
-my.js
-my.css
-my.jpg
-templates
-folder1
-html
-html2
-folder2
-html
-html2
I am almost certain my problem lies in the docker container and my dockerfile.
Spring Boot automatically looks for static files in /src/main/resources/static. I'm thinking my docker container does not have this file structure.
Here is my Dockerfile
FROM ubuntu:latest
RUN apt-get update && apt-get install -y openjdk-14-jdk
WORKDIR /usr/local/bin/myApp
ADD . /src/main/resources/static
ADD target/myapp.jar .
ENTRYPOINT ["java", "-jar", "myApp.jar"]
When i build the container it shows everything copied and built successfully, but the files are not being reached. And what is weird to me is spring boot is serving the correct templates from the static folder. I am at a complete loss on this one. I have tried adding the resources individually from the dockerfile and still no luck.
You are setting WORKDIR and then copying .jar into that location using relative path but when you are copying the other stuff (/src/main/resources/static), you are using absolute path which is completely destroying your folder structure (since those files are not copied into folder referenced by your WORKDIR). You have probably forgot .(dot) in front of that path - ./src/main/resources/static.
Run docker exec -it <image-id> bash to get access into your running container and see what was copied where if you are not sure, fixing the stuff in your Dockerfile should be easy from then on.

How to specify the root folder to deploy an app using the Cloud SDK?

I'm using "Google App Engine" from GCP to host a static website. I already created the website files (HTML, JS) and yaml using Visual Studio Code. I have the folder with those files stored locally in my local computer.
I downloaded the Cloud SDK Shell for Windows. I logged in to my account, and selected the project. According to videos and tutorials, I need to deploy the app using "gcloud app deploy".
However I got an error saying that an "app.yaml" file is required to deploy this directory...
I'm trying to follow this tutorial:
https://cloud.google.com/appengine/docs/standard/python/getting-started/hosting-a-static-website#before_you_begin
I'm also trying to follow the steps contained in this video:
https://www.youtube.com/watch?v=mlcO7nfQzSg
How do I specify the root folder where I have my "app.yaml" file?
Thanks in advance!!
I already tried with many commands and unfortunately none of them have worked
The particular case in which gcloud app deploy works without additional arguments is for single-service applications only and only if the command is executed in the directory in which the service's app.yaml configuration file exists (and has that exact name, can't use a different name).
For other cases deployables can/must be specified. From gcloud app deploy:
SYNOPSIS
gcloud app deploy [DEPLOYABLES …] [--bucket=BUCKET] [--image-url=IMAGE_URL] [--no-promote] [--no-stop-previous-version]
[--version=VERSION, -v VERSION] [GCLOUD_WIDE_FLAG …]
DESCRIPTION
This command is used to deploy both code and configuration to the App
Engine server. As an input it takes one or more DEPLOYABLES that
should be uploaded. A DEPLOYABLE can be a service's .yaml file or a
configuration's .yaml file (for more information about configuration
files specific to your App Engine environment, refer to
https://cloud.google.com/appengine/docs/standard/python/configuration-files
or
https://cloud.google.com/appengine/docs/flexible/python/configuration-files).
Note, for Java Standard apps, you must add the path to the
appengine-web.xml file inside the WEB-INF directory. gcloud app
deploy skips files specified in the .gcloudignore file (see gcloud
topic gcloudignore for more information).
So apart from running the command with no arguments in the directory in which your app.yaml exists is to specify the app.yaml (with a full or relative path if needed) as a deployable:
gcloud app deploy path/to/your/app.yaml
IMHO doing this is a good habit - specifying deployables is more reliable and is the only way to deploy apps with multiple services or using routing via a dispatch.yaml file.
gcloud app deploy will look at the current directory first for app.yaml. Generally you will change to the directory with app.yaml and your other files before deploying

Docker image fails to build on Google Container Registry

I have setup a trigger from Bitbucket to Google Container Registry.
I have a Dockerfile in the root, and am able to build the container fine from my local machine.
I get this error in Google Container Registry when the trigger runs (I did not modify the command that GCR wanted to run - it's the default). My project name has been replaced with "project":
FETCHSOURCE
Initialized empty Git repository in /workspace/.git/
From https://source.developers.google.com/p/project/r/bitbucket-project-gateway
* branch c65f16b3f52262a047c71e7140aecc4300265497 -> FETCH_HEAD
HEAD is now at c65f16b testing
BUILD
Already have image (with digest): gcr.io/cloud-builders/docker
invalid argument "gcr.io/project/bitbucket-project-gateway:" for t: invalid reference format
See 'docker build --help'.
ERROR
ERROR: build step "gcr.io/cloud-builders/docker#sha256:e576df764ae28d3c072019a235b6c8966df11eecb472c59b0963d783bb8a713b" failed: exit status 125
It looks like the image's tag is missing (after the ":").
Do you have a cloudbuild.yaml config file? If so do you use some substitutions variables (e.g. $REVISION_ID)? Maybe there is a misspelling there?
Cheers,
Philmod
For others who come along, when running into this same issue when pushing a Dockerfile with a Cloud Build YAML file - my mistakes:
Had ${SHORT_SHA} in one place and not the other (was on the Artifact push and not the build) [https://stackoverflow.com/a/44716934/18176030credit to Philmod for the tag not being right]
I was using the "grc.io" on during the build process and not the Artifact push (was using "us-east1-docker.pkg.dev").