Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add container level test and refine document #72

Merged
merged 1 commit into from
Apr 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
- 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

16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
55 changes: 39 additions & 16 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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() {
Expand All @@ -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)
Expand All @@ -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
Expand Down
13 changes: 13 additions & 0 deletions test/ubi.Dockerfile
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions test/ubuntu.Dockerfile
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -70,6 +76,9 @@ main() {
cluster)
verify_cluster
;;
containerruntime)
containerruntime
;;
all | *)
verify_bcc
verify_cluster
Expand Down
Loading