Skip to content

Commit 71cce66

Browse files
committedMay 17, 2019
separate ENTRYPOINT and CMD operations in Dockerfiles fixes #29
1 parent 8eabe97 commit 71cce66

7 files changed

+38
-18
lines changed
 

‎Dockerfile.sonarscanner-3.0.3-alpine

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ COPY sonar-runner.properties /usr/lib/sonar-scanner/conf/sonar-scanner.propertie
2323
# ensure Sonar uses the provided Java for musl instead of a borked glibc one
2424
RUN sed -i 's/use_embedded_jre=true/use_embedded_jre=false/g' /usr/lib/sonar-scanner/bin/sonar-scanner
2525

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

‎Dockerfile.sonarscanner-3.0.3-full

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ ENV SONAR_RUNNER_HOME=/usr/lib/sonar-scanner
2525

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

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

‎Dockerfile.sonarscanner-3.2.0-alpine

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ COPY sonar-runner.properties ./sonar-scanner/conf/sonar-scanner.properties
2323
# ensure Sonar uses the provided Java for musl instead of a borked glibc one
2424
RUN sed -i 's/use_embedded_jre=true/use_embedded_jre=false/g' /usr/lib/sonar-scanner/bin/sonar-scanner
2525

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

‎Dockerfile.sonarscanner-3.2.0-full

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ ENV SONAR_RUNNER_HOME=/usr/lib/sonar-scanner
2525

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

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

‎Dockerfile.sonarscanner-3.3.0-alpine

+5-3
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ COPY sonar-runner.properties /usr/lib/sonar-scanner/conf/sonar-scanner.propertie
2323
# ensure Sonar uses the provided Java for musl instead of a borked glibc one
2424
RUN sed -i 's/use_embedded_jre=true/use_embedded_jre=false/g' /usr/lib/sonar-scanner/bin/sonar-scanner
2525

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

‎Dockerfile.sonarscanner-3.3.0-full

+5-3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ ENV SONAR_RUNNER_HOME=/usr/lib/sonar-scanner
2525

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

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

‎README.md

+8
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ docker run -ti -v $(pwd):/usr/src newtmitch/sonar-scanner
4646

4747
# Change Log
4848

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

111+
If you need to use a different directory as the project base directory, you can
112+
pass that in as part of the docker run command to override that default:
113+
114+
docker run -ti -v $(pwd):/usr/src --link sonarqube newtmitch/sonar-scanner -Dsonar.projectBaseDir=/my/project/base/dir
115+
108116
The supplied sonar-runner.properties file points to http://192.168.99.100 as the
109117
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:
110118

0 commit comments

Comments
 (0)