From 5a7b82d9de2f8186cafac4fc580c1239035fd6d0 Mon Sep 17 00:00:00 2001 From: Mads Bisgaard Date: Fri, 17 Jan 2025 11:04:09 +0100 Subject: [PATCH] add docker test image --- tests/performance/Makefile | 11 +++ tests/performance/docker/Dockerfile | 81 +++++++++++++++++++ tests/performance/requirements/_base.txt | 1 + .../requirements/requirements-dev.txt | 1 - 4 files changed, 93 insertions(+), 1 deletion(-) create mode 100644 tests/performance/docker/Dockerfile diff --git a/tests/performance/Makefile b/tests/performance/Makefile index 9c144b18479..b963a55902d 100644 --- a/tests/performance/Makefile +++ b/tests/performance/Makefile @@ -13,6 +13,9 @@ KERNEL_NAME=$(shell uname -s) NETWORK_NAME=dashboards_timenet +TEST_IMAGE_NAME := itisfoundation/performance-tests +TEST_IMAGE_TAG := v0 + # UTILS # NOTE: keep short arguments for `cut` so it works in both BusyBox (alpine) AND Ubuntu get_my_ip := $(shell (hostname --all-ip-addresses || hostname -i) 2>/dev/null | cut -d " " -f 1) @@ -88,3 +91,11 @@ install-ci: config: ## Create config for your locust tests @$(call check_defined, input, please define inputs when calling $@ - e.g. ```make $@ input="--help"```) @uv run locust_settings.py $(input) | tee "${ENV_FILE}" + + +.PHONY: build push +build: ## Build test image + docker build -t ${TEST_IMAGE_NAME}:${TEST_IMAGE_TAG} ./docker + +push: ## Push test image to dockerhub + docker push ${TEST_IMAGE_NAME}:${TEST_IMAGE_TAG} diff --git a/tests/performance/docker/Dockerfile b/tests/performance/docker/Dockerfile new file mode 100644 index 00000000000..d42e0493eac --- /dev/null +++ b/tests/performance/docker/Dockerfile @@ -0,0 +1,81 @@ +# syntax=docker/dockerfile:1 + +ARG PYTHON_VERSION="3.11.9" +ARG UV_VERSION="0.4" +FROM ghcr.io/astral-sh/uv:${UV_VERSION} AS uv_build +FROM python:${PYTHON_VERSION}-slim-bookworm AS base + +LABEL maintainer=bisgaard-itis + +# NOTE: to list the latest version run `make` inside `scripts/apt-packages-versions` +ENV DOCKER_APT_VERSION="5:26.1.4-1~debian.12~bookworm" + +# for docker apt caching to work this needs to be added: [https://vsupalov.com/buildkit-cache-mount-dockerfile/] +RUN rm -f /etc/apt/apt.conf.d/docker-clean && \ + echo 'Binary::apt::APT::Keep-Downloaded-Packages "true";' > /etc/apt/apt.conf.d/keep-cache +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + set -eux; \ + apt-get update; \ + apt-get install -y --no-install-recommends \ + gosu \ + ca-certificates \ + curl \ + gnupg \ + lsb-release \ + && mkdir -p /etc/apt/keyrings \ + && curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg \ + && echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \ + $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null \ + && apt-get update \ + && apt-get install -y --no-install-recommends \ + # only the cli is needed and we remove the unnecessary stuff again + docker-ce-cli=${DOCKER_APT_VERSION} \ + && apt-get remove -y\ + gnupg \ + curl \ + lsb-release \ + && apt-get clean -y\ + # verify that the binary works + && gosu nobody true + +# Sets utf-8 encoding for Python et al +ENV LANG=C.UTF-8 + +# Turns off writing .pyc files; superfluous on an ephemeral container. +ENV PYTHONDONTWRITEBYTECODE=1 \ + VIRTUAL_ENV=/home/scu/.venv + +# Ensures that the python and pip executables used in the image will be +# those from our virtualenv. +ENV PATH="${VIRTUAL_ENV}/bin:$PATH" + + +# -------------------------- Build stage ------------------- +# Installs build/package management tools and third party dependencies +# +# + /build WORKDIR +# +FROM base AS build + +ENV SC_BUILD_TARGET=build + +RUN --mount=type=cache,target=/var/cache/apt,sharing=private \ + set -eux \ + && apt-get update \ + && apt-get install -y --no-install-recommends \ + build-essential \ + curl \ + git \ + jq + +# install UV https://docs.astral.sh/uv/guides/integration/docker/#installing-uv +COPY --from=uv_build /uv /uvx /bin/ + +RUN uv venv "${VIRTUAL_ENV}" + +RUN --mount=type=cache,target=/root/.cache/uv \ + uv pip install --upgrade \ + wheel \ + setuptools + +WORKDIR /test diff --git a/tests/performance/requirements/_base.txt b/tests/performance/requirements/_base.txt index fd952c4bbe1..163773d8db3 100644 --- a/tests/performance/requirements/_base.txt +++ b/tests/performance/requirements/_base.txt @@ -1,3 +1,4 @@ +locust-plugins parse pydantic pydantic-settings diff --git a/tests/performance/requirements/requirements-dev.txt b/tests/performance/requirements/requirements-dev.txt index a971eec6195..dc7dd1458a8 100644 --- a/tests/performance/requirements/requirements-dev.txt +++ b/tests/performance/requirements/requirements-dev.txt @@ -1,2 +1 @@ --requirement _base.txt -locust-plugins