diff options
Diffstat (limited to 'devel_tools')
| -rw-r--r-- | devel_tools/ci_container/Dockerfile | 37 | ||||
| -rw-r--r-- | devel_tools/ci_container/build.sh | 3 | ||||
| -rw-r--r-- | devel_tools/ci_container/entry.sh | 55 | ||||
| -rw-r--r-- | devel_tools/ci_container/run.sh | 7 |
4 files changed, 102 insertions, 0 deletions
diff --git a/devel_tools/ci_container/Dockerfile b/devel_tools/ci_container/Dockerfile new file mode 100644 index 0000000..3cca866 --- /dev/null +++ b/devel_tools/ci_container/Dockerfile @@ -0,0 +1,37 @@ +FROM ubuntu:22.04 + +RUN <<EOF + apt-get update + apt-get install -y g++ python3 pip git clang-format + python3 -m pip install pre-commit +EOF + +RUN <<EOF + apt-get install -y wget cmake libpcre3-dev + + cd /tmp + wget https://github.com/danmar/cppcheck/archive/2.14.0.tar.gz + tar xvf 2.14.0.tar.gz + cd cppcheck-2.14.0 + + mkdir build + cd build + cmake \ + -DCMAKE_INSTALL_PREFIX=/usr \ + -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_GUI=Off \ + -DUSE_MATCHCOMPILER=On \ + -DHAVE_RULES=On \ + .. + make install/strip + + rm -r /tmp/2.14.0.tar.gz /tmp/cppcheck-2.14.0 + apt-get remove -y wget cmake libpcre3-dev + apt-get autoremove -y + apt-get clean +EOF + +WORKDIR /diff-dd + +COPY ./devel_tools/ci_container/entry.sh /entry.sh +ENTRYPOINT ["/entry.sh"] diff --git a/devel_tools/ci_container/build.sh b/devel_tools/ci_container/build.sh new file mode 100644 index 0000000..ab4d124 --- /dev/null +++ b/devel_tools/ci_container/build.sh @@ -0,0 +1,3 @@ +#!/bin/sh + +docker buildx build -t ghcr.io/jansucan/diff-dd-ci:latest -f devel_tools/ci_container/Dockerfile . diff --git a/devel_tools/ci_container/entry.sh b/devel_tools/ci_container/entry.sh new file mode 100644 index 0000000..7779665 --- /dev/null +++ b/devel_tools/ci_container/entry.sh @@ -0,0 +1,55 @@ +#!/bin/sh -ex + +# This script is used for running commands inside the container as a user with +# specified UID and GID so the files created from inside the container have the +# same owner and group as the files created outside of the container. This makes +# it easy to manipulate the files as the user outside the container. + +if [ $# -lt 3 ]; then + echo "Usage: $0 UID GID CMD [ARGS...] " >&2 + exit 1 +fi + +UID=$1 +GID=$2 +USER_NAME=new-user +GROUP_NAME=new-group +shift 2 + +if ! getent passwd $UID >/dev/null; then + # The UID does not exist, create it + useradd -m -u $UID $USER_NAME +else + USER_NAME=$(id -n -u $UID) +fi + +if ! getent group $GID >/dev/null; then + # The GID does not exist, create it + groupadd -g $GID $GROUP_NAME +else + GROUP_NAME=$(getent group $GID | cut -d: -f1) +fi + +# Make sure the group is the user's primary group +usermod -g $GROUP_NAME $USER_NAME + +# Check that the user has expected UID and GID +ACTUAL_UID=$(su -c 'id -u' $USER_NAME) +if [ $ACTUAL_UID -ne $UID ]; then + echo "Error: Actual UID $ACTUAL_UID != $UID" + exit 1 +fi + +ACTUAL_GID=$(su -c 'id -g' $USER_NAME) +if [ $ACTUAL_GID -ne $GID ]; then + echo "Error: Actual GID $ACTUAL_GID != $GID" + exit 1 +fi + +if [ ! -e /.cache ]; then + # Needed for running pre-commit + mkdir /.cache + chown $USER_NAME: /.cache +fi + +su -c "$*" $USER_NAME diff --git a/devel_tools/ci_container/run.sh b/devel_tools/ci_container/run.sh new file mode 100644 index 0000000..ea01ee1 --- /dev/null +++ b/devel_tools/ci_container/run.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +USER_UID=$(id -u) +USER_GID=$(id -g) + +# Intended to run from root directory of the project +docker run -v .:/diff-dd ghcr.io/jansucan/diff-dd-ci $USER_UID $USER_GID "$@" |
