Skip to content

Commit

Permalink
use installed version of userver if any (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
apolukhin authored Apr 19, 2024
1 parent cd7daec commit 90c0d7c
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 26 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
name: CI

'on':
schedule:
- cron: '30 5 * * 1' # Every Monday at 5:30
pull_request:
push:
branches:
Expand Down Expand Up @@ -42,8 +44,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 postgresql $(cat third_party/userver/scripts/docs/en/deps/${{matrix.os}}.md | tr '\n' ' ')
- name: Setup ccache
run: |
Expand Down
5 changes: 2 additions & 3 deletions .github/workflows/docker.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
name: Docker build

'on':
schedule:
- cron: '30 5 * * 1' # Every Monday at 5:30
pull_request:
push:
branches:
- master
- develop
- feature/**

env:
CMAKE_COMMON_FLAGS: -DUserverGrpc_VERSION=1.51.0

jobs:
tests:
runs-on: ubuntu-latest
Expand Down
3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

19 changes: 17 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,24 @@ set(USERVER_FEATURE_POSTGRESQL ON CACHE BOOL "" FORCE)
set(USERVER_FEATURE_CRYPTOPP_BLAKE2 OFF 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)

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()


# Service target
file(
GLOB_RECURSE SOURCES
Expand All @@ -20,7 +35,7 @@ file(
add_executable("${PROJECT_NAME}" ${SOURCES})

target_include_directories("${PROJECT_NAME}" PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/src")
target_link_libraries("${PROJECT_NAME}" userver-core userver-postgresql)
target_link_libraries("${PROJECT_NAME}" userver::core userver::postgresql)

# Functional Tests
include(UserverTestsuite)
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 @@ -37,7 +35,7 @@ build-debug build-release: build-%: build_%/CMakeCache.txt
.PHONY: test-debug test-release
test-debug test-release: test-%: build-%
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 @@ -3,4 +3,6 @@ logger-level: debug

is_testing: true

server-port: 8083

dbconnection: 'postgresql://testsuite@localhost:15433/testdb_uservice_dynconf'
2 changes: 1 addition & 1 deletion configs/config_vars.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
worker-threads: 4
logger-level: debug
logger-level: info

is_testing: false

Expand Down
14 changes: 2 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,32 +17,22 @@ services:
- postgres

uservice-dynconf-container:
image: ghcr.io/userver-framework/ubuntu-userver-build-base:v1
image: ghcr.io/userver-framework/ubuntu-22.04-userver-pg:latest
privileged: true
environment:
- POSTGRES_DB=uservice_dynconf
- POSTGRES_USER=uservice_dynconf
- POSTGRES_PASSWORD=password
- PREFIX=${PREFIX:-~/.local}
- CC
- CCACHE_DIR=/uservice-dynconf/.ccache
- CCACHE_HASHDIR
- CCACHE_NOHASHDIR
- CCACHE_PREFIX
- CCACHE_SIZE
- CMAKE_OPTS
- CORES_DIR=/cores
- CXX
- MAKE_OPTS
- CMAKE_COMMON_FLAGS
volumes:
- .:/uservice-dynconf:rw
- ./third_party/userver/tools/docker:/tools:ro
ports:
- 8083:8083
working_dir: /uservice-dynconf
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/uservice-dynconf.git
ln -s /data/code/userver /data/code/uservice-dynconf/third_party/userver
```
1 change: 0 additions & 1 deletion third_party/userver
Submodule userver deleted from 3cdb43

0 comments on commit 90c0d7c

Please sign in to comment.