Skip to content
Snippets Groups Projects
Commit 92a7ce09 authored by Razvan Deaconescu's avatar Razvan Deaconescu
Browse files

Add template files for assignments


These are setup and checker files for Operating Systems assignments.

Signed-off-by: default avatarRazvan Deaconescu <razvan.deaconescu@upb.ro>
parents
No related branches found
No related tags found
No related merge requests found
# This isn't a Linux kernel tree.
--no-tree
# Show the message type in the output.
--show-types
# Ignore warning related to MAINTAINERS file.
--ignore FILE_PATH_CHANGES
# Allow // comments.
--ignore C99_COMMENTS
# Relax checking for commit ID format.
--ignore GIT_COMMIT_ID
# Allow `extern` declarations in source code files.
--ignore AVOID_EXTERNS
# Allow adding new typedefs.
--ignore NEW_TYPEDEFS
# Ignore email subject format.
--ignore EMAIL_SUBJECT
# Ignore warnings when creating a frestanding environment (such as a libc).
--ignore SYMBOLIC_PERMS
--ignore ENOSYS
# Ignore ARRAY_SIZE, let `sizeof()` be used to determine array size.
# This makes the code compatible with other compilers / environments.
--ignore ARRAY_SIZE
image: docker:19.03.12
services:
- docker:19.03.12-dind
stages:
- build
- test
variables:
CONTAINER_RELEASE_IMAGE: $CI_REGISTRY_IMAGE:latest
DOCKER_HOST: tcp://docker:2375
DOCKER_TLS_CERTDIR: ""
build:
stage: build
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- docker build --pull -t $CONTAINER_RELEASE_IMAGE .
- docker push $CONTAINER_RELEASE_IMAGE
only:
variables:
- $BUILD_DOCKER_IMAGE
checker:
stage: test
image:
name: gitlab.cs.pub.ro:5050/operating-systems/assignment-template
script:
- echo ""
# From: https://github.com/dracutdevs/dracut/blob/master/.shellcheckrc
# SC2039: In POSIX sh, 'local' is undefined.
# https://github.com/koalaman/shellcheck/wiki/SC2039
disable=SC2039
# SC2166: Prefer [ p ] || [ q ] as [ p -o q ] is not well defined.
# https://github.com/koalaman/shellcheck/wiki/SC2166
disable=SC2166
# SC2154: Variable is referenced but not assigned
# https://github.com/koalaman/shellcheck/wiki/SC2154
disable=SC2154
# SC1091: Not following <file>
# https://github.com/koalaman/shellcheck/wiki/SC1091
disable=SC1091
# SC2174: When used with -p, -m only applies to the deepest directory.
# https://github.com/koalaman/shellcheck/wiki/SC2174
disable=SC2174
# SC3043: In POSIX sh, 'local' is undefined.
# https://github.com/koalaman/shellcheck/wiki/SC3043
# ... but dash supports it
disable=SC3043
# SC3013: In POSIX sh, -ef is undefined.
# https://github.com/koalaman/shellcheck/wiki/SC3013
# ... but dash supports it
disable=SC3013
# SC3045: In POSIX sh, read -p is undefined.
# https://github.com/koalaman/shellcheck/wiki/SC3045
# ... but dash supports it
disable=SC3045
filter=-whitespace/tab
filter=-whitespace/line-length
filter=-whitespace/braces
filter=-whitespace/semicolon
filter=-legal/copyright
filter=-whitespace/comments
filter=-build/header_guard
filter=-readability/multiline_comment
filter=-readability/casting
filter=-runtime/int
filter=-runtime/printf
linelength=120
FROM razvandeax/operating-systems-assignments-base
COPY ./checker ${CHECKER_DATA_DIRECTORY}
RUN mkdir ${CHECKER_DATA_DIRECTORY}/../tests
COPY ./tests ${CHECKER_DATA_DIRECTORY}/../tests
#!/bin/bash
# SPDX-License-Identifier: BSD-3-Clause
# (Re)Create tests/ directory with saved information.
rm -fr ../tests/
cp -r "$CHECKER_DATA_DIRECTORY"/../tests ..
# Everything happens in the tests/ directory.
pushd ../tests > /dev/null || exit 1
echo -e "### RUNING LINTER\n\n"
make lint
echo -e "\n\n### RUNING CHECKER\n\n"
make check
popd > /dev/null || exit 1
local.sh 0 → 100755
#!/bin/bash
cd "$(dirname "$0")" || exit 1
#=============================================================================
#================================= CONSTANTS =================================
#=============================================================================
RED='\033[0;31m'
NC='\033[0m'
DEFAULT_IMAGE_NAME=operating-systems/assignment-tutorial
DEFAULT_TAG='latest'
DEFAULT_REGISTRY='gitlab.cs.pub.ro:5050'
MOUNT_PROJECT_DIRECTORY="/build/$USER/$(basename "$(pwd)")"
#=============================================================================
#=================================== UTILS ===================================
#=============================================================================
LOG_INFO() {
echo -e "[$(date +%FT%T)] [INFO] $1"
}
LOG_FATAL() {
echo -e "[$(date +%FT%T)] [${RED}FATAL${NC}] $1"
exit 1
}
#=============================================================================
#=============================================================================
#=============================================================================
print_help() {
echo "Usage:"
echo ""
echo "local.sh checker|docker|-h|--help"
echo ""
echo " docker - runs docker commands to build, test or push an image made of this repo"
echo " checker - runs the checker"
echo " -h|--help - prints this message"
echo ""
echo "local.sh docker build [--image_name <image_name>] [--tag <tag>] [--registry <registry>] [--force_build]"
echo ""
echo " --image_name <image_name> - the name of the image (default: current directory name)"
echo " --tag <tag> - the tag of the image (default: 'latest')"
echo " --registry <registry> - the registry in which the image will be pushed (default: 'gitlab.cs.pub.ro:5050')"
echo " --force_build - disable caching when building the docker image"
echo ""
echo "local.sh docker push --user <user> --token <token> [--image_name <image_name>] [--tag <tag>] [--registry <registry>]"
echo ""
echo " --image_name <image_name> - the name of the image (default: current directory name)"
echo " --tag <tag> - the tag of the image (default: 'latest')"
echo " --registry <registry> - the registry in which the image will be pushed (default: 'gitlab.cs.pub.ro:5050')"
echo " --user <registry> - username for the repository registry"
echo " --token <token> - the token used to authenticate in the docker registry"
echo ""
echo "local.sh docker test [--full_image_name <full_image_name>] [argumets_for_checker]"
echo ""
echo " --full_image_name <full_image_name> - the full name of the image (default: gitlab.cs.pub.ro:5050/<current_directory_name>:latest)"
echo " argumets_for_checker - list of space separated arguments to be passed to the checker"
echo ""
echo "local.sh docker interactive [--full_image_name <full_image_name>] [--use_executable <executbale>]"
echo ""
echo " --full_image_name <full_image_name> - the full name of the image (default: gitlab.cs.pub.ro:5050/<current_directory_name>:latest)"
echo " --use_executable <executable> - command to run inside the container (default: /bin/bash)"
echo ""
echo "local.sh checker [--remove_image] [--use_existing_image <image_name>] [--force_build] [argumets_for_checker]"
echo ""
echo " --remove_image - remove the checker's docker image after the run"
echo " --use_existing_image - user image_name instead of building the image from current directory"
echo " --force_build - disable caching when building the docker image"
echo " argumets_for_checker - list of space separated arguments to be passed to the checker"
echo ""
}
docker_build() {
local image_name="$DEFAULT_IMAGE_NAME"
local tag="$DEFAULT_TAG"
local registry="$DEFAULT_REGISTRY"
local extra_docker_args=()
while [[ $# -gt 0 ]]; do
case $1 in
--image_name)
shift
image_name="$1"
;;
--tag)
shift
tag="$1"
;;
--registry)
shift
registry="$1"
;;
--force_build)
extra_docker_args+=('--no-cache')
;;
esac
shift
done
LOG_INFO "Building Docker image..."
docker image build "${extra_docker_args[@]}" -t "${registry}/${image_name}:${tag}" .
}
docker_push() {
local image_name="$DEFAULT_IMAGE_NAME"
local tag="$DEFAULT_TAG"
local registry="$DEFAULT_REGISTRY"
local user=''
local token=''
while [[ $# -gt 0 ]]; do
case $1 in
--image_name)
shift
image_name="$1"
;;
--tag)
shift
tag="$1"
;;
--registry)
shift
registry="$1"
;;
--user)
shift
user="$1"
;;
--token)
shift
token="$1"
;;
esac
shift
done
[ -z "$user" ] && LOG_FATAL "No user provided. Push operation will be aborted..."
[ -z "$token" ] && LOG_FATAL "No token provided. Push operation will be aborted..."
LOG_INFO "Pushing Docker image..."
docker login "${registry}" -u "${user}" -p "${token}"
docker push "${registry}/${image_name}:${tag}"
}
docker_test() {
local full_image_name="${DEFAULT_REGISTRY}/${DEFAULT_IMAGE_NAME}:${DEFAULT_TAG}"
while [[ $# -gt 0 ]]; do
case $1 in
--full_image_name)
shift
full_image_name="$1"
;;
esac
shift
done
checker_main --use_existing_image "$full_image_name" "$@"
}
docker_interactive() {
local full_image_name="${DEFAULT_REGISTRY}/${DEFAULT_IMAGE_NAME}:${DEFAULT_TAG}"
local executable="/bin/bash"
while [[ $# -gt 0 ]]; do
case $1 in
--full_image_name)
shift
full_image_name="$1"
;;
--use_executable)
shift
executable="$1"
;;
esac
shift
done
tmpdir="$(mktemp -d)"
cp -R ./* "$tmpdir"
docker run --rm -it \
--mount type=bind,source="$tmpdir",target="$MOUNT_PROJECT_DIRECTORY" \
--workdir "$MOUNT_PROJECT_DIRECTORY" \
"$full_image_name" "$executable"
}
docker_main() {
if [ "$1" = "build" ] ; then
shift
docker_build "$@"
elif [ "$1" = "push" ] ; then
shift
docker_push "$@"
elif [ "$1" = "test" ] ; then
shift
docker_test "$@"
elif [ "$1" = "interactive" ] ; then
shift
docker_interactive "$@"
fi
}
checker_main() {
local script_args=()
local remove_image=''
local image_name=''
local extra_docker_args=()
while [[ $# -gt 0 ]]; do
case $1 in
--remove_image)
remove_image='true'
;;
--use_existing_image)
shift
image_name="$1"
;;
--force_build)
extra_docker_args+=('--no-cache')
;;
*)
script_args+=("$1")
;;
esac
shift
done
if [ -z "$image_name" ] ; then
image_name="$(basename "$(pwd)")"
LOG_INFO "Building image..."
docker build "${extra_docker_args[@]}" -q -t "$image_name" .
fi
tmpdir="$(mktemp -d)"
cp -R ./* "$tmpdir"
LOG_INFO "Running checker..."
# In your checker script if you must use absolute paths please use $CI_PROJECT_DIR to reference the location of your directory,
# otherwise stick to relative paths.
# It is guaranteed that the current working directory in which checker.sh will run is $CI_PROJECT_DIR/checker.
docker run --rm \
--mount type=bind,source="$tmpdir",target="$MOUNT_PROJECT_DIRECTORY" \
"$image_name" /bin/bash -c "rm -rf /usr/local/bin/bash; cd \"$MOUNT_PROJECT_DIRECTORY/checker\"; \"$MOUNT_PROJECT_DIRECTORY/checker/checker.sh\" \"${script_args[@]}\"" # remove bash middleware script
if [ -n "$remove_image" ] ; then
LOG_INFO "Cleaning up..."
docker rmi -f "$image_name":latest
fi
}
if [ "$1" = "checker" ] ; then
shift
checker_main "$@"
elif [ "$1" = "docker" ] ; then
shift
docker_main "$@"
elif [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
print_help
else
print_help
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment