Skip to content

Commit

Permalink
separate ENTRYPOINT and CMD operations in Dockerfiles fixes #29
Browse files Browse the repository at this point in the history
  • Loading branch information
newtmitch committed May 17, 2019
1 parent 8eabe97 commit 71cce66
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 18 deletions.
8 changes: 5 additions & 3 deletions Dockerfile.sonarscanner-3.0.3-alpine
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ COPY sonar-runner.properties /usr/lib/sonar-scanner/conf/sonar-scanner.propertie
# ensure Sonar uses the provided Java for musl instead of a borked glibc one
RUN sed -i 's/use_embedded_jre=true/use_embedded_jre=false/g' /usr/lib/sonar-scanner/bin/sonar-scanner

# Use bash if you want to run the environment from inside the shell, otherwise use the command that actually runs the underlying stuff
#CMD /bin/bash
CMD sonar-scanner -Dsonar.projectBaseDir=/usr/src
# Separating ENTRYPOINT and CMD operations allows for core execution variables to
# be easily overridden by passing them in as part of the `docker run` command.
# This allows the default /usr/src base dir to be overridden by users as-needed.
ENTRYPOINT ["sonar-scanner"]
CMD ["-Dsonar.projectBaseDir=/usr/src"]

This comment has been minimized.

Copy link
@ngraf

ngraf May 23, 2019

👎

Changing behavior of existing docker image version (3.0.3-alpine). Not cool. This breaks my pipelines.

This comment has been minimized.

Copy link
@arekzelechowski

arekzelechowski Jun 3, 2019

Same here. I have lost a lot of time today because of that.

This comment has been minimized.

Copy link
@newtmitch

newtmitch Nov 25, 2020

Author Owner

😞 Sorry about that. See my note towards the bottom of this commit.

8 changes: 5 additions & 3 deletions Dockerfile.sonarscanner-3.0.3-full
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ ENV SONAR_RUNNER_HOME=/usr/lib/sonar-scanner

COPY sonar-runner.properties /usr/lib/sonar-scanner/conf/sonar-scanner.properties

# Use bash if you want to run the environment from inside the shell, otherwise use the command that actually runs the underlying stuff
#CMD /bin/bash
CMD sonar-scanner -Dsonar.projectBaseDir=/usr/src
# Separating ENTRYPOINT and CMD operations allows for core execution variables to
# be easily overridden by passing them in as part of the `docker run` command.
# This allows the default /usr/src base dir to be overridden by users as-needed.
ENTRYPOINT ["sonar-scanner"]
CMD ["-Dsonar.projectBaseDir=/usr/src"]
8 changes: 5 additions & 3 deletions Dockerfile.sonarscanner-3.2.0-alpine
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ COPY sonar-runner.properties ./sonar-scanner/conf/sonar-scanner.properties
# ensure Sonar uses the provided Java for musl instead of a borked glibc one
RUN sed -i 's/use_embedded_jre=true/use_embedded_jre=false/g' /usr/lib/sonar-scanner/bin/sonar-scanner

# Use bash if you want to run the environment from inside the shell, otherwise use the command that actually runs the underlying stuff
#CMD /bin/bash
CMD sonar-scanner -Dsonar.projectBaseDir=/usr/src
# Separating ENTRYPOINT and CMD operations allows for core execution variables to
# be easily overridden by passing them in as part of the `docker run` command.
# This allows the default /usr/src base dir to be overridden by users as-needed.
ENTRYPOINT ["sonar-scanner"]
CMD ["-Dsonar.projectBaseDir=/usr/src"]
8 changes: 5 additions & 3 deletions Dockerfile.sonarscanner-3.2.0-full
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ ENV SONAR_RUNNER_HOME=/usr/lib/sonar-scanner

COPY sonar-runner.properties /usr/lib/sonar-scanner/conf/sonar-scanner.properties

# Use bash if you want to run the environment from inside the shell, otherwise use the command that actually runs the underlying stuff
#CMD /bin/bash
CMD sonar-scanner -Dsonar.projectBaseDir=/usr/src
# Separating ENTRYPOINT and CMD operations allows for core execution variables to
# be easily overridden by passing them in as part of the `docker run` command.
# This allows the default /usr/src base dir to be overridden by users as-needed.
ENTRYPOINT ["sonar-scanner"]
CMD ["-Dsonar.projectBaseDir=/usr/src"]
8 changes: 5 additions & 3 deletions Dockerfile.sonarscanner-3.3.0-alpine
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ COPY sonar-runner.properties /usr/lib/sonar-scanner/conf/sonar-scanner.propertie
# ensure Sonar uses the provided Java for musl instead of a borked glibc one
RUN sed -i 's/use_embedded_jre=true/use_embedded_jre=false/g' /usr/lib/sonar-scanner/bin/sonar-scanner

# Use bash if you want to run the environment from inside the shell, otherwise use the command that actually runs the underlying stuff
#CMD /bin/bash
CMD sonar-scanner -Dsonar.projectBaseDir=/usr/src
# Separating ENTRYPOINT and CMD operations allows for core execution variables to
# be easily overridden by passing them in as part of the `docker run` command.
# This allows the default /usr/src base dir to be overridden by users as-needed.
ENTRYPOINT ["sonar-scanner"]
CMD ["-Dsonar.projectBaseDir=/usr/src"]
8 changes: 5 additions & 3 deletions Dockerfile.sonarscanner-3.3.0-full
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ ENV SONAR_RUNNER_HOME=/usr/lib/sonar-scanner

COPY sonar-runner.properties /usr/lib/sonar-scanner/conf/sonar-scanner.properties

# Use bash if you want to run the environment from inside the shell, otherwise use the command that actually runs the underlying stuff
#CMD /bin/bash
CMD sonar-scanner -Dsonar.projectBaseDir=/usr/src
# Separating ENTRYPOINT and CMD operations allows for core execution variables to
# be easily overridden by passing them in as part of the `docker run` command.
# This allows the default /usr/src base dir to be overridden by users as-needed.
ENTRYPOINT ["sonar-scanner"]
CMD ["-Dsonar.projectBaseDir=/usr/src"]
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ docker run -ti -v $(pwd):/usr/src newtmitch/sonar-scanner

# Change Log

### 2019-05-16
* Separated Dockerfile command into ENTRYPOINT and CMD operations to better follow Dockerfile best practices (see https://docs.docker.com/develop/develop-images/dockerfile_best-practices/#entrypoint). (issue #29)

### 2019-05-13
* Commented out `sonar.exclusions` from the `sonar-runner.properties` file included in the image by default (issue #25)
* Removed the use of the `/root` directory as part of the image build. Using `/usr/lib`, `/usr/bin`, and `/usr/src` now (issue #26)
Expand Down Expand Up @@ -105,6 +108,11 @@ Replace "$(pwd)" with the absolute path of the top-level source directly you're
interested in if you're not running the docker image from the top level project
directory. It will scan everything under that directory when it starts up.

If you need to use a different directory as the project base directory, you can
pass that in as part of the docker run command to override that default:

docker run -ti -v $(pwd):/usr/src --link sonarqube newtmitch/sonar-scanner -Dsonar.projectBaseDir=/my/project/base/dir

The supplied sonar-runner.properties file points to http://192.168.99.100 as the
Qube server. If you need to change that or any other of the variables that Scanner needs to run, you can pass them in with the command itself to override them:

Expand Down

7 comments on commit 71cce66

@jupitercl
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you make changes please do not change the other versions, now I have an error and I will have to use another image sonar-scanner

@Kemquiros
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I totally agree with @jupytercl.
Your new change on older versions forces us to modify our pipelines.

@butchyyyy
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, making breaking changes into existing images... not cool 👎

@ellowrath
Copy link

@ellowrath ellowrath commented on 71cce66 May 20, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added:
args "--entrypoint=\'\'"
to my jenkinsfile to get it to work.
Got it from :
https://issues.jenkins-ci.org/browse/JENKINS-51307?jql=text%20~%20%22pipeline%20scm%22

Hope this helps.

@Appelsappel
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, since the update we're getting:
ERROR: Unrecognized option: -c

while we're using:
syntax-sonar:
stage: syntax
image: newtmitch/sonar-scanner
script:
- sonar-scanner -Dsonar.host.url=https://oursite.nl/sonarqube -Dsonar.login=xxx -Dsonar.sources=. -Dsonar.exclusions=*/node_modules/** -Dsonar.projectName=ourproject -Dsonar.projectBaseDir=xxx -Dsonar.projectKey=pro:ject

Could you explain what we need to change to solve the error?

@butchyyyy
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added:
args "--entrypoint=\'\'"
to my jenkinsfile to get it to work.
Got it from :
https://issues.jenkins-ci.org/browse/JENKINS-51307?jql=text%20~%20%22pipeline%20scm%22

Hope this helps.

That's what we did to fix our Jenkins builds. We also used mappings to the /root/src directory which had to be changed to the new default /usr/src.

@newtmitch
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing some cleanup and maintenance of the repo. Sorry about this breaking change, I completely didn't think about this hard enough before I did it, nor understood the impact to the community making use of it. My sincere apologies. I realize also this wasn't a good change to make, and instead I should have responded to the issue that was reporting the problem that prompted me to make this change by suggesting a different approach.

I'm getting ready to add new Dockerfiles for Sonar Scanner versions 4.1 - 4.5 that will move back to the single CMD-based approach rather than the ENTRYPOINT approach I introduced with this change. I'll be leaving the existing images alone given the changes everyone had to make to accommodate this change I made. I'll also be adding a version 4.0 dockerfile alongside the existing 4.0 dockerfile with the CMD approach and labeling it specifically for CI, as suggested in #30.

Please sign in to comment.