Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use installed version of userver if any #66

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
22 changes: 0 additions & 22 deletions .github/workflows/update-submodules.yaml

This file was deleted.

3 changes: 0 additions & 3 deletions .gitmodules

This file was deleted.

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


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 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
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,3 +3,5 @@ worker-fs-threads: 2
logger-level: debug

is_testing: true

server-port: 8080
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 @@ -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:
Expand All @@ -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
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/service_template.git
ln -s /data/code/userver /data/code/service_template/third_party/userver
```
1 change: 0 additions & 1 deletion third_party/userver
Submodule userver deleted from 2846de
Loading