From c746a2c1bed41a0db561fe61ea78364a2520e707 Mon Sep 17 00:00:00 2001 From: Sam Yuan Date: Thu, 4 Apr 2024 10:15:00 +0800 Subject: [PATCH] add container level test Signed-off-by: Sam Yuan --- .github/workflows/test.yml | 30 +++++++++++++++++++++ README.md | 16 ++++++++++- main.sh | 55 +++++++++++++++++++++++++++----------- test/ubi.Dockerfile | 13 +++++++++ test/ubuntu.Dockerfile | 8 ++++++ verify.sh | 9 +++++++ 6 files changed, 114 insertions(+), 17 deletions(-) create mode 100644 test/ubi.Dockerfile create mode 100644 test/ubuntu.Dockerfile diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3f0ad7c..384104d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -86,3 +86,33 @@ jobs: run: | export CLUSTER_PROVIDER=${{matrix.cluster_provider}} ./verify.sh + + containertestubuntu: + needs: + - shellcheck + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + include: + - OS: ubuntu + - OS: ubi + steps: + - name: Checkout + uses: actions/checkout@v4.1.1 + - name: Set up QEMU + uses: docker/setup-qemu-action@v3 + with: + image: tonistiigi/binfmt:qemu-v8.1.5 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: test image with container + uses: docker/build-push-action@v5 + with: + context: . + file: ./test/${{matrix.OS}}.Dockerfile + platforms: linux/amd64 + #,linux/arm64,linux/s390x later + push: false + tags: testcontainer:latest + diff --git a/README.md b/README.md index 30c934c..6d03c85 100644 --- a/README.md +++ b/README.md @@ -5,15 +5,29 @@ This repo provides the scripts to create a local [kubernetes](kind/kind.sh)/[openshift](microshift/microshift.sh) cluster to be used for development or integration tests. It is also used in [Github action](https://github.com/sustainable-computing-io/kepler-action) for kepler. -## Prerequisites +## Prerequisites for this REPO - [kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl-linux/) - [kind](https://kind.sigs.k8s.io/docs/user/quick-start/#installing-from-release-binaries) +- [Git](https://git-scm.com/) Please install the same version of `kubectl` and `kind` as Github-hosted runner. Currently Kepler project's Github Action only supports `Ubuntu` based runners. You can refer to tools list [here](https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md#tools) + +## Prerequisites (optional) +``` +./main.sh prerequisites +``` +Will setup ebpf on your host instance. + +## Container runtime (optional) +``` +./main.sh containerruntime +``` +Will setup container runtime on your host instance. + ## Startup 1. Modify kind [config](./kind/manifests/kind.yml) to make sure `extraMounts:` cover the linux header and BCC. 2. Export `CLUSTER_PROVIDER` env variable: diff --git a/main.sh b/main.sh index a4cc1de..67d8494 100755 --- a/main.sh +++ b/main.sh @@ -53,6 +53,7 @@ declare -r PROMETHEUS_ENABLE=${PROMETHEUS_ENABLE:-false} declare -r GRAFANA_ENABLE=${GRAFANA_ENABLE:-false} declare -r TEKTON_ENABLE=${TEKTON_ENABLE:-false} declare -r LIBBPF_VERSION=${LIBBPF_VERSION:-v1.2.0} +declare -r RESTARTCONTAINERRUNTIME=${RESTARTCONTAINERRUNTIME:-false} source "$PROJECT_ROOT/lib/utils.sh" @@ -142,20 +143,36 @@ ebpf() { } containerruntime() { - # Add Docker's official GPG key: - sudo apt-get update -y - sudo apt-get install ca-certificates curl gnupg -y - install -m 0755 -d /etc/apt/keyrings - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg - chmod a+r /etc/apt/keyrings/docker.gpg - # Add the repository to Apt sources: - echo \ - "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ - $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ - tee /etc/apt/sources.list.d/docker.list > /dev/null - apt-get update -y - apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y - docker info + set -x + echo start install container runtime as docker + if [ -f /usr/bin/yum ]; then + echo install yum utils + yum install -y yum-utils + echo config yum repo + yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo + echo install docker + yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y + fi + if [ -f /usr/bin/apt-get ]; then + # Add Docker's official GPG key: + echo install docker with apt + sudo apt-get update -y + sudo apt-get install ca-certificates curl gnupg -y + install -m 0755 -d /etc/apt/keyrings + curl -fsSL https://download.docker.com/linux/ubuntu/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg + chmod a+r /etc/apt/keyrings/docker.gpg + # Add the repository to Apt sources: + echo \ + "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \ + $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \ + tee /etc/apt/sources.list.d/docker.list > /dev/null + apt-get update -y + apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y + fi + set +x + if is_set "$RESTARTCONTAINERRUNTIME"; then + sudo systemctl start docker + fi } main() { @@ -175,8 +192,6 @@ main() { # shellcheck source=providers/kind/kind.sh # shellcheck source=providers/microshift/microshift.sh - source "$cluster_lib" - print_config case "$1" in prerequisites) @@ -189,21 +204,29 @@ main() { return $? ;; up) + source "$cluster_lib" + print_config cluster_up return $? ;; down) + source "$cluster_lib" + print_config cluster_down return $? ;; restart) + source "$cluster_lib" + print_config cluster_down || true cluster_up return $? ;; *) echo "unknown command $1; bringing a cluster up" + source "$cluster_lib" + print_config cluster_up ;; esac diff --git a/test/ubi.Dockerfile b/test/ubi.Dockerfile new file mode 100644 index 0000000..8d1095b --- /dev/null +++ b/test/ubi.Dockerfile @@ -0,0 +1,13 @@ +From registry.access.redhat.com/ubi9 + +USER 0 + +WORKDIR /workspace + +COPY . . +RUN yum update -y && yum install -y git sudo +#RUN yum install -y yum-utils +#RUN yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo +#RUN yum install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y +RUN sudo ./main.sh containerruntime +RUN sudo ./verify.sh containerruntime \ No newline at end of file diff --git a/test/ubuntu.Dockerfile b/test/ubuntu.Dockerfile new file mode 100644 index 0000000..c0127d9 --- /dev/null +++ b/test/ubuntu.Dockerfile @@ -0,0 +1,8 @@ +From ubuntu + +WORKDIR /workspace + +COPY . . +RUN apt-get update -y && apt-get install -y git sudo +RUN ./main.sh containerruntime +RUN ./verify.sh containerruntime \ No newline at end of file diff --git a/verify.sh b/verify.sh index 3a9dd64..bd6e3e1 100755 --- a/verify.sh +++ b/verify.sh @@ -61,6 +61,12 @@ verify_cluster() { ok "Cluster is up and running" } +containerruntime() { + which docker + # there is a docker in docker issue on GHA, use a or true logic as workaround + docker info || true +} + main() { # verify the deployment of cluster case $1 in @@ -70,6 +76,9 @@ main() { cluster) verify_cluster ;; + containerruntime) + containerruntime + ;; all | *) verify_bcc verify_cluster