Skip to content

Commit 9a68584

Browse files
committed
hadolint fixes/best practices added
Enable -o pipefail for RUN commands with pipes so any errors in the pipeline cause a failure. use wget -q to reduce log size for large file downloads. Run all apk with --no-cache so I don't need to remove /var/cache/apk/*. Quote variables in RUN shell scripts unless they need to be expanded. Don't use direct variable substitution in printf. Update comment for installing python packages using apk. Remove --use-feature=in-tree-build from local_pip pip command. This feature is the default with newer pips and is now an error if used.
1 parent 1ff866b commit 9a68584

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ Fixed:
7979
password_pbkdf2_default_rounds.
8080
- upgrade from jquery-3.5.1 to jquery-3.6.3. Update user.help.html
8181
to new version.
82+
- Dockerfile scanned with hadolint. Fixed multiple issues.
8283

8384
Features:
8485

scripts/Docker/Dockerfile

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# hadolint global ignore=DL3003
12
# build in root dir using:
23
#
34
# docker build -t roundup-app --rm -f scripts/Dockerfile .
@@ -31,12 +32,12 @@ ARG appdir
3132
WORKDIR $appdir
3233

3334
# Update to get security and other improvements;
34-
RUN apk --update-cache upgrade
35+
RUN apk --no-cache upgrade
3536

3637
# Add packages needed to compile mysql, pgsql and other python modules.
37-
# Can't use apk to add them as that installs a 3.9 python version.
38+
# Can't use apk to add python packages as it installs 3.9 python version.
3839
# g++ installs cc1plus needed by pip install
39-
RUN apk add \
40+
RUN apk --no-cache add \
4041
g++ \
4142
gcc \
4243
gpgme-dev \
@@ -54,7 +55,7 @@ ARG pythonversion
5455
RUN image_python_version=$(python -c 'import sys; print("%s.%s"%sys.version_info[0:2])'); \
5556
if [ "${pythonversion}" != "${image_python_version}" ]; then \
5657
printf "\n\n*****\npythonversion does not match.\n" ; \
57-
printf "Add:\n --build-arg=\"pythonversion=${image_python_version}\"\nto docker build\n******\n\n"; \
58+
printf "Add:\n --build-arg=\"pythonversion=%s\"\nto docker build\n******\n\n" "${image_python_version}"; \
5859
exit 1; \
5960
fi
6061

@@ -66,11 +67,12 @@ COPY scripts/Docker/sphinxdeps.txt .
6667
# suppress warning when running pip as root
6768
ENV PIP_ROOT_USER_ACTION=ignore
6869

70+
SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
6971
RUN set -xv && CWD=$PWD && \
7072
upgrades=$(python3 -m pip --no-cache --disable-pip-version-check \
7173
list --outdated | awk 'NR > 2 {print $1}'); \
7274
if [ -n "$upgrades" ]; then \
73-
echo Pip updating $upgrades; \
75+
echo "Pip updating $upgrades"; \
7476
python -m pip --no-cache --disable-pip-version-check \
7577
install -U $upgrades < /dev/null; \
7678
else \
@@ -80,8 +82,8 @@ RUN set -xv && CWD=$PWD && \
8082
VER=$(apk list -I 'xapian-core-dev' | \
8183
sed 's/^xapian-core-dev-\([0-9.]*\)-.*/\1/') && \
8284
cd /tmp && \
83-
wget https://oligarchy.co.uk/xapian/$VER/xapian-bindings-$VER.tar.xz && \
84-
tar -Jxvf xapian-bindings-$VER.tar.xz && \
85+
wget -q "https://oligarchy.co.uk/xapian/$VER/xapian-bindings-$VER.tar.xz" && \
86+
tar -Jxvf "xapian-bindings-$VER.tar.xz" && \
8587
cd xapian-bindings-$VER/ && \
8688
pip --no-cache-dir install sphinx && \
8789
sed -i -e '/PYTHON3_SO=/s/distutils\.//g' \
@@ -116,10 +118,12 @@ RUN set -xv && if [ "$source" = "local" ] || \
116118
else echo "invalid value for source: $source"; \
117119
echo "must be local or pypi"; exit 1; fi; \
118120
if [ "$source" = "local" ]; then cd install && ./setup.py install; fi; \
119-
if [ "$source" = "local_pip" ]; then cd install && pip install \
120-
--use-feature=in-tree-build . ; fi; \
121-
if [ "$source" = "pypi" ]; then pip install roundup; \
122-
cp -ril /usr/local/lib/python${pythonversion}/site-packages/usr/local/share/* \
121+
if [ "$source" = "local_pip" ]; then cd install && \
122+
pip -V && \
123+
pip install --no-cache-dir . ; \
124+
fi; \
125+
if [ "$source" = "pypi" ]; then pip install --no-cache-dir roundup; \
126+
cp -ril /usr/local/lib/"python${pythonversion}"/site-packages/usr/local/share/* \
123127
/usr/local/share; fi
124128

125129
# Allow user to add more modules during build
@@ -145,20 +149,20 @@ ENV PIP_ROOT_USER_ACTION=ignore
145149
# clean out any caches to save space
146150
# upgrade pip packages to get security and other updates
147151
# bundle with apk updates
148-
RUN apk --update-cache upgrade; \
149-
apk add \
152+
SHELL ["/bin/ash", "-eo", "pipefail", "-c"]
153+
RUN apk --no-cache upgrade; \
154+
apk --no-cache add \
150155
brotli-libs \
151156
gpgme \
152157
mariadb-connector-c \
153158
libpq \
154159
libstdc++ \
155160
libxapian \
156161
zstd-libs; \
157-
rm -f /var/cache/apk/*; \
158162
upgrades=$(python3 -m pip --no-cache --disable-pip-version-check \
159163
list --outdated | awk 'NR > 2 {print $1}'); \
160164
if [ -n "$upgrades" ]; then \
161-
echo Pip updating $upgrades; \
165+
echo "Pip updating $upgrades"; \
162166
python -m pip --no-cache --disable-pip-version-check \
163167
install -U $upgrades < /dev/null; \
164168
else \

0 commit comments

Comments
 (0)