Docker: User build context for precommit test

This commit is contained in:
Ole Schütt 2022-03-11 15:05:55 +01:00 committed by Ole Schütt
parent e861a83b17
commit 74473a6d04
6 changed files with 112 additions and 76 deletions

View file

@ -0,0 +1,23 @@
#
# This file was created by generate_dockerfiles.py.
# Usage: docker build -f ./Dockerfile.test_precommit ../../
#
FROM ubuntu:20.04
# Install dependencies.
WORKDIR /opt/cp2k-precommit
COPY ./tools/precommit/ /opt/cp2k-precommit/
RUN ./install_requirements.sh
# Install sources.
WORKDIR /opt/cp2k
COPY ./ ./
# Run precommit test.
RUN ./tools/docker/scripts/test_precommit.sh 2>&1 | tee report.log
# Output the report if the image is old and was therefore pulled from the build cache.
CMD cat $(find ./report.log -mmin +10) | sed '/^Summary:/ s/$/ (cached)/'
#EOF

View file

@ -66,6 +66,9 @@ def main() -> None:
with OutputFile(f"Dockerfile.test_manual", args.check) as f:
f.write(toolchain_full() + manual())
with OutputFile(f"Dockerfile.test_precommit", args.check) as f:
f.write(precommit())
for name in "aiida", "ase", "gromacs", "i-pi":
with OutputFile(f"Dockerfile.test_{name}", args.check) as f:
f.write(toolchain_full() + test_3rd_party(name))
@ -153,6 +156,28 @@ RUN ./test_manual.sh 2>&1 | tee report.log
)
# ======================================================================================
def precommit() -> str:
return (
fr"""
FROM ubuntu:20.04
# Install dependencies.
WORKDIR /opt/cp2k-precommit
COPY ./tools/precommit/ /opt/cp2k-precommit/
RUN ./install_requirements.sh
# Install sources.
WORKDIR /opt/cp2k
COPY ./ ./
# Run precommit test.
RUN ./tools/docker/scripts/test_precommit.sh 2>&1 | tee report.log
"""
+ print_cached_report()
)
# ======================================================================================
def test_3rd_party(name: str) -> str:
return (

View file

@ -0,0 +1,19 @@
#!/bin/bash
# author: Ole Schuett
echo -e "\n========== Starting Precommit Server =========="
cd ./tools/precommit/ || exit 1
export REVISION="unknown revision"
gunicorn --bind=:8080 --workers=1 --threads=8 --timeout=0 precommit_server:app &> /var/tmp/precommit_server.logs &
sleep 3
cat /var/tmp/precommit_server.logs
echo -e "\n========== Running Precommit Checks =========="
export CP2K_PRECOMMIT_SERVER="http://127.0.0.1:8080"
./precommit.py --no-cache --progressbar-wait=10
echo -e "\n"
exit 0 # Prevent CI from overwriting precommit.py's summary message.
#EOF

View file

@ -2,55 +2,13 @@ FROM ubuntu:20.04
# author: Ole Schuett
# Install clang-format, shellcheck, and other Ubuntu packages.
# https://github.com/koalaman/shellcheck
# https://clang.llvm.org/docs/ClangFormat.html
RUN export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true && \
apt-get update -qq && apt-get install -qq --no-install-recommends \
ca-certificates \
clang-format \
git \
less \
nano \
npm \
python3 \
python3-pip \
python3-wheel \
python3-setuptools \
shellcheck \
wget \
&& rm -rf /var/lib/apt/lists/*
# Install markdownlint-cli and dependencies.
# https://github.com/DavidAnson/markdownlint
# https://github.com/igorshubovych/markdownlint-cli
WORKDIR /opt/cp2k-precommit
COPY package.json package-lock.json ./
RUN npm install .
RUN ln -s /opt/cp2k-precommit/node_modules/markdownlint-cli/markdownlint.js /usr/bin/markdownlint
# Install black, flask, gunicorn, and dependencies.
# https://github.com/psf/black
COPY requirements.txt .
RUN pip3 install --quiet -r requirements.txt
# Install shfmt.
# https://github.com/mvdan/sh
RUN wget -q https://github.com/mvdan/sh/releases/download/v3.2.2/shfmt_v3.2.2_linux_amd64 && \
echo '3a32a69286a19491a81fcd854154f0d886c379ff28d99e32d5594490b8bbef4b shfmt_v3.2.2_linux_amd64' | sha256sum --check && \
chmod +x shfmt_v3.2.2_linux_amd64 && \
ln -s /opt/cp2k-precommit/shfmt_v3.2.2_linux_amd64 /usr/bin/shfmt
# Clone cp2k repository (needed for CI mode).
RUN git clone --quiet --recursive --single-branch -b master https://github.com/cp2k/cp2k.git /workspace/cp2k
# Install Flask app.
COPY precommit_server.py .
COPY . /opt/cp2k-precommit/
RUN ./install_requirements.sh
ARG REVISION
ENV REVISION=${REVISION}
COPY entrypoint.sh .
CMD ["./entrypoint.sh"]
CMD ["gunicorn", "--bind=:8080", "--workers=1", "--threads=8", "--timeout=0", "precommit_server:app"]
#EOF

View file

@ -1,31 +0,0 @@
#!/bin/bash -e
# author: Ole Schuett
trap "exit" INT
if [ -z "${GIT_REF}" ]; then
# Server mode.
gunicorn --bind=:8080 --workers=1 --threads=8 --timeout=0 precommit_server:app &
wait # Can be interrupted with ctrl-C.
else
# CI mode.
echo -e "\n========== Fetching Git Commit =========="
cd /workspace/cp2k
git fetch --quiet origin "${GIT_BRANCH}"
git reset --quiet --hard "${GIT_REF}"
git submodule update --init --recursive
git --no-pager log -1 --pretty='%nCommitSHA: %H%nCommitTime: %ci%nCommitAuthor: %an%nCommitSubject: %s%n'
echo -e "\n========== Starting Precommit Server =========="
cd ./tools/precommit/
gunicorn --bind=:8080 --workers=1 --threads=8 --timeout=0 precommit_server:app &> /workspace/precommit_server.logs &
sleep 3
cat /workspace/precommit_server.logs
echo -e "\n========== Running Precommit Checks =========="
export CP2K_PRECOMMIT_SERVER="http://127.0.0.1:8080"
./precommit.py --no-cache --progressbar-wait=10 || true
fi
#EOF

View file

@ -0,0 +1,42 @@
#!/bin/bash -e
# author: Ole Schuett
# Install clang-format, shellcheck, and other Ubuntu packages.
# https://github.com/koalaman/shellcheck
# https://clang.llvm.org/docs/ClangFormat.html
export DEBIAN_FRONTEND=noninteractive DEBCONF_NONINTERACTIVE_SEEN=true
apt-get update -qq
apt-get install -qq --no-install-recommends \
ca-certificates \
clang-format \
git \
less \
nano \
npm \
python3 \
python3-pip \
python3-wheel \
python3-setuptools \
shellcheck \
wget
rm -rf /var/lib/apt/lists/*
# Install markdownlint-cli and dependencies.
# https://github.com/DavidAnson/markdownlint
# https://github.com/igorshubovych/markdownlint-cli
npm install .
ln -s /opt/cp2k-precommit/node_modules/markdownlint-cli/markdownlint.js /usr/bin/markdownlint
# Install black, flask, gunicorn, and dependencies.
# https://github.com/psf/black
pip3 install --quiet -r requirements.txt
# Install shfmt.
# https://github.com/mvdan/sh
wget -q https://github.com/mvdan/sh/releases/download/v3.2.2/shfmt_v3.2.2_linux_amd64
echo '3a32a69286a19491a81fcd854154f0d886c379ff28d99e32d5594490b8bbef4b shfmt_v3.2.2_linux_amd64' | sha256sum --check
chmod +x shfmt_v3.2.2_linux_amd64
ln -s /opt/cp2k-precommit/shfmt_v3.2.2_linux_amd64 /usr/bin/shfmt
#EOF