diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6e032f9..2b5e887 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/.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 b3fb1b6..96cc6bc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,17 +1,26 @@ cmake_minimum_required(VERSION 3.12) project(pg_service_template CXX) -# Enable userver libraries that are needed in this project -set(USERVER_FEATURE_POSTGRESQL ON CACHE BOOL "" FORCE) - -# 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 + # Enable userver libraries that are needed in this project + set(USERVER_FEATURE_POSTGRESQL ON CACHE BOOL "" FORCE) + + # 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 5713a79..bfdb153 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 pg_service_template_unittest cmake --build build_$* -j $(NPROCS) --target pg_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 12bbeae..d10069b 100644 --- a/configs/config_vars.testing.yaml +++ b/configs/config_vars.testing.yaml @@ -4,5 +4,7 @@ logger-level: debug is-testing: true +server-port: 8080 + # pg_service_template_db_1 is the service name + _ + filename of the db_1.sql dbconnection: 'postgresql://testsuite@localhost:15433/pg_service_template_db_1' diff --git a/configs/config_vars.yaml b/configs/config_vars.yaml index c3f6195..9eb01e2 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 6ad623f..2dc08be 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,7 +17,7 @@ services: - postgres pg_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 environment: - POSTGRES_DB=pg_service_template_db-1 @@ -28,13 +28,12 @@ services: - CORES_DIR=/cores volumes: - .:/pg_service_template:rw - - ./third_party/userver/scripts/docker/:/tools:ro - ${TC_CORES_DIR:-./.cores}:/cores:rw ports: - 8080:8080 working_dir: /pg_service_template entrypoint: - - /tools/run_as_user.sh + - ./tests/run_as_user.sh depends_on: - postgres networks: 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..4b54f04 --- /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/pg_service_template.git +ln -s /data/code/userver /data/code/pg_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