aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoman Stratiienko <r.stratiienko@gmail.com>2022-12-15 10:12:31 +0200
committerRoman Stratiienko <r.stratiienko@gmail.com>2022-12-19 19:12:44 +0200
commit3295719124162e5091168173064fedf1cd28f5d3 (patch)
tree462cf3e9f64cce7dd78d95ab9b06e2b4f1b85a00
parent6b40505a7eb8f2e6126db5a8d1ad7fb552ac9040 (diff)
downloaddrm_hwcomposer-3295719124162e5091168173064fedf1cd28f5d3.tar.gz
drm_hwcomposer: Add support for running CI locally using docker
Prior to this commit running local CI script required the latest non-LTS ubuntu installed. To run CI on host run: make local_presubmit To run CI within docker container run: make ci With this commit we're also setting the stage for meson build. Change-Id: I759c35ef8da306de8759f290c11c39c4b237bb8c Signed-off-by: Roman Stratiienko <r.stratiienko@gmail.com>
-rwxr-xr-x.ci/.gitlab-ci-checkcommit.sh11
-rw-r--r--.ci/Dockerfile44
-rw-r--r--Makefile65
-rwxr-xr-xpresubmit.sh13
4 files changed, 120 insertions, 13 deletions
diff --git a/.ci/.gitlab-ci-checkcommit.sh b/.ci/.gitlab-ci-checkcommit.sh
index ff293a8..f854999 100755
--- a/.ci/.gitlab-ci-checkcommit.sh
+++ b/.ci/.gitlab-ci-checkcommit.sh
@@ -1,5 +1,13 @@
#! /usr/bin/env bash
+check_tool_installed() {
+ if ! command -v $1 &> /dev/null
+ then
+ echo "Please install '$1' tool"
+ exit 1
+ fi
+}
+
echoerr() {
printf "ERROR: %s\n" "$*" >&2
}
@@ -27,6 +35,9 @@ findtag() {
return 1
}
+check_tool_installed bpfmt
+check_tool_installed clang-format-diff-15
+
git fetch https://gitlab.freedesktop.org/drm-hwcomposer/drm-hwcomposer.git
git log --pretty='%h' FETCH_HEAD..HEAD | while read h; do
diff --git a/.ci/Dockerfile b/.ci/Dockerfile
new file mode 100644
index 0000000..d0ecee2
--- /dev/null
+++ b/.ci/Dockerfile
@@ -0,0 +1,44 @@
+FROM ubuntu:22.10
+
+ENV DEBIAN_FRONTEND=noninteractive
+
+ENV PATH="/home/user/bin:${PATH}"
+
+# Taking into account layer structure, everything should be done within one layer.
+RUN apt-get update && apt-get upgrade -y && \
+ apt-get install -y clang-15 clang-tidy-15 clang-format-15 git libdrm-dev blueprint-tools libgtest-dev clang llvm make python3 python3-pip wget sudo && \
+ pip3 install mako meson jinja2 ply pyyaml
+
+ENV RUN_USER user
+ENV RUN_UID 1000
+
+ENV USER_HOME /home/${RUN_USER}
+
+RUN mkdir -pv ${USER_HOME}
+# Create new user
+RUN adduser \
+ --gecos 'Build User' \
+ --shell '/usr/bin/bash' \
+ --uid ${RUN_UID} \
+ --disabled-login \
+ --disabled-password ${RUN_USER} \
+ && adduser ${RUN_USER} sudo
+
+RUN chown -R ${RUN_USER}:${RUN_USER} ${USER_HOME} && chmod -R 775 ${USER_HOME}
+
+# Ensure sudo group users are not
+# asked for a password when using
+# sudo command by ammending sudoers file
+RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> \
+/etc/sudoers
+
+# Pass control to a newly created user
+USER ${RUN_USER}
+
+# Create project path
+RUN mkdir -pv ${USER_HOME}/drm_hwcomposer
+WORKDIR ${USER_HOME}/drm_hwcomposer
+
+RUN git config --global user.name "FIRST_NAME LAST_NAME" && git config --global user.email "MY_NAME@example.com"
+
+CMD [ "/bin/bash" ]
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..16269e2
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,65 @@
+#!/usr/bin/make
+
+DOCKER_BIN := $(shell command -v docker 2> /dev/null)
+NPROCS:=$(shell grep -c ^processor /proc/cpuinfo)
+
+DOCKERFILE := .ci/Dockerfile
+IMAGE_NAME := drmhwc_ci
+
+# We can't run style and bpfmt check in docker
+# when repo is within AOSP tree, will run it locally.
+GIT_IS_SYMLINK:=$(shell test -L .git && echo true)
+
+define print_no_docker_err
+$(warning Please install docker, e.g. for Ubuntu:)
+$(warning $$ sudo apt install docker.io)
+$(warning $$ sudo usermod -aG docker $$USER)
+$(warning and reboot your PC)
+$(error Aborting...)
+endef
+
+.PHONY : help prepare shell ci ci_cleanup local_presubmit local_cleanup
+.DEFAULT_GOAL := help
+
+help: ## Show this help
+ @awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)
+
+PREPARE:=.out/prepare_docker.timestamp
+$(PREPARE): $(DOCKERFILE)
+ $(if $(DOCKER_BIN),,$(call print_no_docker_err))
+ mkdir -p $(dir $@)
+ $(DOCKER_BIN) build -t local/build-env -f $(DOCKERFILE) .;
+ $(DOCKER_BIN) stop $(IMAGE_NAME) || true
+ $(DOCKER_BIN) rm $(IMAGE_NAME) || true
+ $(DOCKER_BIN) run -itd --name $(IMAGE_NAME) --network="host" -v $(shell pwd):/home/user/drm_hwcomposer local/build-env
+ @touch $@
+
+prepare: $(PREPARE)
+prepare: ## Build and run Docker image
+
+shell: $(PREPARE)
+shell: ## Start shell into a container
+ $(DOCKER_BIN) exec -it $(IMAGE_NAME) bash
+
+ci: $(PREPARE)
+ci: ## Run presubmit within the docker container
+ @echo "Run native build:"
+ $(DOCKER_BIN) exec -it $(IMAGE_NAME) bash -c "make -f .ci/Makefile -j$(NPROCS)"
+ @echo "Run style check:"
+ $(if $(GIT_IS_SYMLINK), \
+ ./.ci/.gitlab-ci-checkcommit.sh, \
+ $(DOCKER_BIN) exec -it $(IMAGE_NAME) bash -c "./.ci/.gitlab-ci-checkcommit.sh")
+ @echo "\n\e[32m --- SUCCESS ---\n"
+
+ci_cleanup: ## Cleanup after 'make ci'
+ $(DOCKER_BIN) exec -it $(IMAGE_NAME) bash -c "make local_cleanup"
+
+local_presubmit: ## Run local presubmit script (requires latest Ubuntu + additional packages). Consider 'make ci' instead
+ @echo "Run native build:"
+ make -f .ci/Makefile -j12
+ @echo "Run style check:"
+ ./.ci/.gitlab-ci-checkcommit.sh
+ @echo "\n\e[32m --- SUCCESS ---\n"
+
+local_cleanup: ## Cleanup after 'make local_presubmit'
+ make -f .ci/Makefile clean
diff --git a/presubmit.sh b/presubmit.sh
deleted file mode 100755
index a551398..0000000
--- a/presubmit.sh
+++ /dev/null
@@ -1,13 +0,0 @@
-#!/bin/bash
-
-set -e
-
-echo "Run native build:"
-
-make -f .ci/Makefile -j12
-
-echo "Run style check:"
-
-./.ci/.gitlab-ci-checkcommit.sh
-
-echo -e "\n\e[32m --- SUCCESS ---"