From b0efa7f12b02c9260fd5e3aef628c122dbd2ef90 Mon Sep 17 00:00:00 2001 From: Antony Polukhin Date: Thu, 18 Apr 2024 17:55:27 +0300 Subject: [PATCH] use installed version of userver if any --- .github/workflows/ci.yml | 3 ++- .github/workflows/update-submodules.yaml | 22 ---------------------- .gitmodules | 3 --- CMakeLists.txt | 21 +++++++++++++++------ Makefile | 4 +--- configs/config_vars.testing.yaml | 2 ++ configs/config_vars.yaml | 2 +- docker-compose.yml | 5 ++--- tests/run_as_user.sh | 18 ++++++++++++++++++ third_party/Readme.md | 11 +++++++++++ third_party/userver | 1 - 11 files changed, 52 insertions(+), 40 deletions(-) delete mode 100644 .github/workflows/update-submodules.yaml delete mode 100644 .gitmodules create mode 100755 tests/run_as_user.sh create mode 100644 third_party/Readme.md delete mode 160000 third_party/userver diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d0bf9e5..40a7de4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,8 +42,9 @@ jobs: - name: Install packages run: | + (cd third_party && git clone -b develop --single-branch --depth 1 https://github.com/userver-framework/userver.git) sudo apt update - sudo apt install --allow-downgrades -y pep8 $(cat third_party/userver/scripts/docs/en/deps/${{matrix.os}}.md | tr '\n' ' ') + sudo apt install --allow-downgrades -y pycodestyle $(cat third_party/userver/scripts/docs/en/deps/${{matrix.os}}.md | tr '\n' ' ') - name: Setup ccache run: | diff --git a/.github/workflows/update-submodules.yaml b/.github/workflows/update-submodules.yaml deleted file mode 100644 index 9603da8..0000000 --- a/.github/workflows/update-submodules.yaml +++ /dev/null @@ -1,22 +0,0 @@ -name: Update submodules - -on: - workflow_dispatch: - -jobs: - update: - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v2 - - - name: Update submodules - run: | - git submodule update --init - - - name: Commit & push changes - run: | - git config user.email "actions@github.com" - git config user.name "GitHub Actions - update submodules" - git commit -am "Update submodules" - git push diff --git a/.gitmodules b/.gitmodules deleted file mode 100644 index 4d25646..0000000 --- a/.gitmodules +++ /dev/null @@ -1,3 +0,0 @@ -[submodule "third_party/userver"] - path = third_party/userver - url = https://github.com/userver-framework/userver.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b67dde..591b2d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,14 +1,23 @@ cmake_minimum_required(VERSION 3.12) project(service_template CXX) -# Compatibility mode: some systems don't support these features -set(USERVER_FEATURE_CRYPTOPP_BLAKE2 OFF CACHE BOOL "" FORCE) -set(USERVER_FEATURE_GRPC_CHANNELZ OFF CACHE BOOL "" FORCE) -set(USERVER_FEATURE_REDIS_HI_MALLOC ON CACHE BOOL "" FORCE) - # Adding userver dependency -add_subdirectory(third_party/userver) +find_package(userver COMPONENTS core postgresql QUIET) +if(NOT userver_FOUND) # Fallback to subdirectory usage + # Compatibility mode: some systems don't support these features + set(USERVER_FEATURE_CRYPTOPP_BLAKE2 OFF CACHE BOOL "" FORCE) + set(USERVER_FEATURE_GRPC_CHANNELZ OFF CACHE BOOL "" FORCE) + set(USERVER_FEATURE_REDIS_HI_MALLOC ON CACHE BOOL "" FORCE) + + if (EXISTS third_party/userver) + message(STATUS "Using userver framework from third_party/userver") + add_subdirectory(third_party/userver) + else() + message(FATAL_ERROR "Either install the userver or provide a path to it") + endif() +endif() + userver_setup_environment() diff --git a/Makefile b/Makefile index 5ec81a8..5c911ad 100644 --- a/Makefile +++ b/Makefile @@ -17,12 +17,10 @@ all: test-debug test-release # Run cmake .PHONY: cmake-debug cmake-debug: - git submodule update --init cmake -B build_debug $(CMAKE_DEBUG_FLAGS) .PHONY: cmake-release cmake-release: - git submodule update --init cmake -B build_release $(CMAKE_RELEASE_FLAGS) build_debug/CMakeCache.txt: cmake-debug @@ -39,7 +37,7 @@ test-debug test-release: test-%: build-% cmake --build build_$* -j $(NPROCS) --target service_template_unittest cmake --build build_$* -j $(NPROCS) --target service_template_benchmark cd build_$* && ((test -t 1 && GTEST_COLOR=1 PYTEST_ADDOPTS="--color=yes" ctest -V) || ctest -V) - pep8 tests + pycodestyle tests # Start the service (via testsuite service runner) .PHONY: service-start-debug service-start-release diff --git a/configs/config_vars.testing.yaml b/configs/config_vars.testing.yaml index 66b744e..828e658 100644 --- a/configs/config_vars.testing.yaml +++ b/configs/config_vars.testing.yaml @@ -3,3 +3,5 @@ worker-fs-threads: 2 logger-level: debug is_testing: true + +server-port: 8080 diff --git a/configs/config_vars.yaml b/configs/config_vars.yaml index a7ec8b1..d44ed88 100644 --- a/configs/config_vars.yaml +++ b/configs/config_vars.yaml @@ -1,6 +1,6 @@ worker-threads: 4 worker-fs-threads: 2 -logger-level: debug +logger-level: info is_testing: false diff --git a/docker-compose.yml b/docker-compose.yml index 50d2ad7..ae9ee6b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,7 +2,7 @@ version: "2.3" services: service_template-container: - image: ghcr.io/userver-framework/ubuntu-22.04-userver-base-ci:latest + image: ghcr.io/userver-framework/ubuntu-22.04-userver-pg:latest privileged: true network_mode: bridge environment: @@ -11,9 +11,8 @@ services: - CORES_DIR=/cores volumes: - .:/service_template:rw - - ./third_party/userver/scripts/docker/:/tools:ro ports: - 8080:8080 working_dir: /service_template entrypoint: - - /tools/run_as_user.sh + - ./tests/run_as_user.sh diff --git a/tests/run_as_user.sh b/tests/run_as_user.sh new file mode 100755 index 0000000..5e0c9f1 --- /dev/null +++ b/tests/run_as_user.sh @@ -0,0 +1,18 @@ +#!/usr/bin/env bash + +# Exit on any error and treat unset variables as errors +set -euo pipefail + +DIR_UID="$(stat -c '%u' .)" + +if ! id -u user > /dev/null 2> /dev/null; then + if [ "$DIR_UID" = "0" ]; then + useradd --create-home --no-user-group user + else + useradd --create-home --no-user-group --uid $DIR_UID user + fi +elif [ "$DIR_UID" != "0" ]; then + usermod -u $DIR_UID user +fi + +HOME=/home/user sudo -E -u user "$@" diff --git a/third_party/Readme.md b/third_party/Readme.md new file mode 100644 index 0000000..2e623aa --- /dev/null +++ b/third_party/Readme.md @@ -0,0 +1,11 @@ +### Directory for third party libraries + +`userver` placed into this directory would be used if there's no installed +userver framework. For example: + +``` +cd /data/code +git clone --depth 1 https://github.com/userver-framework/userver.git +git clone --depth 1 https://github.com/userver-framework/service_template.git +ln -s /data/code/userver /data/code/service_template/third_party/userver +``` diff --git a/third_party/userver b/third_party/userver deleted file mode 160000 index 2846de7..0000000 --- a/third_party/userver +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 2846de78187610740fd29d81195c06998ed6cdce