Skip to content

Commit

Permalink
Some suggestions (#3) from sanderegg
Browse files Browse the repository at this point in the history
* naming

* consistency

* shellcheck
  • Loading branch information
sanderegg authored Apr 22, 2021
1 parent 8d4838b commit 46fb131
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci-testing-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ jobs:
${{ runner.os }}-
- name: install
run: ./ci/github/unit-testing/dynamic-sidecar.bash install
- name: codestyle-ci
- name: codestyle
run: ./ci/github/unit-testing/dynamic-sidecar.bash codestyle
- name: test
run: ./ci/github/unit-testing/dynamic-sidecar.bash test
Expand Down
11 changes: 4 additions & 7 deletions scripts/act.bash
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,11 @@ ROOT_PROJECT_DIR=$1
# name of the job, usually defined in the .github/workflows/ci-testing-deploy.yaml
JOB_TO_RUN=$2


DOCKER_IMAGE_NAME=dind-act-runner
ACT_RUNNER=ubuntu-20.04=catthehacker/ubuntu:act-20.04
ACT_VERSION_TAG=v0.2.20 # from https://github.com/nektos/act/releases


docker build -t $DOCKER_IMAGE_NAME -<<EOF
docker build -t $DOCKER_IMAGE_NAME - <<EOF
FROM docker:dind
RUN apk add curl bash
Expand All @@ -27,10 +25,9 @@ WORKDIR /project
CMD /bin/sh -c "act -v -P $ACT_RUNNER -j $JOB_TO_RUN"
EOF


echo "$(pwd)/${ROOT_PROJECT_DIR}"
docker run --rm -it \
-v /var/run/docker.sock:/var/run/docker.sock \
-v $(pwd)/${ROOT_PROJECT_DIR}:/project \
-v $(pwd)/ci-logs:/logs \
$DOCKER_IMAGE_NAME
-v "$(pwd)"/"${ROOT_PROJECT_DIR}":/project \
-v "$(pwd)"/ci-logs:/logs \
$DOCKER_IMAGE_NAME
24 changes: 11 additions & 13 deletions scripts/codestyle.bash
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,31 @@ IFS=$'\n\t'
SRC_DIRECTORY_NAME=${2}
BASE_PATH_DIR=${3-MISSING_DIR}


# used for development (fails on pylint and mypy)
development(){
development() {
echo "enforcing codestyle to soruce_directory=$SRC_DIRECTORY_NAME"
echo "isort"
isort setup.py src/$SRC_DIRECTORY_NAME tests
isort setup.py src/"$SRC_DIRECTORY_NAME" tests
echo "black"
black src/$SRC_DIRECTORY_NAME tests/
black src/"$SRC_DIRECTORY_NAME" tests/
echo "pylint"
pylint --rcfile=../../.pylintrc src/$SRC_DIRECTORY_NAME tests/
pylint --rcfile=../../.pylintrc src/"$SRC_DIRECTORY_NAME" tests/
echo "mypy"
mypy --ignore-missing-imports --config-file ../../mypy.ini src/$SRC_DIRECTORY_NAME tests/
mypy --ignore-missing-imports --config-file ../../mypy.ini src/"$SRC_DIRECTORY_NAME" tests/
}


# invoked by ci as test (also fails on isort and black)
ci(){
ci() {
echo "checking codestyle in service=$BASE_PATH_DIR with soruce_directory=$SRC_DIRECTORY_NAME"
echo "isort"
isort --check setup.py $BASE_PATH_DIR/src/$SRC_DIRECTORY_NAME $BASE_PATH_DIR/tests
isort --check setup.py "$BASE_PATH_DIR"/src/"$SRC_DIRECTORY_NAME" "$BASE_PATH_DIR"/tests
echo "black"
black --check $BASE_PATH_DIR/src/$SRC_DIRECTORY_NAME $BASE_PATH_DIR/tests
black --check "$BASE_PATH_DIR"/src/"$SRC_DIRECTORY_NAME" "$BASE_PATH_DIR"/tests
echo "pylint"
pylint --rcfile=.pylintrc $BASE_PATH_DIR/src/$SRC_DIRECTORY_NAME $BASE_PATH_DIR/tests
pylint --rcfile=.pylintrc "$BASE_PATH_DIR"/src/"$SRC_DIRECTORY_NAME" "$BASE_PATH_DIR"/tests
echo "mypy"
mypy --config-file mypy.ini --ignore-missing-imports $BASE_PATH_DIR/src/$SRC_DIRECTORY_NAME $BASE_PATH_DIR/tests
mypy --config-file mypy.ini --ignore-missing-imports "$BASE_PATH_DIR"/src/"$SRC_DIRECTORY_NAME" "$BASE_PATH_DIR"/tests
}

# Allows to call a function based on arguments passed to the script
$*
"$@"
34 changes: 17 additions & 17 deletions services/dynamic-sidecar/docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@ echo "$INFO" "User : $(id scu)"
echo "$INFO" "python : $(command -v python)"
echo "$INFO" "pip : $(command -v pip)"

USERNAME=scu
GROUPNAME=scu

#
# DEVELOPMENT MODE
# - expects docker run ... -v $(pwd):$SC_DEVEL_MOUNT
# - mounts source folders
# - deduces host's uid/gip and assigns to user within docker
#
if [ "${SC_BUILD_TARGET}" = "development" ]; then
echo "$INFO" "development mode detected..."
# NOTE: expects docker run ... -v $(pwd):$DEVEL_MOUNT
Expand Down Expand Up @@ -71,23 +74,20 @@ fi

# Appends docker group if socket is mounted
DOCKER_MOUNT=/var/run/docker.sock
if stat $DOCKER_MOUNT > /dev/null 2>&1
then
echo "$INFO detected docker socket is mounted, adding user to group..."
GROUPID=$(stat --format=%g $DOCKER_MOUNT)
GROUPNAME=scdocker
if stat $DOCKER_MOUNT >/dev/null 2>&1; then
echo "$INFO detected docker socket is mounted, adding user to group..."
GROUPID=$(stat --format=%g $DOCKER_MOUNT)
GROUPNAME=scdocker

if ! addgroup --gid "$GROUPID" $GROUPNAME > /dev/null 2>&1
then
echo "$WARNING docker group with $GROUPID already exists, getting group name..."
# if group already exists in container, then reuse name
GROUPNAME=$(getent group "${GROUPID}" | cut --delimiter=: --fields=1)
echo "$WARNING docker group with $GROUPID has name $GROUPNAME"
fi
adduser "$SC_USER_NAME" "$GROUPNAME"
if ! addgroup --gid "$GROUPID" $GROUPNAME >/dev/null 2>&1; then
echo "$WARNING docker group with $GROUPID already exists, getting group name..."
# if group already exists in container, then reuse name
GROUPNAME=$(getent group "${GROUPID}" | cut --delimiter=: --fields=1)
echo "$WARNING docker group with $GROUPID has name $GROUPNAME"
fi
adduser "$SC_USER_NAME" "$GROUPNAME"
fi


echo "$INFO Starting $* ..."
echo " $SC_USER_NAME rights : $(id "$SC_USER_NAME")"
echo " local dir : $(ls -al)"
Expand Down

0 comments on commit 46fb131

Please sign in to comment.