Skip to content

Commit 2ffa895

Browse files
Merge pull request #430 from jstourac/codeQuality
Add hadolint checks for Dockerfiles
2 parents 682f653 + 55177d3 commit 2ffa895

File tree

11 files changed

+65
-18
lines changed

11 files changed

+65
-18
lines changed

.github/workflows/code-quality.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,13 @@ jobs:
4040
echo "There were errors in some of the checked files. Please run `json_verify` on such files and fix issues there."
4141
fi
4242
exit "${ret_code}"
43+
44+
- name: Validate Dockerfiles
45+
id: validate-dockerfiles
46+
run: |
47+
type hadolint || sudo apt-get -y install wget \
48+
&& wget --output-document=hadolint https://github.com/hadolint/hadolint/releases/download/v2.12.0/hadolint-Linux-x86_64 \
49+
&& chmod a+x hadolint
50+
echo "Starting Hadolint"
51+
find . -name "Dockerfile" | xargs ./hadolint --config ./ci/hadolint-config.yaml
52+
echo "Hadolint done"

base/anaconda-python-3.8/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ ENV BASH_ENV="source /opt/anaconda3/bin/activate ${APP_ROOT}" \
7979
USER 1001
8080

8181
# Set the default CMD to print the usage of the language image.
82-
CMD $STI_SCRIPTS_PATH/usage
82+
CMD ["$STI_SCRIPTS_PATH/usage"]
8383

8484

8585
FROM s2i-python-anaconda-38-base

base/c9s-python-3.9/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LABEL name="odh-notebook-base-centos-stream9-python-3.9" \
1313
WORKDIR /opt/app-root/bin
1414

1515
# Install micropipenv to deploy packages from Pipfile.lock
16-
RUN pip install -U "micropipenv[toml]"
16+
RUN pip install --no-cache-dir -U "micropipenv[toml]"
1717

1818
# Install Python dependencies from Pipfile.lock file
1919
COPY Pipfile.lock ./
@@ -22,7 +22,7 @@ COPY Pipfile.lock ./
2222
USER root
2323

2424
# Install usefull OS packages
25-
RUN dnf install -y mesa-libGL
25+
RUN dnf install -y mesa-libGL && dnf clean all && rm -rf /var/cache/yum
2626

2727
# Other apps and tools installed as default user
2828
USER 1001

base/ubi8-python-3.8/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LABEL name="odh-notebook-base-ubi8-python-3.8" \
1313
WORKDIR /opt/app-root/bin
1414

1515
# Install micropipenv to deploy packages from Pipfile.lock
16-
RUN pip install -U "micropipenv[toml]"
16+
RUN pip install --no-cache-dir -U "micropipenv[toml]"
1717

1818
# Install Python dependencies from Pipfile.lock file
1919
COPY Pipfile.lock ./

base/ubi9-python-3.9/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ LABEL name="odh-notebook-base-ubi9-python-3.9" \
1313
WORKDIR /opt/app-root/bin
1414

1515
# Install micropipenv to deploy packages from Pipfile.lock
16-
RUN pip install -U "micropipenv[toml]"
16+
RUN pip install --no-cache-dir -U "micropipenv[toml]"
1717

1818
# Install Python dependencies from Pipfile.lock file
1919
COPY Pipfile.lock ./
@@ -24,7 +24,7 @@ RUN echo "Installing softwares and packages" && micropipenv install && rm -f ./P
2424
USER root
2525

2626
# Install usefull OS packages
27-
RUN dnf install -y mesa-libGL
27+
RUN dnf install -y mesa-libGL && dnf clean all && rm -rf /var/cache/yum
2828

2929
# Other apps and tools installed as default user
3030
USER 1001

ci/hadolint-config.yaml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
---
2+
3+
# Reference https://github.com/hadolint/hadolint
4+
# hadolint --config ./ci/hadolint-config.yaml <Dockerfile>
5+
6+
# We should revisit this ignore list and reduce it regularly
7+
8+
ignored:
9+
# DL3006 warning: Always tag the version of an image explicitly
10+
- DL3006
11+
# DL3033 warning: Specify version with `yum install -y <package>-<version>`.
12+
- DL3033
13+
# DL3045 warning: `COPY` to a relative destination without `WORKDIR` set.
14+
- DL3045
15+
# DL3041 warning: Specify version with `dnf install -y <package>-<version>`.
16+
- DL3041
17+
# DL3059 info: Multiple consecutive `RUN` instructions. Consider consolidation.
18+
- DL3059
19+
# DL3013 warning: Pin versions in pip. Instead of `pip install <package>` use
20+
# `pip install <package>==<version>` or `pip install --requirement <requirements file>`
21+
- DL3013
22+
# DL4006 warning: Set the SHELL option -o pipefail before RUN with a pipe in it.
23+
# If you are using /bin/sh in an alpine image or if your shell is symlinked to busybox
24+
# then consider explicitly setting your SHELL to /bin/ash, or disable this check
25+
- DL4006
26+
# DL3007 warning: Using latest is prone to errors if the image will ever update.
27+
# Pin the version explicitly to a release tag
28+
- DL3007
29+
# SC3060 warning: In POSIX sh, string replacement is undefined.
30+
- SC3060
31+
# SC2086 info: Double quote to prevent globbing and word splitting.
32+
- SC2086
33+
# SC2046 warning: Quote this to prevent word splitting.
34+
- SC2046
35+
# SC2140 warning: Word is of the form "A"B"C" (B indicated). Did you mean "ABC" or "A\"B\"C"?
36+
- SC2140

codeserver/c9s-python-3.9/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,4 @@ WORKDIR /opt/app-root/src
8787

8888
USER 1001
8989

90-
CMD /opt/app-root/bin/run-code-server.sh
90+
CMD ["/opt/app-root/bin/run-code-server.sh"]

codeserver/ubi9-python-3.9/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ RUN echo "Installing softwares and packages" && \
2929
fix-permissions /opt/app-root -P
3030

3131
# Install usefull OS packages
32-
RUN dnf install -y jq git-lfs libsndfile
32+
RUN dnf install -y jq git-lfs libsndfile && dnf clean all && rm -rf /var/cache/yum
3333

3434
# Install code-server
3535
RUN yum install -y "https://github.com/coder/code-server/releases/download/${CODESERVER_VERSION}/code-server-${CODESERVER_VERSION/v/}-amd64.rpm" && \
@@ -105,4 +105,4 @@ WORKDIR /opt/app-root/src
105105

106106
USER 1001
107107

108-
CMD /opt/app-root/bin/run-code-server.sh
108+
CMD ["/opt/app-root/bin/run-code-server.sh"]

jupyter/datascience/ubi8-python-3.8/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ COPY utils ./utils/
2828
USER root
2929

3030
# Install usefull OS packages
31-
RUN dnf install -y jq unixODBC git-lfs libsndfile
31+
RUN dnf install -y jq unixODBC git-lfs libsndfile && dnf clean all && rm -rf /var/cache/yum
3232

3333
# Disable announcement plugin of jupyterlab
3434
RUN jupyter labextension disable "@jupyterlab/apputils-extension:announcements"
3535

3636
# Install MongoDB Client, We need a special repo for MongoDB as they do their own distribution
3737
COPY mongodb-org-6.0.repo-x86_64 /etc/yum.repos.d/mongodb-org-6.0.repo
3838

39-
RUN dnf install -y mongocli
39+
RUN dnf install -y mongocli && dnf clean all && rm -rf /var/cache/yum
4040

4141
# Install MSSQL Client, We need a special repo for MSSQL as they do their own distribution
4242
COPY mssql-2022.repo-x86_64 /etc/yum.repos.d/mssql-2022.repo
4343

44-
RUN ACCEPT_EULA=Y dnf install -y mssql-tools18 unixODBC-devel
44+
RUN ACCEPT_EULA=Y dnf install -y mssql-tools18 unixODBC-devel && dnf clean all && rm -rf /var/cache/yum
4545

4646
ENV PATH="$PATH:/opt/mssql-tools18/bin"
4747

jupyter/datascience/ubi9-python-3.9/Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,20 +28,20 @@ COPY utils ./utils/
2828
USER root
2929

3030
# Install usefull OS packages
31-
RUN dnf install -y jq unixODBC postgresql git-lfs libsndfile
31+
RUN dnf install -y jq unixODBC postgresql git-lfs libsndfile && dnf clean all && rm -rf /var/cache/yum
3232

3333
# Disable announcement plugin of jupyterlab
3434
RUN jupyter labextension disable "@jupyterlab/apputils-extension:announcements"
3535

3636
# Install MongoDB Client, We need a special repo for MongoDB as they do their own distribution
3737
COPY mongodb-org-6.0.repo-x86_64 /etc/yum.repos.d/mongodb-org-6.0.repo
3838

39-
RUN dnf install -y mongocli
39+
RUN dnf install -y mongocli && dnf clean all && rm -rf /var/cache/yum
4040

4141
# Install MSSQL Client, We need a special repo for MSSQL as they do their own distribution
4242
COPY mssql-2022.repo-x86_64 /etc/yum.repos.d/mssql-2022.repo
4343

44-
RUN ACCEPT_EULA=Y dnf install -y mssql-tools18 unixODBC-devel
44+
RUN ACCEPT_EULA=Y dnf install -y mssql-tools18 unixODBC-devel && dnf clean all && rm -rf /var/cache/yum
4545

4646
ENV PATH="$PATH:/opt/mssql-tools18/bin"
4747

0 commit comments

Comments
 (0)