Skip to content

Commit

Permalink
use installed version of userver if any (#51)
Browse files Browse the repository at this point in the history
  • Loading branch information
apolukhin authored Apr 18, 2024
1 parent 0bafc5d commit 7b65cd4
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

27 changes: 18 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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()


Expand Down
4 changes: 1 addition & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions configs/config_vars.testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
2 changes: 1 addition & 1 deletion configs/config_vars.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
worker-threads: 4
worker-fs-threads: 2
logger-level: debug
logger-level: info

is-testing: false

Expand Down
5 changes: 2 additions & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
18 changes: 18 additions & 0 deletions tests/run_as_user.sh
Original file line number Diff line number Diff line change
@@ -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 "$@"
11 changes: 11 additions & 0 deletions third_party/Readme.md
Original file line number Diff line number Diff line change
@@ -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
```
1 change: 0 additions & 1 deletion third_party/userver
Submodule userver deleted from 2846de

0 comments on commit 7b65cd4

Please sign in to comment.