From 6d01be39e26d5fdbdebf6fa74ba4c1dd0a1a024d Mon Sep 17 00:00:00 2001 From: Mohamed Bana Date: Thu, 1 Aug 2024 18:55:33 +0100 Subject: [PATCH] Build on Ubuntu 22.04 * `autolib/docker.sh`: Add `autolib_new_ubuntu_22_04_template` function to generate `Dockerfile` for Ubuntu 22.04. * `promhttp/include/promhttp.h` and `promhttp/src/promhttp.c`: Definitions changed in libmicrohttpd so change it to match. * `autolib/build.sh`: Remove `-v` from the call to CMAKE so it is compatible with the version shipped in Ubuntu 22.04. * `.github/workflows/ci.yaml`: Add workflow for Ubuntu 22.04. Signed-off-by: Mohamed Bana --- .github/workflows/ci.yaml | 12 +++++++++++- auto | 2 +- autolib/build.sh | 2 +- autolib/docker.sh | 26 ++++++++++++++++++++++++++ promhttp/include/promhttp.h | 9 +++++++++ promhttp/src/promhttp.c | 3 ++- 6 files changed, 50 insertions(+), 4 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 513f47d..3500653 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -5,6 +5,16 @@ on: - pull_request jobs: + ubuntu-22-04: + name: ubuntu-22-04 + runs-on: ubuntu-22.04 + steps: + - uses: actions/checkout@v2 + - name: test + env: + DOCKER_IMAGE: ubuntu:22.04 + CI: 1 + run: make ubuntu-20-04: name: ubuntu-20-04 runs-on: ubuntu-latest @@ -64,4 +74,4 @@ jobs: env: DOCKER_IMAGE: debian:jessie CI: 1 - run: make \ No newline at end of file + run: make diff --git a/auto b/auto index 92ed18f..9f508ce 100755 --- a/auto +++ b/auto @@ -11,7 +11,7 @@ if [[ "$AUTO_DEBUG" == "1" ]]; then fi export PROJECT_ROOT=$(pushd $(dirname $0) > /dev/null; echo $PWD; popd > /dev/null) -export DOCKER_IMAGE +export DOCKER_IMAGE="${DOCKER_IMAGE:=ubuntu:22.04}" export CI=${CI:=0} export CC=/usr/bin/gcc diff --git a/autolib/build.sh b/autolib/build.sh index 42ec7de..f792d14 100644 --- a/autolib/build.sh +++ b/autolib/build.sh @@ -19,7 +19,7 @@ autolib_build() { pushd ${lib}/build > /dev/null || return $? autolib_output_banner "${lib}: CMake Build Stage" # YOU MUST set TEST to 1 in order to build the tests - TEST=$build_test cmake -v .. || { + TEST=$build_test cmake .. || { autolib_output_error "${lib}: CMake Failure" return 1 } diff --git a/autolib/docker.sh b/autolib/docker.sh index 7f78d83..d14623f 100644 --- a/autolib/docker.sh +++ b/autolib/docker.sh @@ -5,6 +5,25 @@ source "${lib}/output.sh" PROJECT_ROOT=$(pushd "$(dirname ${BASH_SOURCE[0]})/.." > /dev/null; echo $PWD; popd > /dev/null) +autolib_new_ubuntu_22_04_template() { + cat <<'EOF' +FROM __DOCKER_IMAGE__ + +RUN apt-get update -y +RUN apt-get install -y apt-utils software-properties-common clang-format git tar curl build-essential pkg-config gdb valgrind gcc libmicrohttpd-dev doxygen graphviz cmake golang +RUN go install github.com/prometheus/prom2json/cmd/prom2json@v1.3.3 +RUN go install github.com/git-chglog/git-chglog/cmd/git-chglog@latest +RUN printf "export PATH="${PATH}:$(go env GOPATH)/bin"" >> /root/.bash_profile +RUN printf '#!/usr/bin/env bash\nsource /root/.bash_profile\nexec /bin/bash $@\n' > /entrypoint +RUN chmod +x /entrypoint +RUN rm -rf /var/lib/apt/lists/* + +WORKDIR /code +ENTRYPOINT ["/entrypoint"] + +EOF +} + autolib_new_debian_template(){ cat <<'EOF' FROM __DOCKER_IMAGE__ @@ -102,6 +121,13 @@ autolib_write_dockerfile(){ local docker_image="$1" local r case "$docker_image" in + ( ubuntu:22.04 ) { + autolib_new_ubuntu_22_04_template | sed "s/__DOCKER_IMAGE__/$docker_image/g" > ${PROJECT_ROOT}/docker/Dockerfile || { + r=$? + autolib_output_error "failed to generate dockerfile" + return $r + } + } ;; ( ubuntu:20.04 | ubuntu:18.04 ) { autolib_new_debian_template | sed "s/__DOCKER_IMAGE__/$docker_image/g" > ${PROJECT_ROOT}/docker/Dockerfile || { r=$? diff --git a/promhttp/include/promhttp.h b/promhttp/include/promhttp.h index fc47523..2e69f31 100644 --- a/promhttp/include/promhttp.h +++ b/promhttp/include/promhttp.h @@ -36,6 +36,15 @@ */ void promhttp_set_active_collector_registry(prom_collector_registry_t *active_registry); +#if MHD_VERSION >= 0x00097002 +#define PROM_MHD_RESULT enum MHD_Result +#else +#define PROM_MHD_RESULT int +#endif + +PROM_MHD_RESULT promhttp_handler(void *cls, struct MHD_Connection *connection, const char *url, const char *method, + const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls); + /** * @brief Starts a daemon in the background and returns a pointer to an HMD_Daemon. * diff --git a/promhttp/src/promhttp.c b/promhttp/src/promhttp.c index d94a53e..9a1327a 100644 --- a/promhttp/src/promhttp.c +++ b/promhttp/src/promhttp.c @@ -18,6 +18,7 @@ #include "microhttpd.h" #include "prom.h" +#include "promhttp.h" prom_collector_registry_t *PROM_ACTIVE_REGISTRY; @@ -29,7 +30,7 @@ void promhttp_set_active_collector_registry(prom_collector_registry_t *active_re } } -int promhttp_handler(void *cls, struct MHD_Connection *connection, const char *url, const char *method, +PROM_MHD_RESULT promhttp_handler(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **con_cls) { if (strcmp(method, "GET") != 0) { char *buf = "Invalid HTTP Method\n";