Git Product home page Git Product logo

userver-framework / service_template Goto Github PK

View Code? Open in Web Editor NEW
93.0 9.0 27.0 84 KB

Template of a C++ service that uses userver framework. Build, test and CI scripts ready

Home Page: https://userver.tech/da/d16/md_en_2userver_2tutorial_2hello__service.html

CMake 22.99% C++ 32.19% Python 3.23% Makefile 36.81% Shell 4.78%
asynchronous backend coroutines rest-api server template template-project userver cplusplus cplusplus-17

service_template's Introduction

service_template

Template of a C++ service that uses userver framework.

Download and Build

To create your own userver-based service follow the following steps:

  1. Press the green "Use this template button" at the top of this github page
  2. Clone the service git clone your-service-repo && cd your-service-repo && git submodule update --init
  3. Give a proper name to your service and replace all the occurences of "service_template" string with that name
  4. Feel free to tweak, adjust or fully rewrite the source code of your service.

Makefile

Makefile contains typicaly useful targets for development:

  • make build-debug - debug build of the service with all the assertions and sanitizers enabled
  • make build-release - release build of the service with LTO
  • make test-debug - does a make build-debug and runs all the tests on the result
  • make test-release - does a make build-release and runs all the tests on the result
  • make service-start-debug - builds the service in debug mode and starts it
  • make service-start-release - builds the service in release mode and starts it
  • make or make all - builds and runs all the tests in release and debug modes
  • make format - autoformat all the C++ and Python sources
  • make clean- - cleans the object files
  • make dist-clean - clean all, including the CMake cached configurations
  • make install - does a make build-release and run install in directory set in environment PREFIX
  • make install-debug - does a make build-debug and runs install in directory set in environment PREFIX
  • make docker-COMMAND - run make COMMAND in docker environment
  • make docker-build-debug - debug build of the service with all the assertions and sanitizers enabled in docker environment
  • make docker-test-debug - does a make build-debug and runs all the tests on the result in docker environment
  • make docker-start-service-release - does a make install-release and runs service in docker environment
  • make docker-start-service-debug - does a make install-debug and runs service in docker environment
  • make docker-clean-data - stop docker containers

Edit Makefile.local to change the default configuration and build options.

License

The original template is distributed under the Apache-2.0 License and CLA. Services based on the template may change the license and CLA.

service_template's People

Contributors

alexiprof avatar anton3 avatar apolukhin avatar podsvirov avatar sashamelentyev avatar tsilia avatar vitek avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

service_template's Issues

Installation issue on MacOS

When trying to install userver/service_template on MacOS there are couple of issues:

1. Configure and Build.

The path third_party/userver/scripts/docs/en/deps/macos.md - simply doesn't exist and we should create macos.md file and copy-paste dependencies from here macos.html. Only after that we can use the mentioned command in documentation: brew install $(cat path/to/macos.md | tr '\n' ' ').

After the first step we should be aware that http-parser - is disabled and we cannot install it by brew or macport. We should go to this repo: https://github.com/nodejs/http-parser and clone it.
Steps after the cloning: cd http-parser and try make install. There's an issue that on MacOS there's no flag -D for install command. So we can replace it by -c, because we are moving files, not directories. After that make install should work and give us the lib.

Other dependencies, that not mentioned.

When we will try to build service_template we will have other problems, that haven't been mentioned anywhere - installation of libraries for python files. There's couple of them: pyyaml, voluptuous, jinja-2:
conda install anaconda::pyyaml && conda install conda-forge::voluptuous && conda install `anaconda::jinja2

2. Build and Run

Issue found here.

This command will not work because of the lacking userver-samples-hello_service target on Makefile.

mkdir build_release
cd build_release
cmake -DCMAKE_BUILD_TYPE=Release ..
make userver-samples-hello_service

I've fixed it by reading Makefile and finding similar target: make start-service_template or make service_template.

But after that this command will not work also (maybe it was issue only in my mac, don't really know)
./samples/hello_service/userver-samples-hello_service -c </path/to/static_config.yaml>
Given static_config.yaml won't be parsed, because of the newlines between fields and non initialized variables such as worker-threads or ports.

I fixed it in static_config.yaml in this way:

components_manager:
    task_processors:                  # Task processor is an executor for coroutine tasks
        main-task-processor:          # Make a task processor for CPU-bound coroutine tasks.
            worker_threads: 4         # Process tasks in 4 threads.
        fs-task-processor:            # Make a separate task processor for filesystem bound tasks.
            worker_threads: 1
    default_task_processor: main-task-processor
    components:                       # Configuring components that were registered via component_list
        server:
            listener:                 # configuring the main listening socket...
                port: 80            # ...to listen on this port and...
                task_processor: main-task-processor    # ...process incoming requests on this task processor.

And after all everything will compile and work well. I hope this issue will help someone and I didn't miss anything.

missing pycodestyle dependency

Encountered issue while using template:

make test-debug
...
pycodestyle tests
make: pycodestyle: No such file or directory
make: *** [Makefile:40: test-debug] Error 127
...

pycodestyle used in makefile, but not specified as a dependency.

pycodestyle tests

docker-compose: No such file or directory

eoanermine@eoanermine:~/Repositories/userver_sample$ make docker-start-service-release
make: docker-compose: No such file or directory
make: *** [Makefile:86: docker-start-service-release] Error 127

Doesn't work on macOS with CLang compiler

Doesn't work on macOS with CLang compiler, produces following CMake error (CMakeError.log) attached as well:

cmake ..
-- C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc
-- C++ compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
-- Forcing warnings as errors!
-- Custom linker isn't available, using the default system linker.
-- LTO: on
-- LTO_CACHE enabled, cache folder is /Users/dev/Projects/GitHub/service_template/build/.ltocache
-- Looking for C++ include string
-- Looking for C++ include string - not found
CMake Error at third_party/userver/cmake/RequireLTO.cmake:31 (message):
LTO fails to compile a trivial program. See error logs for info. Try
specifying another linker via USERVER_USE_LD or changing the CMAKE_AR,
CMAKE_RANLIB, CMAKE_EXE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS
Call Stack (most recent call first):
CMakeError.log

third_party/userver/cmake/SetupLTO.cmake:22 (include)
third_party/userver/cmake/SetupEnvironment.cmake:44 (include)
CMakeLists.txt:4 (include)

make docker-start-service-release error

OS: Ubuntu 22
image

'''
Unhandled exception in components::Run: Error while parsing configs from file '/home/user/.local/etc/service_template/static_config.yaml'. Details: Field 'components_manager.task_processors.main-task-processor.worker_threads' is missing
make: *** [Makefile:81: --in-docker-start-release] Error 1
make: *** [Makefile:88: docker-start-service-release] Error 2
'''

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.