comparison contrib/docker/pytype/recipe.sh @ 51307:87bfd1703597

contrib: add a set of scripts to run pytype in Docker Having a simple way to run pytype for developers can massively shorten development cycle. Using the same Docker image and scripts that we use on our CI guarantees that the result achieved locally will be very similar to (if not the same as) the output of our CI runners. Things to note: the Dockerfile needs to do a little dance around user permissions inside /home/ci-runner/ because: - on one hand, creating new files on the host (e.g. .pyi files inside .pytype/) should use host user's uid and gid - on the other hand, when we run the image as uid:gid of host user, it needs to be able to read/execute files inside the image that are owned by ci-runner Since local user's uid might be different from ci-runner's uid, we execute this very broad chmod command inside /home/ci-runner/, but then run the image as the host user's uid:gid. There might be a better way to do this.
author Anton Shestakov <av6@dwimlabs.net>
date Mon, 08 Jan 2024 13:35:02 +0100
parents
children
comparison
equal deleted inserted replaced
51306:46280260d010 51307:87bfd1703597
1 #!/usr/bin/env bash
2
3 # find repo-root without calling hg as this might be run with sudo
4 THIS="$(readlink -m "$0")"
5 HERE="$(dirname "$THIS")"
6 HG_ROOT="$(readlink -m "$HERE"/../../..)"
7 echo source mercurial repository: "$HG_ROOT"
8
9 # find actual user as this might be run with sudo
10 if [ -n "$SUDO_UID" ]; then
11 ACTUAL_UID="$SUDO_UID"
12 else
13 ACTUAL_UID="$(id -u)"
14 fi
15 if [ -n "$SUDO_GID" ]; then
16 ACTUAL_GID="$SUDO_GID"
17 else
18 ACTUAL_GID="$(id -g)"
19 fi
20 echo using user "$ACTUAL_UID:$ACTUAL_GID"
21 if groups | egrep -q '\<(docker|root)\>' ; then
22 env DOCKER_BUILDKIT=1 docker build --tag mercurial-pytype-checker "$HERE"
23 docker run --rm -it --user "$ACTUAL_UID:$ACTUAL_GID" -v "$HG_ROOT:/tmp/mercurial-ci" mercurial-pytype-checker
24 else
25 echo "user not in the docker group" >&2
26 echo "(consider running this with \`sudo\`)" >&2
27 exit 255
28 fi