3
3
@anchor quick_start_for_beginners
4
4
## Quick start for beginners
5
5
6
- If you are new to userver it is a good idea to start with using the ` service template ` git repository to design your first userver-based service.
6
+ 1\. Press the "Use this template" button at the top right of the
7
+ [ GitHub template page] ( https://github.com/userver-framework/service_template ) .
7
8
8
- @warning @ref https://github.com/userver-framework/service_template.git "service_template" has no database. If you need a database please use other @ref service_templates "service templates".
9
-
10
- For a service without a database use https://github.com/userver-framework/service_template
11
-
12
- 1\. Clone ` service template ` and userver repositories.
9
+ @warning @ref https://github.com/userver-framework/service_template "service_template" has no databases and uses HTTP.
10
+ If you need gRPC or a database, please use other @ref service_templates "templates".
13
11
12
+ 2\. Clone the service:
14
13
15
14
``` shell
16
- git clone --depth 1 https://github.com/userver-framework/service_template.git && \
17
- git clone --depth 1 https://github.com/userver-framework/userver.git service_template/third_party/userver && \
18
- cd service_template
15
+ git clone https://github.com/your-username/your-service.git && cd your-service
19
16
```
20
17
21
- More information about ` hello service ` can be found here: @ref scripts/docs/en/userver/tutorial/hello_service.md
22
-
23
- 2\. Install userver dependencies.
24
-
25
- There is an option to use a @ref docker_with_ubuntu_22_04 "docker container".
18
+ 3\. @ref ways_to_get_userver "Get userver".
26
19
27
- Alternatively you can install @ref scripts/docs/en/userver/build/dependencies.md "build dependencies" for userver.
28
-
29
- For example to install @ref ubuntu_22_04 build dependencies:
30
-
31
- ``` shell
32
- sudo apt update && \
33
- sudo apt install --allow-downgrades -y $( cat third_party/userver/scripts/docs/en/deps/ubuntu-22.04.md | tr ' \n' ' ' )
34
- ```
35
-
36
- 3\. Build and start your service.
20
+ 4\. Build and start your service. Run in the service repo root:
37
21
38
22
``` shell
39
23
make build-release && \
40
- make service- start-release
24
+ make start-release
41
25
```
42
26
43
27
During the build, you can make a coffee break until approximately the following output appears:
@@ -56,7 +40,7 @@ DEBUG <userver> Incoming connection from ::ffff:127.0.0.1, fd 43
56
40
57
41
```
58
42
59
- 4 \. Try to send a request.
43
+ 5 \. Try to send a request.
60
44
61
45
``` shell
62
46
curl http://127.0.0.1:8080/hello? name=userver
@@ -69,50 +53,143 @@ The answer should be something like this:
69
53
Hello, userver!
70
54
```
71
55
72
- 5 \. Now you are ready for fast and comfortable creation of C++ microservices, services and utilities!
56
+ Now you are ready for fast and comfortable creation of C++ microservices, services and utilities!
73
57
74
58
@anchor service_templates
75
59
## Service templates for userver based services
76
60
77
- There are prepared and ready to use service templates at the github :
61
+ There are ready to use service templates at GitHub :
78
62
79
- | Link | Contains |
80
- | ---------------------------------------------------------------- | ---------------- |
81
- | https://github.com/userver-framework/service_template | |
82
- | https://github.com/userver-framework/pg_service_template | postgreSQL |
83
- | https://github.com/userver-framework/pg_grpc_service_template | postgreSQL, gRPC |
63
+ | Link | Contains |
64
+ | ------------------------------------------------------------------| ------------------------|
65
+ | https://github.com/userver-framework/service_template | HTTP |
66
+ | https://github.com/userver-framework/pg_service_template | HTTP, PostgreSQL |
67
+ | https://github.com/userver-framework/pg_grpc_service_template | HTTP, PostgreSQL, gRPC |
68
+ | https://github.com/userver-framework/mongo_grpc_service_template | HTTP, MongoDB, gRPC |
84
69
85
- Just use the template to make your own service:
70
+ To create a service:
86
71
87
- 1 . Press the green "Use this template" button at the top of the github template page
72
+ 1 . Press the "Use this template" button at the top right of the GitHub template page
88
73
2 . Clone the service ` git clone your-service-repo && cd your-service-repo `
89
74
3 . Give a proper name to your service and replace all the occurrences of "* service_template" string with that name.
90
75
4 . Feel free to tweak, adjust or fully rewrite the source code of your service.
91
76
92
- For local development of your service either
77
+ You'll need to @ref ways_to_get_userver "get userver" before proceeding with local development.
78
+
79
+ More information on the project directory structure can be found
80
+ @ref scripts/docs/en/userver/tutorial/hello_service.md "here".
93
81
94
- * use the docker build and tests run via ` make docker-test ` ;
95
- * or install the build dependencies on your local system and
96
- adjust the ` Makefile.local ` file to provide \b platform-specific \b CMake
97
- options to the template:
82
+ @anchor service_templates_libraries
83
+ ### Using additional userver libraries in service templates
98
84
99
85
The service templates allow to kickstart the development of your production-ready service,
100
86
but there can't be a repo for each and every combination of userver libraries.
101
87
To use additional userver libraries, e.g. ` userver::grpc ` , add to the root ` CMakeLists.txt ` :
102
88
103
89
``` cmake
104
- set(USERVER_FEATURE_GRPC ON CACHE BOOL "" FORCE)
105
- # ...
106
- add_subdirectory(third_party/userver)
107
- # ...
108
- target_link_libraries(${PROJECT_NAME} userver::grpc)
90
+ find_package(userver COMPONENTS core grpc QUIET)
109
91
```
110
92
93
+ Then add the corresponding option to @ref service_templates_presets "cmake presets",
94
+ e.g. ` "USERVER_FEATURE_GRPC": "ON" ` .
95
+
111
96
@see @ref userver_libraries
112
- @see @ref cmake_options
113
97
114
98
See @ref tutorial_services for minimal usage examples of various userver libraries.
115
99
100
+ @anchor service_templates_presets
101
+ ### Managing cmake options in service templates
102
+
103
+ @note If you use @userver_install "installed userver", then for most options to take effect, you need to uninstall
104
+ userver (if already installed), then install again, passing the desired cmake options.
105
+
106
+ Service templates use [ cmake presets] ( https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html ) for managing
107
+ service's cmake options. If you DON'T use installed userver and build userver together with the service,
108
+ then userver also takes its @ref cmake_options "cmake options" from there.
109
+
110
+ If an option has semantic meaning (should be committed to VCS and applied in CI),
111
+ then it should be added to ` CMakePresets.json ` :
112
+
113
+ ``` json
114
+ {
115
+ "configurePresets" : [
116
+ {
117
+ "name" : " common-flags" ,
118
+ "cacheVariables" : {
119
+ "USERVER_FEATURE_GRPC" : " ON" ,
120
+ "USERVER_SOME_OPTION" : " WHAT"
121
+ }
122
+ }
123
+ ]
124
+ }
125
+ ```
126
+
127
+ If an option only configures local build (should NOT be commited to VCS and applied in CI),
128
+ then it should instead be added to ` CMakeUserPresets.json ` :
129
+
130
+ * @ref service-template/CMakeUserPresets.json.example
131
+
132
+ Service's ` Makefile ` supports custom presets through additional targets like
133
+ ` cmake-debug-custom ` , ` cmake-release-custom ` , ` build-debug-custom ` , etc.
134
+
135
+ @anchor ways_to_get_userver
136
+ ## Ways to get userver
137
+
138
+ You can download prebuilt userver using one of the following ways:
139
+
140
+ 1 ) @ref devcontainers "Docker (Dev Containers)" ← recommended for beginners;
141
+ 2 ) @ref docker_with_ubuntu_22_04 "Docker (manual)";
142
+ 3 ) @ref prebuilt_deb_package "prebuilt Debian package";
143
+ 4 ) @ref userver_conan "Conan";
144
+
145
+ Alternatively, install @ref scripts/docs/en/userver/build/dependencies.md "build dependencies" for userver,
146
+ then build userver in one of the following ways:
147
+
148
+ 5 ) @ref userver_install "install userver";
149
+ 6 ) let the service template download and build userver as a subdirectory using (@ref userver_cpm "CPM");
150
+ 7 ) pass a path to custom userver location to ` download_userver() ` , then let the service
151
+ @ref service_templates_presets "build userver as a subdirectory".
152
+
153
+ @anchor devcontainers
154
+ ## Dev Containers
155
+
156
+ Dev Containers is the easiest and least problematic way to get prebuilt userver together with its dependencies.
157
+
158
+ 1 . Install Docker
159
+
160
+ * Linux:
161
+ ``` shell
162
+ curl https://get.docker.com/ | sudo sh
163
+ ```
164
+ Allow
165
+ [usage without sudo](https://docs.docker.com/engine/install/linux-postinstall/# manage-docker-as-a-non-root-user)
166
+ (reboot is required) and
167
+ [configure service start on boot](https://docs.docker.com/engine/install/linux-postinstall/# configure-docker-to-start-on-boot-with-systemd).
168
+
169
+ * [macOS](https://docs.docker.com/desktop/setup/install/mac-install/)
170
+
171
+ 2. Install IDE extension
172
+
173
+ * [VSCode](https://code.visualstudio.com/docs/devcontainers/containers): ` ms-vscode-remote.remote-containers`
174
+ * [CLion](https://www.jetbrains.com/help/clion/connect-to-devcontainer.html): " Dev Containers" (** note:** beta)
175
+
176
+ 3. Open the service project. If CMake asks to configure, deny
177
+
178
+ 4. Agree to reopen the project in a Dev Container
179
+
180
+ 5. The Docker container for development will automatically be downloaded (~6GB, may take a while), unpacked and run
181
+ using the config from
182
+ [.devcontainer](https://github.com/userver-framework/service_template/tree/develop/.devcontainer)
183
+ directory
184
+
185
+ 6. When prompted, select `Debug` cmake preset
186
+
187
+ 7. (Optional)
188
+ [Share Git credentials](https://code.visualstudio.com/remote/advancedcontainers/sharing-git-credentials)
189
+ with the container to perform VCS operations from the IDE
190
+
191
+ 8. You can configure, build, debug and run tests using either the IDE itself or ` Makefile` (see the service' s README.md)
192
+ using the IDE' s integrated terminal
116
193
117
194
# # Downloading packages using CPM
118
195
@@ -136,26 +213,19 @@ Some advice:
136
213
# ## Downloading userver using CPM
137
214
138
215
userver itself can be downloaded and built using CPM.
216
+ In fact, this is what
217
+ [download_userver()](https://github.com/userver-framework/service_template/blob/develop/cmake/DownloadUserver.cmake)
218
+ function does in @ref service_templates " service templates" by default.
139
219
140
- ``` cmake
141
- CPMAddPackage(
142
- NAME userver
143
- VERSION (userver release version or git commit hash)
144
- GIT_TAG (userver release version or git commit hash)
145
- GITHUB_REPOSITORY userver-framework/userver
146
- OPTIONS
147
- "USERVER_FEATURE_GRPC ON"
148
- )
149
-
150
- target_link_libraries(${PROJECT_NAME} userver::grpc)
151
- ```
220
+ `download_userver ()` just calls ` CPMAddPackage` with some defaults, so you can pin userver ` VERSION` or ` GIT_TAG`
221
+ for reproducible builds.
152
222
153
- First, install build dependencies. There are options:
223
+ When acquiring userver via CPM, you first need to install build dependencies. There are options:
154
224
155
225
* install @ref scripts/docs/en/userver/build/dependencies.md " build dependencies"
156
226
* or use base image of @ref docker_with_ubuntu_22_04
157
227
158
- Make sure to enable the CMake options to build userver libraries you need,
228
+ Make sure to @ref service_templates_presets " enable" the CMake options to build userver libraries you need,
159
229
then link to those libraries.
160
230
161
231
@see @ref cmake_options
@@ -195,10 +265,11 @@ sudo dpkg -i ./libuserver-all-dev*.deb
195
265
# ## Install with cmake --install
196
266
197
267
@warning installing userver with cmake --install is NOT recommended due to update and uninstall issues.
198
- Please @ref userver_install_debian_package "build and install Debian package" instead.
268
+ Please, @ref userver_install_debian_package " build and install Debian package" instead.
199
269
200
270
To install userver build it with ` USERVER_INSTALL=ON` flags in ` Debug` and ` Release` modes:
201
- ``` cmake
271
+
272
+ ` ` ` shell
202
273
cmake -S./ -B./build_debug \
203
274
-DCMAKE_BUILD_TYPE=Debug \
204
275
-DUSERVER_INSTALL=ON \
@@ -284,6 +355,15 @@ Alternatively see @ref userver_install "userver install"
284
355
inspiration on building your own custom docker containers.
285
356
286
357
358
+ @anchor prebuilt_deb_package
359
+ # ## Using a prebuilt Debian package for Ubuntu 22.04
360
+
361
+ You can download and install a ` .deb` package that is attached to each
362
+ [userver release](https://github.com/userver-framework/userver/releases).
363
+
364
+ The package currently targets Ubuntu 22.04, for other Ubuntu versions your mileage may vary.
365
+
366
+
287
367
@anchor userver_conan
288
368
# # Conan
289
369
@@ -363,3 +443,6 @@ The resulting binary should be 2-15% faster than without PGO, depending on the c
363
443
@htmlonly < div class=" bottom-nav" > @endhtmlonly
364
444
⇦ @ref scripts/docs/en/userver/faq.md | @ref scripts/docs/en/userver/build/dependencies.md ⇨
365
445
@htmlonly < /div> @endhtmlonly
446
+
447
+ @example service-template/CMakeUserPresets.json.example
448
+ @example service-template/Makefile.local
0 commit comments